add help to main screen
[enigma2-curlytx.git] / src / CurlyTx.py
index 6da35c6b1b74519f1a685afea7e2752b7026fb52..7052610c6d2b380af6f99b85b258eeb02a28fd3b 100644 (file)
@@ -1,4 +1,5 @@
 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
@@ -9,7 +10,7 @@ from twisted.web import client
 from . import config
 from Components.config import config
 
-class CurlyTx(Screen):
+class CurlyTx(Screen,HelpableScreen):
     skin = """
         <screen name="CurlyTx" position="center,center" size="560,400" title="CurlyTx" >
          <ePixmap position="0,0" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
@@ -29,6 +30,7 @@ class CurlyTx(Screen):
     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 +41,8 @@ class CurlyTx(Screen):
         self["key_blue"]   = StaticText(_("Next"))
 
 
-        self["actions"] = NumberActionMap(["WizardActions", "ColorActions", "InputActions"], {
+        self["actions"] = NumberActionMap(
+            ["WizardActions", "ColorActions", "InputActions", "HelpActions"], {
                 "ok":   self.close,
                 "back": self.close,
                 "up":   self.pageUp,
@@ -51,8 +54,30 @@ class CurlyTx(Screen):
                 "blue":   self.nextPage
             }, -1)
 
+        self.loadHelp()
         self.loadUrl(config.plugins.CurlyTx.defaultPage.value)
 
+    def loadHelp(self):
+        self.helpList.append((
+                self["actions"], "WizardActions",
+                [("ok", _("Close window"))]))
+        self.helpList.append((
+                self["actions"], "WizardActions",
+                [("back", _("Close window"))]))
+        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"))]))
+
+
     def pageUp(self):
         self["text"].pageUp()
 
@@ -60,25 +85,38 @@ 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
+
         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");
+                self.loadNoPage()
             else:
                 self["text"].setText("Invalid page " + pageId);
             return
@@ -102,10 +140,17 @@ 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"
+        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)