From: Christian Weiske Date: Wed, 16 Nov 2011 22:26:56 +0000 (+0100) Subject: urls from configuration are used now. switching between urls works! X-Git-Tag: v0.3~38 X-Git-Url: https://git.cweiske.de/enigma2-curlytx.git/commitdiff_plain/e8d8cc9ab842d1b22d3c11d991c5561dec805f7e urls from configuration are used now. switching between urls works! --- diff --git a/src/CurlyTx.py b/src/CurlyTx.py index d85143b..6da35c6 100644 --- a/src/CurlyTx.py +++ b/src/CurlyTx.py @@ -24,6 +24,7 @@ class CurlyTx(Screen): """ currentUrl = None + currentPage = None def __init__(self, session, args = None): #self.skin = CurlyTx.skin @@ -39,16 +40,18 @@ class CurlyTx(Screen): self["actions"] = NumberActionMap(["WizardActions", "ColorActions", "InputActions"], { - "ok": self.close, + "ok": self.close, "back": self.close, - "up": self.pageUp, - "down": self.pageDown, + "up": self.pageUp, + "down": self.pageDown, - "red": self.showSettings, - "green": self.reload + "red": self.showSettings, + "green": self.reload, + "yellow": self.prevPage, + "blue": self.nextPage }, -1) - self.loadUrl("http://monitoring.home.cweiske.de/wetter/plain.txt") + self.loadUrl(config.plugins.CurlyTx.defaultPage.value) def pageUp(self): self["text"].pageUp() @@ -56,19 +59,37 @@ class CurlyTx(Screen): def pageDown(self): self["text"].pageDown() + def prevPage(self): + pageId = self.currentPage - 1 + if pageId < 0: + pageId = len(config.plugins.CurlyTx.pages) - 1 + self.loadUrl(pageId) - def mycallback(self, answer): - print "answer:", answer - if answer: - raise Exception("test-crash") - self.close() + def nextPage(self): + pageId = self.currentPage + 1 + if pageId > len(config.plugins.CurlyTx.pages) - 1: + pageId = 0 + self.loadUrl(pageId) def reload(self): - self.loadUrl(self.currentUrl) + self.loadUrl(self.currentPage) + + def loadUrl(self, pageId): + 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"); + else: + self["text"].setText("Invalid page " + pageId); + return + + url = config.plugins.CurlyTx.pages[pageId].uri.value + title = config.plugins.CurlyTx.pages[pageId].title.value + self.currentPage = pageId + self.currentUrl = url - def loadUrl(self, url): + self.setTitle(title) self["text"].setText("Loading ...\n" + url); - self.currentUrl = url client.getPage(url).addCallback(self.urlLoaded).addErrback(self.urlFailed, url)