Zapping Mode Selection : add new Plugin
[vuplus_dvbapp] / lib / python / Plugins / SystemPlugins / ZappingModeSelection / plugin.py
1 from Screens.Screen import Screen
2 from Components.ConfigList import ConfigListScreen
3 from Components.config import config, getConfigListEntry, ConfigSubsection, ConfigSelection
4 from Components.ActionMap import ActionMap
5 from Screens.MessageBox import MessageBox
6 from Components.Sources.StaticText import StaticText
7 from Plugins.Plugin import PluginDescriptor
8 from Tools.Directories import fileExists
9
10 config.plugins.zappingModeSelection = ConfigSubsection()
11 config.plugins.zappingModeSelection.zappingMode = ConfigSelection(default = "mute", choices = [ ("mute", _("MUTE")), ("hold", _("HOLD"))] )
12
13 class ZappingModeSelectionInit:
14         def __init__(self):
15                 self.setZappingMode(config.plugins.zappingModeSelection.zappingMode.value)
16
17         def setZappingMode(self, mode = "mute"):
18                 if not fileExists("/proc/stb/video/zapping_mode"):
19                         return -1
20                 print "<ZappingModeSelection> set zapping mode : %s" % mode
21                 f = open("/proc/stb/video/zapping_mode", "w")
22                 f.write("%s" % mode)
23                 f.close()
24                 return 0
25
26 class ZappingModeSelection(Screen,ConfigListScreen,ZappingModeSelectionInit):
27         skin =  """
28                 <screen position="center,center" size="560,250" title="Zapping Mode Selection" >
29                         <ePixmap pixmap="skin_default/buttons/red.png" position="110,10" size="140,40" alphatest="on" />
30                         <ePixmap pixmap="skin_default/buttons/green.png" position="310,10" size="140,40" alphatest="on" />
31                         <widget source="key_red" render="Label" position="110,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" foregroundColor="#ffffff" transparent="1" />
32                         <widget source="key_green" render="Label" position="310,10" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" foregroundColor="#ffffff" transparent="1" />
33                         <widget name="config" zPosition="2" position="5,70" size="550,200" scrollbarMode="showOnDemand" transparent="1" />
34                 </screen>
35                 """
36
37         def __init__(self,session):
38                 Screen.__init__(self,session)
39                 self.session = session
40                 self["shortcuts"] = ActionMap(["ShortcutActions", "SetupActions" ],
41                 {
42                         "ok": self.keySave,
43                         "cancel": self.keyCancel,
44                         "red": self.keyCancel,
45                         "green": self.keySave,
46                 }, -2)
47                 self.list = []
48                 ConfigListScreen.__init__(self, self.list,session = self.session)
49                 self["key_red"] = StaticText(_("Cancel"))
50                 self["key_green"] = StaticText(_("Ok"))
51                 self.createSetup()
52
53         def createSetup(self):
54                 self.list = []
55                 self.rcsctype = getConfigListEntry(_("Zapping Mode"), config.plugins.zappingModeSelection.zappingMode)
56                 self.list.append( self.rcsctype )
57                 self["config"].list = self.list
58                 self["config"].l.setList(self.list)
59
60         def keySave(self):
61                 print "<ZappingModeSelection> Zapping Code : ",config.plugins.zappingModeSelection.zappingMode.value
62                 ret = self.setZappingMode(config.plugins.zappingModeSelection.zappingMode.value)
63                 if ret == -1:
64                         self.resetConfig()
65                         self.session.openWithCallback(self.close, MessageBox, _("SET FAILED!\nPlease update to the latest driver"), MessageBox.TYPE_ERROR)
66                 else:
67                         self.saveAll()
68                         self.close()
69
70         def resetConfig(self):
71                 for x in self["config"].list:
72                         x[1].cancel()
73
74 def main(session, **kwargs):
75         session.open(ZappingModeSelection)
76
77 def Plugins(**kwargs):
78         return [PluginDescriptor(name=_("ZappingModeSelection"), description="Zapping Mode Selection", where = PluginDescriptor.WHERE_PLUGINMENU, needsRestart = False, fnc=main)]
79
80 zappingmodeselectioninit = ZappingModeSelectionInit()