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, eListbox, gFont, \
21 RT_HALIGN_LEFT, RT_VALIGN_CENTER
22 from Screens.Screen import Screen
23 from Screens.MessageBox import MessageBox
24 from Components.MenuList import MenuList
25 from Components.Button import Button
26 from Components.config import config
27 from Components.ActionMap import ActionMap, NumberActionMap
28 from Components.ConfigList import ConfigList, ConfigListScreen
29 from Components.config import ConfigSubsection, ConfigSubList, ConfigIP, ConfigInteger, ConfigSelection, ConfigText, ConfigYesNo, getConfigListEntry, configfile
32 def initWeatherPluginEntryConfig():
33 config.plugins.WeatherPlugin.Entries.append(ConfigSubsection())
34 i = len(config.plugins.WeatherPlugin.Entries) -1
35 config.plugins.WeatherPlugin.Entries[i].city = ConfigText(default = "Heidelberg", visible_width = 50, fixed_size = False)
36 config.plugins.WeatherPlugin.Entries[i].language = ConfigText(default = "de", visible_width = 50, fixed_size = False)
37 return config.plugins.WeatherPlugin.Entries[i]
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 name="city" position="5,0" size="150,50" font="Regular;20" halign="left"/>
51 <widget name="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 name="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 name="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 name="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 name="red" position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
57 <ePixmap name="yellow" position="280,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
58 <ePixmap name="blue" 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)
63 self.session = session
64 self["city"] = Button(_("City"))
65 self["language"] = Button(_("Language"))
66 self["key_red"] = Button(_("Add"))
67 self["key_yellow"] = Button(_("Edit"))
68 self["key_blue"] = Button(_("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 = 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))
125 def postWidgetCreate(self, instance):
126 MenuList.postWidgetCreate(self, instance)
127 instance.setItemHeight(20)
129 def getCurrentIndex(self):
130 return self.instance.getCurrentIndex()
134 for c in config.plugins.WeatherPlugin.Entries:
136 res.append((eListboxPythonMultiContent.TYPE_TEXT, 5, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.city.value)))
137 res.append((eListboxPythonMultiContent.TYPE_TEXT, 155, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.language.value)))
138 self.list.append(res)
139 self.l.setList(self.list)
142 class WeatherPluginEntryConfigScreen(ConfigListScreen, Screen):
144 <screen name="WeatherPluginEntryConfigScreen" position="center,center" size="550,400" title="%s">
145 <widget name="config" position="20,10" size="520,330" scrollbarMode="showOnDemand" />
146 <ePixmap name="red" position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
147 <ePixmap name="green" position="140,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
148 <ePixmap name="blue" position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
150 <widget name="key_red" position="0,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
151 <widget name="key_green" position="140,350" zPosition="5" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
152 <widget name="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" />
153 </screen>""" % _("WeatherPlugin: Edit Entry")
155 def __init__(self, session, entry):
156 self.session = session
157 Screen.__init__(self, session)
159 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
161 "green": self.keySave,
162 "red": self.keyCancel,
163 "blue": self.keyDelete,
164 "cancel": self.keyCancel
167 self["key_red"] = Button(_("Cancel"))
168 self["key_green"] = Button(_("OK"))
169 self["key_blue"] = Button(_("Delete"))
173 self.current = initWeatherPluginEntryConfig()
179 getConfigListEntry(_("City or Postal Code"), self.current.city),
180 getConfigListEntry(_("Language"), self.current.language)
183 ConfigListScreen.__init__(self, cfglist, session)
186 if self.newmode == 1:
187 config.plugins.WeatherPlugin.entriescount.value = config.plugins.WeatherPlugin.entriescount.value + 1
188 config.plugins.WeatherPlugin.entriescount.save()
189 ConfigListScreen.keySave(self)
190 config.plugins.WeatherPlugin.save()
195 if self.newmode == 1:
196 config.plugins.WeatherPlugin.Entries.remove(self.current)
197 ConfigListScreen.cancelConfirm(self, True)
200 if self.newmode == 1:
203 self.session.openWithCallback(self.deleteConfirm, MessageBox, _("Really delete this WeatherPlugin Entry?"))
205 def deleteConfirm(self, result):
208 config.plugins.WeatherPlugin.entriescount.value = config.plugins.WeatherPlugin.entriescount.value - 1
209 config.plugins.WeatherPlugin.entriescount.save()
210 config.plugins.WeatherPlugin.Entries.remove(self.current)
211 config.plugins.WeatherPlugin.Entries.save()
212 config.plugins.WeatherPlugin.save()