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_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" />
59 <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" />
60 <ePixmap position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
61 <ePixmap position="280,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
62 <ePixmap position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
63 </screen>""" % _("WeatherPlugin: List of Entries")
65 def __init__(self, session):
66 Screen.__init__(self, session)
68 self["city"] = StaticText(_("City"))
69 self["language"] = StaticText(_("Language"))
70 self["key_red"] = StaticText(_("Add"))
71 self["key_yellow"] = StaticText(_("Edit"))
72 self["key_blue"] = StaticText(_("Delete"))
73 self["entrylist"] = WeatherPluginEntryList([])
74 self["actions"] = ActionMap(["WizardActions","MenuActions","ShortcutActions"],
77 "back" : self.keyClose,
79 "yellow": self.keyYellow,
80 "blue": self.keyDelete,
85 self["entrylist"].buildList()
91 self.session.openWithCallback(self.updateList,WeatherPluginEntryConfigScreen,None)
94 try:sel = self["entrylist"].l.getCurrentSelection()[0]
96 self.close(self["entrylist"].getCurrentIndex(), sel)
99 try:sel = self["entrylist"].l.getCurrentSelection()[0]
103 self.session.openWithCallback(self.updateList,WeatherPluginEntryConfigScreen,sel)
106 try:sel = self["entrylist"].l.getCurrentSelection()[0]
110 self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Really delete this WeatherPlugin Entry?"))
112 def deleteConfirm(self, result):
115 sel = self["entrylist"].l.getCurrentSelection()[0]
116 config.plugins.WeatherPlugin.entriescount.value -= 1
117 config.plugins.WeatherPlugin.entriescount.save()
118 config.plugins.WeatherPlugin.Entries.remove(sel)
119 config.plugins.WeatherPlugin.Entries.save()
120 config.plugins.WeatherPlugin.save()
124 class WeatherPluginEntryList(MenuList):
125 def __init__(self, list, enableWrapAround = True):
126 MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
127 self.l.setFont(0, gFont("Regular", 20))
128 self.l.setFont(1, gFont("Regular", 18))
130 def postWidgetCreate(self, instance):
131 MenuList.postWidgetCreate(self, instance)
132 instance.setItemHeight(20)
134 def getCurrentIndex(self):
135 return self.instance.getCurrentIndex()
139 for c in config.plugins.WeatherPlugin.Entries:
142 (eListboxPythonMultiContent.TYPE_TEXT, 5, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.city.value)),
143 (eListboxPythonMultiContent.TYPE_TEXT, 155, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.language.value)),
150 class WeatherPluginEntryConfigScreen(ConfigListScreen, Screen):
152 <screen name="WeatherPluginEntryConfigScreen" position="center,center" size="550,400" title="%s">
153 <widget name="config" position="20,10" size="520,330" scrollbarMode="showOnDemand" />
154 <ePixmap position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
155 <ePixmap position="140,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
156 <ePixmap position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
158 <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" />
159 <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" />
160 <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" />
161 </screen>""" % _("WeatherPlugin: Edit Entry")
163 def __init__(self, session, entry):
164 Screen.__init__(self, session)
166 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
168 "green": self.keySave,
169 "red": self.keyCancel,
170 "blue": self.keyDelete,
171 "cancel": self.keyCancel
174 self["key_red"] = StaticText(_("Cancel"))
175 self["key_green"] = StaticText(_("OK"))
176 self["key_blue"] = StaticText(_("Delete"))
180 self.current = initWeatherPluginEntryConfig()
186 getConfigListEntry(_("City or Postal Code"), self.current.city),
187 getConfigListEntry(_("Language"), self.current.language)
190 ConfigListScreen.__init__(self, cfglist, session)
193 if self.newmode == 1:
194 config.plugins.WeatherPlugin.entriescount.value = config.plugins.WeatherPlugin.entriescount.value + 1
195 config.plugins.WeatherPlugin.entriescount.save()
196 ConfigListScreen.keySave(self)
197 config.plugins.WeatherPlugin.save()
202 if self.newmode == 1:
203 config.plugins.WeatherPlugin.Entries.remove(self.current)
204 ConfigListScreen.cancelConfirm(self, True)
207 if self.newmode == 1:
210 self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Really delete this WeatherPlugin Entry?"))
212 def deleteConfirm(self, result):
215 config.plugins.WeatherPlugin.entriescount.value = config.plugins.WeatherPlugin.entriescount.value - 1
216 config.plugins.WeatherPlugin.entriescount.save()
217 config.plugins.WeatherPlugin.Entries.remove(self.current)
218 config.plugins.WeatherPlugin.Entries.save()
219 config.plugins.WeatherPlugin.save()