7d27c097ee9fd2c98a68c977a7711253f25d82be
[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 InitLcd():
32         detected = eDBoxLCD.getInstance().detected()
33         SystemInfo["Display"] = detected
34         config.lcd = ConfigSubsection();
35         if detected:
36                 def setLCDbright(configElement):
37                         ilcd.setBright(configElement.value);
38
39                 def setLCDcontrast(configElement):
40                         ilcd.setContrast(configElement.value);
41
42                 def setLCDinverted(configElement):
43                         ilcd.setInverted(configElement.value);
44
45                 standby_default = 0
46
47                 ilcd = LCD()
48
49                 if not ilcd.isOled():
50                         config.lcd.contrast = ConfigSlider(default=5, limits=(0, 20))
51                         config.lcd.contrast.addNotifier(setLCDcontrast);
52                 else:
53                         config.lcd.contrast = ConfigNothing()
54                         standby_default = 1
55
56                 config.lcd.standby = ConfigSlider(default=standby_default, limits=(0, 10))
57                 config.lcd.standby.addNotifier(setLCDbright);
58                 config.lcd.standby.apply = lambda : setLCDbright(config.lcd.standby)
59
60                 config.lcd.bright = ConfigSlider(default=5, limits=(0, 10))
61                 config.lcd.bright.addNotifier(setLCDbright);
62                 config.lcd.bright.apply = lambda : setLCDbright(config.lcd.bright)
63                 config.lcd.bright.callNotifiersOnSaveAndCancel = True
64
65                 config.lcd.invert = ConfigYesNo(default=False)
66                 config.lcd.invert.addNotifier(setLCDinverted);
67         else:
68                 def doNothing():
69                         pass
70                 config.lcd.contrast = ConfigNothing()
71                 config.lcd.bright = ConfigNothing()
72                 config.lcd.standby = ConfigNothing()
73                 config.lcd.bright.apply = lambda : doNothing()
74                 config.lcd.standby.apply = lambda : doNothing()