6 # Coded by Dr.Best (c) 2009
7 # Support: www.dreambox-tools.info
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
20 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, \
22 from Screens.Screen import Screen
23 from Screens.MessageBox import MessageBox
24 from Components.MenuList import MenuList
25 from Components.Sources.StaticText import StaticText
26 from Components.ActionMap import ActionMap
27 from Components.ConfigList import ConfigList, ConfigListScreen
28 from Components.config import ConfigSubsection, ConfigText, \
29 getConfigListEntry, config, configfile
32 def initWeatherPluginEntryConfig():
33 s = ConfigSubsection()
34 s.city = ConfigText(default = "Heidelberg", visible_width = 50, fixed_size = False)
35 s.language = ConfigText(default = "de", visible_width = 50, fixed_size = False)
36 config.plugins.WeatherPlugin.Entries.append(s)
40 count = config.plugins.WeatherPlugin.entriescount.value
44 initWeatherPluginEntryConfig()
47 class WeatherPluginEntriesListConfigScreen(Screen):
49 <screen position="center,center" size="550,400" title="%s" >
50 <widget render="Label" source="city" position="5,0" size="150,50" font="Regular;20" halign="left"/>
51 <widget render="Label" source="language" position="155,0" size="150,50" font="Regular;20" halign="left"/>
52 <widget name="entrylist" position="0,50" size="550,300" scrollbarMode="showOnDemand"/>
53 <widget render="Label" source="key_red" position="0,350" size="140,40" zPosition="5" valign="center" halign="center" backgroundColor="red" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
54 <widget render="Label" source="key_yellow" position="280,350" size="140,40" zPosition="5" valign="center" halign="center" backgroundColor="yellow" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
55 <widget render="Label" source="key_blue" position="420,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
56 <ePixmap position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
57 <ePixmap position="280,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
58 <ePixmap position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
59 </screen>""" % _("WeatherPlugin: List of Entries")
61 def __init__(self, session):
62 Screen.__init__(self, session)
64 self["city"] = StaticText(_("City"))
65 self["language"] = StaticText(_("Language"))
66 self["key_red"] = StaticText(_("Add"))
67 self["key_yellow"] = StaticText(_("Edit"))
68 self["key_blue"] = StaticText(_("Delete"))
69 self["entrylist"] = WeatherPluginEntryList([])
70 self["actions"] = ActionMap(["WizardActions","MenuActions","ShortcutActions"],
73 "back" : self.keyClose,
75 "yellow": self.keyYellow,
76 "blue": self.keyDelete,
81 self["entrylist"].buildList()
87 self.session.openWithCallback(self.updateList,WeatherPluginEntryConfigScreen,None)
90 try:sel = self["entrylist"].l.getCurrentSelection()[0]
92 self.close(self["entrylist"].getCurrentIndex(), sel)
95 try:sel = self["entrylist"].l.getCurrentSelection()[0]
99 self.session.openWithCallback(self.updateList,WeatherPluginEntryConfigScreen,sel)
102 try:sel = self["entrylist"].l.getCurrentSelection()[0]
106 self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Really delete this WeatherPlugin Entry?"))
108 def deleteConfirm(self, result):
111 sel = self["entrylist"].l.getCurrentSelection()[0]
112 config.plugins.WeatherPlugin.entriescount.value -= 1
113 config.plugins.WeatherPlugin.entriescount.save()
114 config.plugins.WeatherPlugin.Entries.remove(sel)
115 config.plugins.WeatherPlugin.Entries.save()
116 config.plugins.WeatherPlugin.save()
120 class WeatherPluginEntryList(MenuList):
121 def __init__(self, list, enableWrapAround = True):
122 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
123 self.l.setFont(0, gFont("Regular", 20))
124 self.l.setFont(1, gFont("Regular", 18))
126 def postWidgetCreate(self, instance):
127 MenuList.postWidgetCreate(self, instance)
128 instance.setItemHeight(20)
130 def getCurrentIndex(self):
131 return self.instance.getCurrentIndex()
135 for c in config.plugins.WeatherPlugin.Entries:
138 (eListboxPythonMultiContent.TYPE_TEXT, 5, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.city.value)),
139 (eListboxPythonMultiContent.TYPE_TEXT, 155, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.language.value)),
146 class WeatherPluginEntryConfigScreen(ConfigListScreen, Screen):
148 <screen name="WeatherPluginEntryConfigScreen" position="center,center" size="550,400" title="%s">
149 <widget name="config" position="20,10" size="520,330" scrollbarMode="showOnDemand" />
150 <ePixmap position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
151 <ePixmap position="140,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
152 <ePixmap position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
154 <widget source="key_red" render="Label" position="0,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
155 <widget source="key_green" render="Label" position="140,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
156 <widget source="key_blue" render="Label" position="420,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
159 def __init__(self, session, entry):
160 Screen.__init__(self, session)
161 self.title = _("WeatherPlugin: Edit Entry")
163 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
165 "green": self.keySave,
166 "red": self.keyCancel,
167 "blue": self.keyDelete,
168 "cancel": self.keyCancel
171 self["key_red"] = StaticText(_("Cancel"))
172 self["key_green"] = StaticText(_("OK"))
173 self["key_blue"] = StaticText(_("Delete"))
177 self.current = initWeatherPluginEntryConfig()
183 getConfigListEntry(_("City or Postal Code"), self.current.city),
184 getConfigListEntry(_("Language"), self.current.language)
187 ConfigListScreen.__init__(self, cfglist, session)
190 if self.newmode == 1:
191 config.plugins.WeatherPlugin.entriescount.value = config.plugins.WeatherPlugin.entriescount.value + 1
192 config.plugins.WeatherPlugin.entriescount.save()
193 ConfigListScreen.keySave(self)
194 config.plugins.WeatherPlugin.save()
199 if self.newmode == 1:
200 config.plugins.WeatherPlugin.Entries.remove(self.current)
201 ConfigListScreen.cancelConfirm(self, True)
204 if self.newmode == 1:
207 self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Really delete this WeatherPlugin Entry?"))
209 def deleteConfirm(self, result):
212 config.plugins.WeatherPlugin.entriescount.value = config.plugins.WeatherPlugin.entriescount.value - 1
213 config.plugins.WeatherPlugin.entriescount.save()
214 config.plugins.WeatherPlugin.Entries.remove(self.current)
215 config.plugins.WeatherPlugin.Entries.save()
216 config.plugins.WeatherPlugin.save()