cleanup lcd code
[enigma2.git] / lib / python / Components / Lcd.py
1 from config import config, ConfigSubsection, ConfigSlider, ConfigYesNo, ConfigNothing
2 from enigma import eDBoxLCD
3 from Components.SystemInfo import SystemInfo
4
5 class LCD:
6         def __init__(self):
7                 pass
8
9         def setBright(self, value):
10                 value *= 255
11                 value /= 10
12                 if value > 255:
13                         value = 255
14                 eDBoxLCD.getInstance().setLCDBrightness(value)
15
16         def setContrast(self, value):
17                 value *= 63
18                 value /= 20
19                 if value > 63:
20                         value = 63
21                 eDBoxLCD.getInstance().setLCDContrast(value)
22
23         def setInverted(self, value):
24                 if value:
25                         value = 255
26                 eDBoxLCD.getInstance().setInverted(value)
27
28         def isOled(self):
29                 return eDBoxLCD.getInstance().isOled()
30
31 def leaveStandby():
32         config.lcd.bright.apply()
33
34 def standbyCounterChanged(configElement):
35         from Screens.Standby import inStandby
36         inStandby.onClose.append(leaveStandby)
37         config.lcd.standby.apply()
38
39 def InitLcd():
40         detected = eDBoxLCD.getInstance().detected()
41         SystemInfo["Display"] = detected
42         config.lcd = ConfigSubsection();
43         if detected:
44                 def setLCDbright(configElement):
45                         ilcd.setBright(configElement.value);
46
47                 def setLCDcontrast(configElement):
48                         ilcd.setContrast(configElement.value);
49
50                 def setLCDinverted(configElement):
51                         ilcd.setInverted(configElement.value);
52
53                 standby_default = 0
54
55                 ilcd = LCD()
56
57                 if not ilcd.isOled():
58                         config.lcd.contrast = ConfigSlider(default=5, limits=(0, 20))
59                         config.lcd.contrast.addNotifier(setLCDcontrast);
60                 else:
61                         config.lcd.contrast = ConfigNothing()
62                         standby_default = 1
63
64                 config.lcd.standby = ConfigSlider(default=standby_default, limits=(0, 10))
65                 config.lcd.standby.addNotifier(setLCDbright);
66                 config.lcd.standby.apply = lambda : setLCDbright(config.lcd.standby)
67
68                 config.lcd.bright = ConfigSlider(default=5, limits=(0, 10))
69                 config.lcd.bright.addNotifier(setLCDbright);
70                 config.lcd.bright.apply = lambda : setLCDbright(config.lcd.bright)
71                 config.lcd.bright.callNotifiersOnSaveAndCancel = True
72
73                 config.lcd.invert = ConfigYesNo(default=False)
74                 config.lcd.invert.addNotifier(setLCDinverted);
75         else:
76                 def doNothing():
77                         pass
78                 config.lcd.contrast = ConfigNothing()
79                 config.lcd.bright = ConfigNothing()
80                 config.lcd.standby = ConfigNothing()
81                 config.lcd.bright.apply = lambda : doNothing()
82                 config.lcd.standby.apply = lambda : doNothing()
83
84         config.misc.standbyCounter.addNotifier(standbyCounterChanged, initial_call = False)
85