pipzap and PluginHider (OE2.5) (#15)
[enigma2-plugins.git] / pipzap / src / PipzapSetup.py
1 # GUI (Screens)
2 from Screens.Screen import Screen
3 from Components.ConfigList import ConfigListScreen
4
5 # GUI (Summary)
6 from Screens.Setup import SetupSummary
7
8 # GUI (Components)
9 from Components.ActionMap import ActionMap
10 from Components.Sources.StaticText import StaticText
11
12 # Configuration
13 from Components.config import config, getConfigListEntry
14
15 class PipzapSetup(Screen, ConfigListScreen):
16         skin = """<screen name="PipzapSetup" position="center,center" size="565,370">
17                 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" scale="stretch" alphatest="on" />
18                 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" scale="stretch" alphatest="on" />
19                 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" scale="stretch" alphatest="on" />
20                 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" scale="stretch" alphatest="on" />
21                 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
22                 <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
23                 <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
24                 <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
25                 <widget name="config" position="5,50" size="555,250" scrollbarMode="showOnDemand" />
26                 <ePixmap pixmap="skin_default/div-h.png" position="0,301" zPosition="1" size="565,2" />
27                 <widget source="help" render="Label" position="5,305" size="555,63" font="Regular;21" />
28         </screen>"""
29
30         def __init__(self, session):
31                 Screen.__init__(self, session)
32
33                 # Summary
34                 self.setup_title = _("pipzap Setup")
35                 self.onChangedEntry = []
36                 
37                 # Initialize widgets
38                 self["key_green"] = StaticText(_("OK"))
39                 self["key_red"] = StaticText(_("Cancel"))
40                 self["key_yellow"] = StaticText("")
41                 from plugin import pipzapHelp
42                 if pipzapHelp:
43                         self["key_blue"] = StaticText(_("Help"))
44                 else:
45                         self["key_blue"] = StaticText("")
46                 self["help"] = StaticText()
47                 
48                 # Define Actions
49                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
50                                         {
51                                                 "cancel": self.keyCancel,
52                                                 "save": self.keySave,
53                                                 "blue": self.keyBlue,
54                                         }
55                                 )
56
57                 self.list = []
58                 self.buildConfig()
59                 ConfigListScreen.__init__(self, self.list, session = session, on_change = self.changed)
60                 
61                 def selectionChanged():
62                         if self["config"].current:
63                                 self["config"].current[1].onDeselect(self.session)
64                         self["config"].current = self["config"].getCurrent()
65                         if self["config"].current:
66                                 self["config"].current[1].onSelect(self.session)
67                         for x in self["config"].onSelectionChanged:
68                                 x()
69
70                 self["config"].selectionChanged = selectionChanged
71                 self["config"].onSelectionChanged.append(self.updateHelp)
72
73                 # Trigger change
74                 self.changed()
75                 
76                 self.onLayoutFinish.append(self.setCustomTitle)
77
78
79         def buildConfig(self):
80                         
81                         self.list.append( getConfigListEntry(_("Enable Hotkey"), config.plugins.pipzap.enable_hotkey, _("Use the STOP-Key to quickly enable/disable pipzap in TV-Mode? Changing this setting requires a restart.") ) )
82                         if config.plugins.pipzap.enable_hotkey.value:
83                                 self.list.append( getConfigListEntry(_("  Open/Close PiP with Exit-Key"), config.plugins.pipzap.enable_exitkey, _("Use the Exit-Key to open/close the PiP.") ) )
84                         self.list.append( getConfigListEntry(_("Show in Plugin menu"), config.plugins.pipzap.show_in_plugins, _("Adds an entry to the Plugin menu to toggle pipzap") ) )
85                         self.list.append( getConfigListEntry(_("Show indicator label if zapping PiP"), config.plugins.pipzap.show_label, _("Displays a label in the opposite corner of PiP if pipzap is enabled.") ) )
86                         if config.plugins.pipzap.show_label.value:
87                                 self.list.append( getConfigListEntry(_("  Show label with channelname under PiP"), config.plugins.pipzap.show_channelname, _("Displays the channelname in a label directly under the PiP - instead of indicator label.") ) )
88
89
90         def setCustomTitle(self):
91                 self.setTitle(self.setup_title)
92
93         def updateHelp(self):
94                 cur = self["config"].getCurrent()
95                 if cur:
96                         self["help"].text = cur[2]
97
98         def changeConfig(self):
99                 self.list = []
100                 self.buildConfig()
101                 self["config"].setList(self.list)
102                 
103         def changed(self):
104                 for x in self.onChangedEntry:
105                         x()
106                 current = self["config"].getCurrent()[1]
107                 if (current == config.plugins.pipzap.show_label or current == config.plugins.pipzap.enable_hotkey):
108                         self.changeConfig()
109                         return
110
111         def getCurrentEntry(self):
112                 return self["config"].getCurrent()[0]
113
114         def getCurrentValue(self):
115                 return str(self["config"].getCurrent()[1].getText())
116
117         def createSummary(self):
118                 return SetupSummary
119
120         def keyBlue(self):
121                 from plugin import pipzapHelp
122                 if pipzapHelp:
123                         pipzapHelp.open(self.session)