Add toggle TV on LCD display for VU+Solo4K
[openblackhole/openblackhole-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 from Screens.InfoBar import InfoBar
5 from Screens.Screen import Screen
6
7 class dummyScreen(Screen):
8         skin = """<screen position="0,0" size="0,0" transparent="1">
9         <widget source="session.VideoPicture" render="Pig" position="0,0" size="0,0" backgroundColor="transparent" zPosition="1"/>
10         </screen>"""
11         def __init__(self, session, args=None):
12                 Screen.__init__(self, session)
13                 self.close()
14
15 class LCD:
16         def __init__(self):
17                 pass
18
19         def setBright(self, value):
20                 value *= 255
21                 value /= 10
22                 if value > 255:
23                         value = 255
24                 eDBoxLCD.getInstance().setLCDBrightness(value)
25
26         def setContrast(self, value):
27                 value *= 63
28                 value /= 20
29                 if value > 63:
30                         value = 63
31                 eDBoxLCD.getInstance().setLCDContrast(value)
32
33         def setInverted(self, value):
34                 if value:
35                         value = 255
36                 eDBoxLCD.getInstance().setInverted(value)
37
38         def setFlipped(self, value):
39                 eDBoxLCD.getInstance().setFlipped(value)
40
41         def isOled(self):
42                 return eDBoxLCD.getInstance().isOled()
43
44 def leaveStandby():
45         config.lcd.bright.apply()
46
47 def standbyCounterChanged(configElement):
48         from Screens.Standby import inStandby
49         inStandby.onClose.append(leaveStandby)
50         config.lcd.standby.apply()
51
52 def InitLcd():
53         detected = eDBoxLCD.getInstance() and eDBoxLCD.getInstance().detected()
54         SystemInfo["Display"] = detected
55         config.lcd = ConfigSubsection();
56         if detected:
57                 def setLCDbright(configElement):
58                         ilcd.setBright(configElement.value);
59
60                 def setLCDcontrast(configElement):
61                         ilcd.setContrast(configElement.value);
62
63                 def setLCDinverted(configElement):
64                         ilcd.setInverted(configElement.value);
65
66                 def setLCDflipped(configElement):
67                         ilcd.setFlipped(configElement.value);
68
69                 standby_default = 0
70
71                 ilcd = LCD()
72
73                 if not ilcd.isOled():
74                         config.lcd.contrast = ConfigSlider(default=5, limits=(0, 20))
75                         config.lcd.contrast.addNotifier(setLCDcontrast);
76                 else:
77                         config.lcd.contrast = ConfigNothing()
78                         standby_default = 1
79
80                 config.lcd.standby = ConfigSlider(default=standby_default, limits=(0, 10))
81                 config.lcd.standby.addNotifier(setLCDbright);
82                 config.lcd.standby.apply = lambda : setLCDbright(config.lcd.standby)
83
84                 config.lcd.bright = ConfigSlider(default=5, limits=(0, 10))
85                 config.lcd.bright.addNotifier(setLCDbright);
86                 config.lcd.bright.apply = lambda : setLCDbright(config.lcd.bright)
87                 config.lcd.bright.callNotifiersOnSaveAndCancel = True
88
89                 config.lcd.invert = ConfigYesNo(default=False)
90                 config.lcd.invert.addNotifier(setLCDinverted);
91
92                 config.lcd.flip = ConfigYesNo(default=False)
93                 config.lcd.flip.addNotifier(setLCDflipped);
94
95                 if SystemInfo["LcdLiveTV"]:
96                         def lcdLiveTvChanged(configElement):
97                                 if "live_enable" in SystemInfo["LcdLiveTV"]:
98                                         open(SystemInfo["LcdLiveTV"], "w").write(configElement.value and "enable" or "disable")
99                                 else:
100                                         open(SystemInfo["LcdLiveTV"], "w").write(configElement.value and "0" or "1")
101                                 InfoBarInstance = InfoBar.instance
102                                 InfoBarInstance and InfoBarInstance.session.open(dummyScreen)
103                         config.lcd.showTv = ConfigYesNo(default = False)
104                         config.lcd.showTv.addNotifier(lcdLiveTvChanged)
105         else:
106                 def doNothing():
107                         pass
108                 config.lcd.contrast = ConfigNothing()
109                 config.lcd.bright = ConfigNothing()
110                 config.lcd.standby = ConfigNothing()
111                 config.lcd.bright.apply = lambda : doNothing()
112                 config.lcd.standby.apply = lambda : doNothing()
113
114         config.misc.standbyCounter.addNotifier(standbyCounterChanged, initial_call = False)