basic settings work now
[enigma2-curlytx.git] / src / CurlyTx.py
1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Components.Label import Label
4 from Components.ScrollLabel import ScrollLabel
5 from Components.ActionMap import NumberActionMap
6 from Components.Sources.StaticText import StaticText
7 from twisted.web import client
8
9 from . import config
10 from Components.config import config
11
12 class CurlyTx(Screen):
13     skin = """
14         <screen name="CurlyTx" position="center,center" size="560,400" title="CurlyTx" >
15           <ePixmap position="0,0" size="140,40" pixmap="skin_default/buttons/red.png" transparent="1" alphatest="on" />
16           <ePixmap position="140,0" size="140,40" pixmap="skin_default/buttons/green.png" transparent="1" alphatest="on" />
17           <ePixmap position="280,0" size="140,40" pixmap="skin_default/buttons/yellow.png" transparent="1" alphatest="on" />
18           <ePixmap position="420,0" size="140,40" pixmap="skin_default/buttons/blue.png" transparent="1" alphatest="on" />
19           <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" />
20           <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" />
21           <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" />
22           <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" />
23           <widget name="text" position="5,45" size="550,350" font="Console;20" />
24         </screen>"""
25
26     currentUrl = None
27
28     def __init__(self, session, args = None):
29         #self.skin = CurlyTx.skin
30         Screen.__init__(self, session)
31         #self.skinName = [ "CurlyTx", "Setup" ]
32
33         self["text"] = ScrollLabel("foo")
34
35         self["key_red"]    = StaticText(_("Settings"))
36         self["key_green"]  = StaticText(_("Reload"))
37         self["key_yellow"] = StaticText(_("Prev"))
38         self["key_blue"]   = StaticText(_("Next"))
39
40
41         self["actions"] = NumberActionMap(["WizardActions", "ColorActions", "InputActions"], {
42                 "ok": self.close,
43                 "back": self.close,
44                 "up": self.pageUp,
45                 "down": self.pageDown,
46
47                 "red": self.showSettings,
48                 "green": self.reload
49             }, -1)
50
51         self.loadUrl("http://monitoring.home.cweiske.de/wetter/plain.txt")
52
53     def pageUp(self):
54         self["text"].pageUp()
55
56     def pageDown(self):
57         self["text"].pageDown()
58
59
60     def mycallback(self, answer):
61         print "answer:", answer
62         if answer:
63             raise Exception("test-crash")
64         self.close()
65
66     def reload(self):
67         self.loadUrl(self.currentUrl)
68
69     def loadUrl(self, url):
70         self["text"].setText("Loading ...\n" + url);
71         self.currentUrl = url
72
73         client.getPage(url).addCallback(self.urlLoaded).addErrback(self.urlFailed, url)
74
75     def urlLoaded(self, html):
76         self["text"].setText(html)
77
78     def urlFailed(self, error, url):
79         self["text"].setText(
80             "Error fetching URL:\n " + error.getErrorMessage()
81             + "\n\nURL: " + url
82             )
83
84     def showSettings(self):
85         #self.session.openWithCallback(self.setConf ,Pic_Setup)
86         from CurlyTxSettings import CurlyTxSettings
87         self.session.openWithCallback(self.onSettingsChanged, CurlyTxSettings)
88
89     def onSettingsChanged(self):
90         "fixme"