ecasa: add basic setup dialog
[enigma2-plugins.git] / ecasa / src / EcasaSetup.py
1 # GUI (Screens)
2 from Screens.Screen import Screen
3 from Components.ConfigList import ConfigListScreen
4
5 # GUI (Summary)
6 from Screens.Setup import SetupSummary
7
8 # GUI (Components)
9 from Components.ActionMap import ActionMap
10 from Components.Sources.StaticText import StaticText
11
12 # Configuration
13 from Components.config import config, getConfigListEntry
14
15 class EcasaSetup(Screen, ConfigListScreen):
16         skin = """<screen name="EcasaSetup" position="center,center" size="565,370">
17                 <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" alphatest="on" />
18                 <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" alphatest="on" />
19                 <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" alphatest="on" />
20                 <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" alphatest="on" />
21                 <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
22                 <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
23                 <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" />
24                 <widget source="key_blue" render="Label" position="420,0" zPosition="1" size="140,40" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" />
25                 <widget name="config" position="5,50" size="555,250" scrollbarMode="showOnDemand" />
26                 <ePixmap pixmap="skin_default/div-h.png" position="0,301" zPosition="1" size="565,2" />
27                 <widget source="help" render="Label" position="5,305" size="555,63" font="Regular;21" />
28         </screen>"""
29
30         def __init__(self, session):
31                 Screen.__init__(self, session)
32
33                 # Summary
34                 self.setup_title = _("eCasa Setup")
35                 self.onChangedEntry = []
36
37                 ConfigListScreen.__init__(
38                         self,
39                         [
40                                 getConfigListEntry(_("Google Username"), config.plugins.ecasa.google_username, _("Username to use for authentication with google. Leave empty for unauthenticated use.")),
41                                 getConfigListEntry(_("Google Password"), config.plugins.ecasa.google_password, _("Password to the google account.")),
42                                 #getConfigListEntry(_("Cache directory"), config.plugins.ecasa.cache, _("Directory used to store cached images.")),
43                         ],
44                         session = session,
45                         on_change = self.changed
46                 )
47                 def selectionChanged():
48                         if self["config"].current:
49                                 self["config"].current[1].onDeselect(self.session)
50                         self["config"].current = self["config"].getCurrent()
51                         if self["config"].current:
52                                 self["config"].current[1].onSelect(self.session)
53                         for x in self["config"].onSelectionChanged:
54                                 x()
55                 self["config"].selectionChanged = selectionChanged
56                 self["config"].onSelectionChanged.append(self.updateHelp)
57
58                 # Initialize widgets
59                 self["key_green"] = StaticText(_("OK"))
60                 self["key_red"] = StaticText(_("Cancel"))
61                 self["key_yellow"] = StaticText("")
62                 self["key_blue"] = StaticText("")
63                 self["help"] = StaticText()
64
65                 # Define Actions
66                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
67                         {
68                                 "cancel": self.keyCancel,
69                                 "save": self.keySave,
70                         }
71                 )
72
73                 # Trigger change
74                 self.changed()
75
76                 self.onLayoutFinish.append(self.setCustomTitle)
77
78         def setCustomTitle(self):
79                 self.setTitle(_("eCasa Setup"))
80
81         def updateHelp(self):
82                 cur = self["config"].getCurrent()
83                 if cur:
84                         self["help"].text = cur[2]
85
86         def changed(self):
87                 for x in self.onChangedEntry:
88                         x()
89
90         def getCurrentEntry(self):
91                 return self["config"].getCurrent()[0]
92
93         def getCurrentValue(self):
94                 return str(self["config"].getCurrent()[1].getText())
95
96         def createSummary(self):
97                 return SetupSummary