X-Git-Url: https://git.cweiske.de/enigma2-curlytx.git/blobdiff_plain/e8d8cc9ab842d1b22d3c11d991c5561dec805f7e..d8683e34bef971a36bb56e81af8f13d19c53ebf2:/src/CurlyTx.py diff --git a/src/CurlyTx.py b/src/CurlyTx.py index 6da35c6..09d9ad1 100644 --- a/src/CurlyTx.py +++ b/src/CurlyTx.py @@ -1,15 +1,19 @@ +from . import _ + from Screens.Screen import Screen +from Screens.HelpMenu import HelpableScreen from Screens.MessageBox import MessageBox from Components.Label import Label from Components.ScrollLabel import ScrollLabel -from Components.ActionMap import NumberActionMap +from Components.ActionMap import ActionMap from Components.Sources.StaticText import StaticText from twisted.web import client +from enigma import gFont from . import config from Components.config import config -class CurlyTx(Screen): +class CurlyTx(Screen,HelpableScreen): skin = """ @@ -25,10 +29,12 @@ class CurlyTx(Screen): currentUrl = None currentPage = None + currentFontSize = 20 def __init__(self, session, args = None): #self.skin = CurlyTx.skin Screen.__init__(self, session) + HelpableScreen.__init__(self) #self.skinName = [ "CurlyTx", "Setup" ] self["text"] = ScrollLabel("foo") @@ -39,7 +45,8 @@ class CurlyTx(Screen): self["key_blue"] = StaticText(_("Next")) - self["actions"] = NumberActionMap(["WizardActions", "ColorActions", "InputActions"], { + self["actions"] = ActionMap( + ["WizardActions", "ColorActions", "InputActions"], { "ok": self.close, "back": self.close, "up": self.pageUp, @@ -51,7 +58,54 @@ class CurlyTx(Screen): "blue": self.nextPage }, -1) + self.loadHelp() + self.loadButtons() self.loadUrl(config.plugins.CurlyTx.defaultPage.value) + self.onLayoutFinish.append(self.setTextFont) + + def loadHelp(self): + self.helpList.append(( + self["actions"], "WizardActions", + [("up", _("Scroll page contents up"))])) + self.helpList.append(( + self["actions"], "WizardActions", + [("down", _("Scroll page contents down"))])) + self.helpList.append(( + self["actions"], "ColorActions", + [("red", _("Show program settings"))])) + self.helpList.append(( + self["actions"], "ColorActions", + [("green", _("Reload current page URL"))])) + self.helpList.append(( + self["actions"], "ColorActions", + [("yellow", _("Switch to next configured page URL"))])) + self.helpList.append(( + self["actions"], "ColorActions", + [("blue", _("Switch to previous configured page URL"))])) + self.helpList.append(( + self["actions"], "WizardActions", + [("ok", _("Close window"))])) + self.helpList.append(( + self["actions"], "WizardActions", + [("back", _("Close window"))])) + self.helpList.append(( + self["actions"], "HelpActions", + [("displayHelp", _("Show this help screen"))])) + + def loadButtons(self): + pageCount = len(config.plugins.CurlyTx.pages) + if pageCount == 0: + self["key_green"].setText("") + self["key_yellow"].setText("") + self["key_blue"].setText("") + elif pageCount == 1: + self["key_green"].setText(_("Reload")) + self["key_yellow"].setText("") + self["key_blue"].setText("") + else: + self["key_green"].setText(_("Reload")) + self["key_yellow"].setText(_("Prev")) + self["key_blue"].setText(_("Next")) def pageUp(self): self["text"].pageUp() @@ -60,39 +114,64 @@ class CurlyTx(Screen): self["text"].pageDown() def prevPage(self): + if self.currentPage == None: + return + pageId = self.currentPage - 1 if pageId < 0: pageId = len(config.plugins.CurlyTx.pages) - 1 self.loadUrl(pageId) def nextPage(self): + if self.currentPage == None: + return + pageId = self.currentPage + 1 if pageId > len(config.plugins.CurlyTx.pages) - 1: pageId = 0 self.loadUrl(pageId) def reload(self): + if self.currentPage == None: + return + self.loadUrl(self.currentPage) def loadUrl(self, pageId): + if pageId == None: + self.loadNoPage() + return + + cfg = config.plugins.CurlyTx + pageCount = len(cfg.pages) pageId = int(pageId) - if pageId > (len(config.plugins.CurlyTx.pages) - 1): - if len(config.plugins.CurlyTx.pages) == 0: - self["text"].setText("Go and add a page in the settings"); + if pageId > (pageCount - 1): + if len(cfg.pages) == 0: + self.loadNoPage() else: self["text"].setText("Invalid page " + pageId); return - url = config.plugins.CurlyTx.pages[pageId].uri.value - title = config.plugins.CurlyTx.pages[pageId].title.value + url = cfg.pages[pageId].uri.value + title = cfg.pages[pageId].title.value + + if pageCount > 1: + title = "{0} [{1}/{2}]".format(title, pageId + 1, pageCount) + self.currentPage = pageId self.currentUrl = url + self.currentFontSize = cfg.pages[pageId].fontSize.value self.setTitle(title) + self.setTextFont() self["text"].setText("Loading ...\n" + url); client.getPage(url).addCallback(self.urlLoaded).addErrback(self.urlFailed, url) + def setTextFont(self): + if self["text"].long_text is not None: + self["text"].long_text.setFont(gFont("Console", self.currentFontSize)) + def urlLoaded(self, html): self["text"].setText(html) @@ -102,10 +181,18 @@ class CurlyTx(Screen): + "\n\nURL: " + url ) + def loadNoPage(self): + self["text"].setText("Go and add a page in the settings"); + def showSettings(self): - #self.session.openWithCallback(self.setConf ,Pic_Setup) from CurlyTxSettings import CurlyTxSettings self.session.openWithCallback(self.onSettingsChanged, CurlyTxSettings) def onSettingsChanged(self): - "fixme" + self.loadButtons() + if len(config.plugins.CurlyTx.pages) == 0: + self.currentPage = None + self.loadUrl(self.currentPage) + elif self.currentPage == None: + self.currentPage = 0 + self.loadUrl(self.currentPage)