move url loading after layout finishing to prevent crashes.
[enigma2-curlytx.git] / src / CurlyTx.py
index b6df45d..6ce0efd 100644 (file)
@@ -1,3 +1,8 @@
+# -*- coding: utf-8 -*-
+# CurlyTx main window
+# Copyright (C) 2011 Christian Weiske <cweiske@cweiske.de>
+# License: GPLv3 or later
+
 from . import _
 
 from Screens.Screen import Screen
@@ -16,16 +21,16 @@ from Components.config import config
 
 class CurlyTx(Screen,HelpableScreen):
     skin = """
-        <screen name="CurlyTx" position="center,center" size="560,400" title="CurlyTx" >
+        <screen name="CurlyTx" position="center,center" size="560,430" title="CurlyTx" >
          <ePixmap position="0,0" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
          <ePixmap position="140,0" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
          <ePixmap position="280,0" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
          <ePixmap position="420,0" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
-         <widget source="key_red" render="Label" position="0,0" zPosition="1" 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,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" 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,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
-         <widget name="text" position="5,45" size="550,350" font="Console;20" />
+         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" />
+         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" />
+         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" />
+         <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" />
+         <widget name="text" position="5,45" size="550,380" font="Console;20" />
         </screen>"""
 
     currentUrl = None
@@ -65,8 +70,11 @@ class CurlyTx(Screen,HelpableScreen):
 
         self.loadHelp()
         self.loadButtons()
+        self.onLayoutFinish.append(self.afterLayout)
+
+    def afterLayout(self):
+        self.setTextFont
         self.loadUrl(config.plugins.CurlyTx.defaultPage.value)
-        self.onLayoutFinish.append(self.setTextFont)
 
     def loadHelp(self):
         self.helpList.append((
@@ -157,7 +165,7 @@ class CurlyTx(Screen,HelpableScreen):
             if len(cfg.pages) == 0:
                 self.loadNoPage()
             else:
-                self["text"].setText("Invalid page " + pageId);
+                self["text"].setText(_("Invalid page") + " " + pageId);
             return
 
         url   = cfg.pages[pageId].uri.value
@@ -172,7 +180,7 @@ class CurlyTx(Screen,HelpableScreen):
 
         self.setTitle(title)
         self.setTextFont()
-        self["text"].setText("Loading ...\n" + url);
+        self["text"].setText(_("Loading ...") + "\n" + url);
 
         self.getPageWebClient(url).addCallback(self.urlLoaded).addErrback(self.urlFailed, url)
 
@@ -185,20 +193,20 @@ class CurlyTx(Screen,HelpableScreen):
 
     def urlFailed(self, error, url):
         self["text"].setText(
-            "Error fetching URL:\n " + error.getErrorMessage()
+            _("Error fetching URL:") + "\n " + error.getErrorMessage()
             + "\n\nURL: " + url
             )
 
     def loadNoPage(self):
-        self["text"].setText("Go and add a page in the settings");
+        self["text"].setText(_("Go and add a page in the settings"));
 
     def showHeader(self):
         if self.showingHeaders:
             self["text"].setText(self.pageContent)
             self.pageContent    = None
             self.showingHeaders = False
-        else:
-            headers = "HTTP response headers for\n" + self.currentUrl + "\n\n"
+        elif self.httpGetterFactory.response_headers:
+            headers = _("HTTP response headers for") + "\n" + self.currentUrl + "\n\n"
             for (k, v) in self.httpGetterFactory.response_headers.items():
                 headers += k + ": " + ("\n" + k + ": ").join(v) + "\n"
             self.pageContent = self["text"].getText()