from Plugins.Plugin import PluginDescriptor
from Screens.Screen import Screen
from Components.ActionMap import ActionMap
-from Components.Label import Label
-from Components.Button import Button
-from Tools.LoadPixmap import LoadPixmap
-import xml.etree.cElementTree
-from twisted.internet import reactor, defer
-from twisted.web import client
-import urllib
+from Components.Sources.StaticText import StaticText
+from xml.etree.cElementTree import fromstring as cet_fromstring
+from twisted.internet import defer
+from twisted.web.client import getPage, downloadPage
+from urllib import quote
from Components.Pixmap import Pixmap
from enigma import ePicLoad
-import string
-import os
-from enigma import getDesktop
-from Components.ConfigList import ConfigList, ConfigListScreen
+from os import path as os_path, mkdir as os_mkdir
from Components.AVSwitch import AVSwitch
-from Components.ConfigList import ConfigList, ConfigListScreen
-from Components.config import ConfigSubsection, ConfigSubList, ConfigText, ConfigInteger, config
+from Components.config import ConfigSubsection, ConfigSubList, ConfigInteger, config
from setup import initConfig, WeatherPluginEntriesListConfigScreen
config.plugins.WeatherPlugin = ConfigSubsection()
self.error = error
def getXML(url):
- return client.getPage(url, agent=UserAgent)
+ return getPage(url, agent=UserAgent)
def download(item):
- return client.downloadPage(item.url, file(item.filename, 'wb'), agent=UserAgent)
+ return downloadPage(item.url, file(item.filename, 'wb'), agent=UserAgent)
def main(session,**kwargs):
skin = """
<screen name="WeatherPlugin" position="center,center" size="664,170" title="Weather Plugin">
- <widget name="caption" position="10,20" zPosition="1" size="300,23" font="Regular;22" transparent="1"/>
- <widget name="currentTemp" position="10,45" zPosition="1" size="300,23" font="Regular;22" transparent="1"/>
- <widget name="condition" position="10,80" zPosition="1" size="300,20" font="Regular;18" transparent="1"/>
- <widget name="wind_condition" position="10,105" zPosition="1" size="300,20" font="Regular;18" transparent="1"/>
- <widget name="humidity" position="10,130" zPosition="1" size="300,20" font="Regular;18" valign="bottom" transparent="1"/>
- <widget name="weekday1" position="255,30" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
+ <widget render="Label" source="caption" position="10,20" zPosition="1" size="300,23" font="Regular;22" transparent="1"/>
+ <widget render="Label" source="currentTemp" position="10,45" zPosition="1" size="300,23" font="Regular;22" transparent="1"/>
+ <widget render="Label" source="condition" position="10,80" zPosition="1" size="300,20" font="Regular;18" transparent="1"/>
+ <widget render="Label" source="wind_condition" position="10,105" zPosition="1" size="300,20" font="Regular;18" transparent="1"/>
+ <widget render="Label" source="humidity" position="10,130" zPosition="1" size="300,20" font="Regular;18" valign="bottom" transparent="1"/>
+ <widget render="Label" source="weekday1" position="255,30" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
<widget name="weekday1_icon" position="255,50" zPosition="1" size="72,72" alphatest="blend"/>
- <widget name="weekday1_temp" position="241,130" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
- <widget name="weekday2" position="358,30" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
+ <widget render="Label" source="weekday1_temp" position="241,130" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
+ <widget render="Label" source="weekday2" position="358,30" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
<widget name="weekday2_icon" position="358,50" zPosition="1" size="72,72" alphatest="blend"/>
- <widget name="weekday2_temp" position="344,130" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
- <widget name="weekday3" position="461,30" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
+ <widget render="Label" source="weekday2_temp" position="344,130" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
+ <widget render="Label" source="weekday3" position="461,30" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
<widget name="weekday3_icon" position="461,50" zPosition="1" size="72,72" alphatest="blend"/>
- <widget name="weekday3_temp" position="448,130" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
- <widget name="weekday4" position="564,30" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
+ <widget render="Label" source="weekday3_temp" position="448,130" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
+ <widget render="Label" source="weekday4" position="564,30" zPosition="1" size="72,20" halign="center" valign="center" font="Regular;18" transparent="1"/>
<widget name="weekday4_icon" position="564,50" zPosition="1" size="72,72" alphatest="blend"/>
- <widget name="weekday4_temp" position="550,130" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
- <widget name="statustext" position="0,0" zPosition="1" size="664,170" font="Regular;20" halign="center" valign="center" transparent="1"/>
+ <widget render="Label" source="weekday4_temp" position="550,130" zPosition="1" size="100,20" halign="center" valign="bottom" font="Regular;16" transparent="1"/>
+ <widget render="Label" source="statustext" position="0,0" zPosition="1" size="664,170" font="Regular;20" halign="center" valign="center" transparent="1"/>
</screen>"""
def __init__(self, session):
- self.session = session
Screen.__init__(self, session)
self["actions"] = ActionMap(["WizardActions", "DirectionActions", "ColorActions", "EPGSelectActions"],
{
"left": self.previousItem
}, -1)
- self["statustext"] = Label()
+ self["statustext"] = StaticText()
+ self["caption"] = StaticText()
+ self["currentTemp"] = StaticText()
+ self["condition"] = StaticText()
+ self["wind_condition"] = StaticText()
+ self["humidity"] = StaticText()
- self["caption"] = Label()
- self["currentTemp"] = Label()
- self["condition"] = Label()
- self["wind_condition"] = Label()
- self["humidity"] = Label()
-
- for i in range(1, 5):
- self["weekday%s" % i] = Label()
+ i = 1
+ while i < 5:
+ self["weekday%s" % i] = StaticText()
self["weekday%s_icon" %i] = WeatherIcon()
- self["weekday%s_temp" % i] = Label()
+ self["weekday%s_temp" % i] = StaticText()
+ i += 1
+ del i
self.appdir = "/usr/lib/enigma2/python/Plugins/Extensions/WeatherPlugin/icons/"
- if not os.path.exists(self.appdir):
- os.mkdir(self.appdir)
+ if not os_path.exists(self.appdir):
+ os_mkdir(self.appdir)
self.weatherPluginEntryIndex = -1
self.weatherPluginEntryCount = config.plugins.WeatherPlugin.entriescount.value
def startRun(self):
if self.weatherPluginEntry is not None:
- self["statustext"].setText(_("Getting weather information..."))
- url = ("http://www.google.com/ig/api?weather=%s&hl=%s" % (urllib.quote(self.weatherPluginEntry.city.value), self.weatherPluginEntry.language.value))
+ self["statustext"].text = _("Getting weather information...")
+ url = ("http://www.google.com/ig/api?weather=%s&hl=%s" % (quote(self.weatherPluginEntry.city.value), self.weatherPluginEntry.language.value))
getXML(url).addCallback(self.xmlCallback).addErrback(self.error)
else:
- self["statustext"].setText(_("No locations defined...\nPress 'Menu' to do that."))
- self["statustext"].show()
+ self["statustext"].text = _("No locations defined...\nPress 'Menu' to do that.")
def nextItem(self):
if self.weatherPluginEntryCount != 0:
self.startRun()
def clearFields(self):
- self["caption"].setText("")
- self["currentTemp"].setText("")
- self["condition"].setText("")
- self["wind_condition"].setText("")
- self["humidity"].setText("")
- for i in range(1, 5):
- self["weekday%s" % i].setText("")
+ self["caption"].text = ""
+ self["currentTemp"].text = ""
+ self["condition"].text = ""
+ self["wind_condition"].text = ""
+ self["humidity"].text = ""
+ i = 1
+ while i < 5:
+ self["weekday%s" % i].text = ""
self["weekday%s_icon" %i].hide()
- self["weekday%s_temp" % i].setText("")
+ self["weekday%s_temp" % i].text = ""
+ i += 1
def errorIconDownload(self, error = None, item = None):
item.error = True
self["weekday%s_icon" % index].show()
def xmlCallback(self, xmlstring):
- self["statustext"].hide()
+ self["statustext"].text = ""
metric = 0
index = 0
UnitSystemText = "F"
IconDownloadList = []
- root = xml.etree.cElementTree.fromstring(xmlstring)
+ root = cet_fromstring(xmlstring)
for childs in root.findall("weather"):
for items in childs:
if items.tag == "problem_cause":
- self["statustext"].setText(items.attrib.get("data").encode("utf-8", 'ignore'))
- self["statustext"].show()
- if items.tag == "forecast_information":
+ self["statustext"].text = items.attrib.get("data").encode("utf-8", 'ignore')
+ elif items.tag == "forecast_information":
for items2 in items:
if items2.tag == "city":
- self["caption"].setText(items2.attrib.get("data").encode("utf-8", 'ignore'))
+ self["caption"].text = items2.attrib.get("data").encode("utf-8", 'ignore')
elif items2.tag == "unit_system":
if items2.attrib.get("data").encode("utf-8", 'ignore') == "SI":
metric = 1
elif items.tag == "current_conditions":
for items2 in items:
if items2.tag == "condition":
- self["condition"].setText(_("Current: %s") % items2.attrib.get("data").encode("utf-8", 'ignore'))
+ self["condition"].text = _("Current: %s") % items2.attrib.get("data").encode("utf-8", 'ignore')
elif items2.tag == "temp_f" and metric == 0:
- self["currentTemp"].setText( ("%s °F" % items2.attrib.get("data").encode("utf-8", 'ignore')) )
+ self["currentTemp"].text = ("%s °F" % items2.attrib.get("data").encode("utf-8", 'ignore'))
elif items2.tag == "temp_c" and metric == 1:
- self["currentTemp"].setText( ("%s °C" % items2.attrib.get("data").encode("utf-8", 'ignore')) )
+ self["currentTemp"].text = ("%s °C" % items2.attrib.get("data").encode("utf-8", 'ignore'))
elif items2.tag == "humidity":
- self["humidity"].setText(items2.attrib.get("data").encode("utf-8", 'ignore'))
+ self["humidity"].text = items2.attrib.get("data").encode("utf-8", 'ignore')
elif items2.tag == "wind_condition":
- self["wind_condition"].setText(items2.attrib.get("data").encode("utf-8", 'ignore'))
+ self["wind_condition"].text = items2.attrib.get("data").encode("utf-8", 'ignore')
elif items.tag == "forecast_conditions":
index = index + 1
lowTemp = ""
icon = ""
for items2 in items:
if items2.tag == "day_of_week":
- self["weekday%s" % index].setText(items2.attrib.get("data").encode("utf-8", 'ignore'))
- if items2.tag == "low":
+ self["weekday%s" % index].text = items2.attrib.get("data").encode("utf-8", 'ignore')
+ elif items2.tag == "low":
lowTemp = items2.attrib.get("data").encode("utf-8", 'ignore')
- if items2.tag == "high":
+ elif items2.tag == "high":
highTemp = items2.attrib.get("data").encode("utf-8", 'ignore')
- self["weekday%s_temp" % index].setText("%s °%s | %s °%s" % (highTemp, UnitSystemText, lowTemp, UnitSystemText))
- if items2.tag == "icon":
+ self["weekday%s_temp" % index].text = "%s °%s | %s °%s" % (highTemp, UnitSystemText, lowTemp, UnitSystemText)
+ elif items2.tag == "icon":
url = "http://www.google.com%s" % items2.attrib.get("data").encode("utf-8", 'ignore')
- parts = string.split(url,"/")
+ parts = url.split("/")
filename = self.appdir + parts[-1]
- if not os.path.exists(filename):
+ if not os_path.exists(filename):
IconDownloadList.append(WeatherIconItem(url = url,filename = filename, index = index))
else:
self.showIcon(index,filename)
def error(self, error = None):
if error is not None:
self.clearFields()
- self["statustext"].setText(str(error.getErrorMessage()))
- self["statustext"].show()
-
-
+ self["statustext"].text = str(error.getErrorMessage())
+
+
class WeatherIcon(Pixmap):
def __init__(self):
Pixmap.__init__(self)
# GNU General Public License for more details.
#
-from enigma import eListboxPythonMultiContent, eListbox, gFont, \
- RT_HALIGN_LEFT, RT_VALIGN_CENTER
+from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, \
+ RT_VALIGN_CENTER
from Screens.Screen import Screen
from Screens.MessageBox import MessageBox
from Components.MenuList import MenuList
-from Components.Button import Button
-from Components.config import config
-from Components.ActionMap import ActionMap, NumberActionMap
+from Components.Sources.StaticText import StaticText
+from Components.ActionMap import ActionMap
from Components.ConfigList import ConfigList, ConfigListScreen
-from Components.config import ConfigSubsection, ConfigSubList, ConfigIP, ConfigInteger, ConfigSelection, ConfigText, ConfigYesNo, getConfigListEntry, configfile
+from Components.config import ConfigSubsection, ConfigText, \
+ getConfigListEntry, config, configfile
def initWeatherPluginEntryConfig():
- config.plugins.WeatherPlugin.Entries.append(ConfigSubsection())
- i = len(config.plugins.WeatherPlugin.Entries) -1
- config.plugins.WeatherPlugin.Entries[i].city = ConfigText(default = "Heidelberg", visible_width = 50, fixed_size = False)
- config.plugins.WeatherPlugin.Entries[i].language = ConfigText(default = "de", visible_width = 50, fixed_size = False)
- return config.plugins.WeatherPlugin.Entries[i]
+ s = ConfigSubsection()
+ s.city = ConfigText(default = "Heidelberg", visible_width = 50, fixed_size = False)
+ s.language = ConfigText(default = "de", visible_width = 50, fixed_size = False)
+ config.plugins.WeatherPlugin.Entries.append(s)
+ return s
def initConfig():
count = config.plugins.WeatherPlugin.entriescount.value
class WeatherPluginEntriesListConfigScreen(Screen):
skin = """
<screen position="center,center" size="550,400" title="%s" >
- <widget name="city" position="5,0" size="150,50" font="Regular;20" halign="left"/>
- <widget name="language" position="155,0" size="150,50" font="Regular;20" halign="left"/>
+ <widget render="Label" source="city" position="5,0" size="150,50" font="Regular;20" halign="left"/>
+ <widget render="Label" source="language" position="155,0" size="150,50" font="Regular;20" halign="left"/>
<widget name="entrylist" position="0,50" size="550,300" scrollbarMode="showOnDemand"/>
- <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" />
- <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" />
- <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" />
- <ePixmap name="red" position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
- <ePixmap name="yellow" position="280,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
- <ePixmap name="blue" position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
+ <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" />
+ <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" />
+ <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" />
+ <ePixmap position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+ <ePixmap position="280,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
+ <ePixmap position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
</screen>""" % _("WeatherPlugin: List of Entries")
def __init__(self, session):
Screen.__init__(self, session)
- self.session = session
- self["city"] = Button(_("City"))
- self["language"] = Button(_("Language"))
- self["key_red"] = Button(_("Add"))
- self["key_yellow"] = Button(_("Edit"))
- self["key_blue"] = Button(_("Delete"))
+
+ self["city"] = StaticText(_("City"))
+ self["language"] = StaticText(_("Language"))
+ self["key_red"] = StaticText(_("Add"))
+ self["key_yellow"] = StaticText(_("Edit"))
+ self["key_blue"] = StaticText(_("Delete"))
self["entrylist"] = WeatherPluginEntryList([])
self["actions"] = ActionMap(["WizardActions","MenuActions","ShortcutActions"],
{
if not result:
return
sel = self["entrylist"].l.getCurrentSelection()[0]
- config.plugins.WeatherPlugin.entriescount.value = config.plugins.WeatherPlugin.entriescount.value - 1
+ config.plugins.WeatherPlugin.entriescount.value -= 1
config.plugins.WeatherPlugin.entriescount.save()
config.plugins.WeatherPlugin.Entries.remove(sel)
config.plugins.WeatherPlugin.Entries.save()
MenuList.__init__(self, list, enableWrapAround, eListboxPythonMultiContent)
self.l.setFont(0, gFont("Regular", 20))
self.l.setFont(1, gFont("Regular", 18))
+
def postWidgetCreate(self, instance):
MenuList.postWidgetCreate(self, instance)
instance.setItemHeight(20)
return self.instance.getCurrentIndex()
def buildList(self):
- self.list=[]
+ list = []
for c in config.plugins.WeatherPlugin.Entries:
- res = [c]
- res.append((eListboxPythonMultiContent.TYPE_TEXT, 5, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.city.value)))
- res.append((eListboxPythonMultiContent.TYPE_TEXT, 155, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.language.value)))
- self.list.append(res)
- self.l.setList(self.list)
+ res = [
+ c,
+ (eListboxPythonMultiContent.TYPE_TEXT, 5, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.city.value)),
+ (eListboxPythonMultiContent.TYPE_TEXT, 155, 0, 150, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, str(c.language.value)),
+ ]
+ list.append(res)
+ self.list = list
+ self.l.setList(list)
self.moveToIndex(0)
class WeatherPluginEntryConfigScreen(ConfigListScreen, Screen):
skin = """
<screen name="WeatherPluginEntryConfigScreen" position="center,center" size="550,400" title="%s">
<widget name="config" position="20,10" size="520,330" scrollbarMode="showOnDemand" />
- <ePixmap name="red" position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
- <ePixmap name="green" position="140,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
- <ePixmap name="blue" position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
+ <ePixmap position="0,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
+ <ePixmap position="140,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
+ <ePixmap position="420,350" zPosition="4" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
- <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" />
- <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" />
- <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" />
- </screen>""" % _("WeatherPlugin: Edit Entry")
+ <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" />
+ <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" />
+ <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" />
+ </screen>"""
def __init__(self, session, entry):
- self.session = session
Screen.__init__(self, session)
+ self.title = _("WeatherPlugin: Edit Entry")
self["actions"] = ActionMap(["SetupActions", "ColorActions"],
{
"cancel": self.keyCancel
}, -2)
- self["key_red"] = Button(_("Cancel"))
- self["key_green"] = Button(_("OK"))
- self["key_blue"] = Button(_("Delete"))
+ self["key_red"] = StaticText(_("Cancel"))
+ self["key_green"] = StaticText(_("OK"))
+ self["key_blue"] = StaticText(_("Delete"))
if entry is None:
self.newmode = 1