1 # -*- coding: utf-8 -*-
7 # Coded by Dr.Best (c) 2009
8 # Support: www.dreambox-tools.info
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License
12 # as published by the Free Software Foundation; either version 2
13 # of the License, or (at your option) any later version.
15 # This program is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
21 # for localized messages
24 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, \
26 from Screens.Screen import Screen
27 from Screens.MessageBox import MessageBox
28 from Components.MenuList import MenuList
29 from Components.Sources.StaticText import StaticText
30 from Components.ActionMap import ActionMap
31 from Components.ConfigList import ConfigList, ConfigListScreen
32 from Components.config import ConfigSubsection, ConfigText, \
33 getConfigListEntry, config, configfile
36 def initWeatherPluginEntryConfig():
37 s = ConfigSubsection()
38 s.city = ConfigText(default = "Heidelberg", visible_width = 50, fixed_size = False)
39 s.language = ConfigText(default = "de", visible_width = 50, fixed_size = False)
40 config.plugins.WeatherPlugin.Entries.append(s)
44 count = config.plugins.WeatherPlugin.entriescount.value
48 initWeatherPluginEntryConfig()
51 class WeatherPluginEntriesListConfigScreen(Screen):
53 <screen position="center,center" size="550,400" title="%s" >
54 <widget render="Label" source="city" position="5,0" size="150,50" font="Regular;20" halign="left"/>
55 <widget render="Label" source="language" position="155,0" size="150,50" font="Regular;20" halign="left"/>
56 <widget name="entrylist" position="0,50" size="550,300" scrollbarMode="showOnDemand"/>
57 <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" />
58 <widget render="Label" source="key_green" position="140,350" size="140,40" zPosition="5" valign="center" halign="center" backgroundColor="green" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
59 <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" />
60 <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" />
61 <ePixmap position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
62 <ePixmap position="140,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
63 <ePixmap position="280,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
64 <ePixmap position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
65 </screen>""" % _("WeatherPlugin: List of Entries")
67 def __init__(self, session):
68 Screen.__init__(self, session)
70 self["city"] = StaticText(_("City"))
71 self["language"] = StaticText(_("Language"))
72 self["key_red"] = StaticText(_("Back"))
73 self["key_green"] = StaticText(_("Add"))
74 self["key_yellow"] = StaticText(_("Edit"))
75 self["key_blue"] = StaticText(_("Delete"))
76 self["entrylist"] = WeatherPluginEntryList([])
77 self["actions"] = ActionMap(["WizardActions","MenuActions","ShortcutActions"],
80 "back" : self.keyClose,
81 "red" : self.keyClose,
82 "green": self.keyGreen,
83 "yellow": self.keyYellow,
84 "blue": self.keyDelete,
89 self["entrylist"].buildList()
95 self.session.openWithCallback(self.updateList,WeatherPluginEntryConfigScreen,None)
98 try:sel = self["entrylist"].l.getCurrentSelection()[0]
100 self.close(self["entrylist"].getCurrentIndex(), sel)
103 try:sel = self["entrylist"].l.getCurrentSelection()[0]
107 self.session.openWithCallback(self.updateList,WeatherPluginEntryConfigScreen,sel)
110 try:sel = self["entrylist"].l.getCurrentSelection()[0]
114 self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Really delete this WeatherPlugin Entry?"))
116 def deleteConfirm(self, result):
119 sel = self["entrylist"].l.getCurrentSelection()[0]
120 config.plugins.WeatherPlugin.entriescount.value -= 1
121 config.plugins.WeatherPlugin.entriescount.save()
122 config.plugins.WeatherPlugin.Entries.remove(sel)
123 config.plugins.WeatherPlugin.Entries.save()
124 config.plugins.WeatherPlugin.save()
128 class WeatherPluginEntryList(MenuList):
129 def __init__(self, list, enableWrapAround = True):
130 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
131 self.l.setFont(0, gFont("Regular", 20))
132 self.l.setFont(1, gFont("Regular", 18))
134 def postWidgetCreate(self, instance):
135 MenuList.postWidgetCreate(self, instance)
136 instance.setItemHeight(20)
138 def getCurrentIndex(self):
139 return self.instance.getCurrentIndex()
143 for c in config.plugins.WeatherPlugin.Entries:
146 (eListboxPythonMultiContent.TYPE_TEXT, 5, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.city.value)),
147 (eListboxPythonMultiContent.TYPE_TEXT, 155, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.language.value)),
154 class WeatherPluginEntryConfigScreen(ConfigListScreen, Screen):
156 <screen name="WeatherPluginEntryConfigScreen" position="center,center" size="550,400" title="%s">
157 <widget name="config" position="20,10" size="520,330" scrollbarMode="showOnDemand" />
158 <ePixmap position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
159 <ePixmap position="140,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
160 <ePixmap position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
162 <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" />
163 <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" />
164 <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" />
165 </screen>""" % _("WeatherPlugin: Edit Entry")
167 def __init__(self, session, entry):
168 Screen.__init__(self, session)
170 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
172 "green": self.keySave,
173 "red": self.keyCancel,
174 "blue": self.keyDelete,
175 "cancel": self.keyCancel
178 self["key_red"] = StaticText(_("Cancel"))
179 self["key_green"] = StaticText(_("OK"))
180 self["key_blue"] = StaticText(_("Delete"))
184 self.current = initWeatherPluginEntryConfig()
190 getConfigListEntry(_("City or Postal Code"), self.current.city),
191 getConfigListEntry(_("Language"), self.current.language)
194 ConfigListScreen.__init__(self, cfglist, session)
197 if self.newmode == 1:
198 config.plugins.WeatherPlugin.entriescount.value = config.plugins.WeatherPlugin.entriescount.value + 1
199 config.plugins.WeatherPlugin.entriescount.save()
200 ConfigListScreen.keySave(self)
201 config.plugins.WeatherPlugin.save()
206 if self.newmode == 1:
207 config.plugins.WeatherPlugin.Entries.remove(self.current)
208 ConfigListScreen.cancelConfirm(self, True)
211 if self.newmode == 1:
214 self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Really delete this WeatherPlugin Entry?"))
216 def deleteConfirm(self, result):
219 config.plugins.WeatherPlugin.entriescount.value = config.plugins.WeatherPlugin.entriescount.value - 1
220 config.plugins.WeatherPlugin.entriescount.save()
221 config.plugins.WeatherPlugin.Entries.remove(self.current)
222 config.plugins.WeatherPlugin.Entries.save()
223 config.plugins.WeatherPlugin.save()