4.2.0r3
[enigma2.git] / usr / lib / enigma2 / 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         instance = eDBoxLCD.getInstance()
41         if instance:
42                 detected = instance.detected()
43         else:
44                 detected = False
45         SystemInfo["Display"] = detected
46         config.lcd = ConfigSubsection();
47         if detected:
48                 def setLCDbright(configElement):
49                         ilcd.setBright(configElement.value);
50
51                 def setLCDcontrast(configElement):
52                         ilcd.setContrast(configElement.value);
53
54                 def setLCDinverted(configElement):
55                         ilcd.setInverted(configElement.value);
56
57                 standby_default = 0
58
59                 ilcd = LCD()
60
61                 if not ilcd.isOled():
62                         config.lcd.contrast = ConfigSlider(default=5, limits=(0, 20))
63                         config.lcd.contrast.addNotifier(setLCDcontrast);
64                 else:
65                         config.lcd.contrast = ConfigNothing()
66                         standby_default = 1
67
68                 config.lcd.standby = ConfigSlider(default=standby_default, limits=(0, 10))
69                 config.lcd.standby.addNotifier(setLCDbright);
70                 config.lcd.standby.apply = lambda : setLCDbright(config.lcd.standby)
71
72                 config.lcd.bright = ConfigSlider(default=5, limits=(0, 10))
73                 config.lcd.bright.addNotifier(setLCDbright, call_on_save_or_cancel=True);
74                 config.lcd.bright.apply = lambda : setLCDbright(config.lcd.bright)
75
76                 config.lcd.invert = ConfigYesNo(default=False)
77                 config.lcd.invert.addNotifier(setLCDinverted);
78         else:
79                 def doNothing():
80                         pass
81                 config.lcd.contrast = ConfigNothing()
82                 config.lcd.bright = ConfigNothing()
83                 config.lcd.standby = ConfigNothing()
84                 config.lcd.bright.apply = lambda : doNothing()
85                 config.lcd.standby.apply = lambda : doNothing()
86
87         config.misc.standbyCounter.addNotifier(standbyCounterChanged, initial_call = False)
88