make code more readable
[enigma2-curlytx.git] / src / CurlyTx.py
index d4853f9..09d9ad1 100644 (file)
@@ -8,6 +8,7 @@ from Components.ScrollLabel import ScrollLabel
 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
@@ -28,6 +29,7 @@ class CurlyTx(Screen,HelpableScreen):
 
     currentUrl = None
     currentPage = None
+    currentFontSize = 20
 
     def __init__(self, session, args = None):
         #self.skin = CurlyTx.skin
@@ -57,7 +59,9 @@ class CurlyTx(Screen,HelpableScreen):
             }, -1)
 
         self.loadHelp()
+        self.loadButtons()
         self.loadUrl(config.plugins.CurlyTx.defaultPage.value)
+        self.onLayoutFinish.append(self.setTextFont)
 
     def loadHelp(self):
         self.helpList.append((
@@ -88,6 +92,21 @@ class CurlyTx(Screen,HelpableScreen):
                 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()
 
@@ -123,24 +142,36 @@ class CurlyTx(Screen,HelpableScreen):
             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:
+        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)
 
@@ -158,6 +189,7 @@ class CurlyTx(Screen,HelpableScreen):
         self.session.openWithCallback(self.onSettingsChanged, CurlyTxSettings)
 
     def onSettingsChanged(self):
+        self.loadButtons()
         if len(config.plugins.CurlyTx.pages) == 0:
             self.currentPage = None
             self.loadUrl(self.currentPage)