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 if situation.lastSetup:
44 applyLast = self.userChoose("This display is known. The last setup for it was like this:\n%s.\nApply the last used configuration?" % str(situation.lastSetup), ("Apply last setup", "Enter different setup"), (True,False), None)
48 return situation.lastSetup
49 assert applyLast is False
50 operationmodes = list(OperationMode)
51 operationmodedescs = list(map(lambda x: x.text, operationmodes))
52 operationmode = self.userChoose ("Display setup", operationmodedescs, operationmodes, None)
53 if operationmode is None:
55 elif operationmode is OperationMode.INTERNAL_ONLY:
56 intres = self.selectResolution("the internal screen", situation.internalResolutions())
60 return ScreenSetup(intres, None, None, False)
61 elif operationmode is OperationMode.EXTERNAL_ONLY:
62 extres = self.selectResolution("the external screen", situation.externalResolutions())
66 return ScreenSetup(None, extres, None, True)
68 assert operationmode is OperationMode.USE_BOTH
69 relscrpositions = list(RelativeScreenPosition)
70 relscrdescs = list(map(lambda x: x.text+" internal screen", relscrpositions))
71 relpos = self.userChoose ("Position of external screen", relscrdescs, relscrpositions, None)
74 elif relpos == RelativeScreenPosition.MIRROR:
75 # for mirroring only ask for common resolutions
76 commonres = self.selectResolution("both screens", situation.commonResolutions())
79 return ScreenSetup(commonres,commonres,relpos,False)
80 # select resolutions independently
81 intres = self.selectResolution("the internal screen", situation.internalResolutions())
84 extres = self.selectResolution("the external screen", situation.externalResolutions())
87 extprim = self.userChoose("Select primary screen", ["Internal screen is primary","External screen is primary"], [False,True], None)
90 return ScreenSetup(intres,extres,relpos,extprim)