1 # DSL - easy Display Setup for Laptops
2 # Copyright (C) 2012 Ralf Jung <post@ralfj.de>
3 # Copyright (C) 2012-2015 Constantin Berhard<constantin@exxxtremesys.lu>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 from screen import RelativeScreenPosition, ScreenSetup, processOutputIt
23 class OperationMode(Enum):
24 INTERNAL_ONLY = ("Use internal display only")
25 EXTERNAL_ONLY = ("Use external display only")
26 USE_BOTH = ("Use both displays")
27 def __init__(self, text):
30 self._value_ = len(cls.__members__)
34 class QuestionFrontend:
35 def userChoose (self, title, choices, returns, fallback):
36 raise Exception("The abstract method 'userChoose' has not been implemented by %s"%str(self.__class__))
38 def selectResolution(self, displayname, availablemodes):
39 modedescs = list(map(str, availablemodes))
40 return self.userChoose("Select resolution for %s"%displayname, modedescs, availablemodes, None)
42 def setup (self, situation):
43 operationmodes = list(OperationMode)
44 operationmodedescs = list(map(lambda x: x.text, operationmodes))
45 operationmode = self.userChoose ("Display setup", operationmodedescs, operationmodes, None)
46 if operationmode is None:
48 elif operationmode is OperationMode.INTERNAL_ONLY:
49 intres = self.selectResolution("the internal screen", situation.internalResolutions())
53 return ScreenSetup(intres, None, None, False)
54 elif operationmode is OperationMode.EXTERNAL_ONLY:
55 extres = self.selectResolution("the external screen", situation.externalResolutions())
59 return ScreenSetup(None, extres, None, True)
61 assert operationmode is OperationMode.USE_BOTH
62 relscrpositions = list(RelativeScreenPosition)
63 relscrdescs = list(map(lambda x: x.text+" internal screen", relscrpositions))
64 relpos = self.userChoose ("Position of external screen", relscrdescs, relscrpositions, None)
67 elif relpos == RelativeScreenPosition.MIRROR:
68 # for mirroring only ask for common resolutions
69 commonres = self.selectResolution("both screens", situation.commonResolutions())
72 return ScreenSetup(commonres,commonres,relpos,False)
73 # select resolutions independently
74 intres = self.selectResolution("the internal screen", situation.internalResolutions())
77 extres = self.selectResolution("the external screen", situation.externalResolutions())
80 extprim = self.userChoose("Select primary screen", ["Internal screen is primary","External screen is primary"], [False,True], None)
83 return ScreenSetup(intres,extres,relpos,extprim)