ecasa: various enhancements/fixes
[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(_("Albums of"), config.plugins.ecasa.user, _("Show albums for this user by default. Use \"default\" for currently logged in user.")),
43                                 getConfigListEntry(_("Search results"), config.plugins.ecasa.searchlimit, _("Number of search results to display at most.")),
44                                 #getConfigListEntry(_("Cache directory"), config.plugins.ecasa.cache, _("Directory used to store cached images.")),
45                         ],
46                         session = session,
47                         on_change = self.changed
48                 )
49                 def selectionChanged():
50                         if self["config"].current:
51                                 self["config"].current[1].onDeselect(self.session)
52                         self["config"].current = self["config"].getCurrent()
53                         if self["config"].current:
54                                 self["config"].current[1].onSelect(self.session)
55                         for x in self["config"].onSelectionChanged:
56                                 x()
57                 self["config"].selectionChanged = selectionChanged
58                 self["config"].onSelectionChanged.append(self.updateHelp)
59
60                 # Initialize widgets
61                 self["key_green"] = StaticText(_("OK"))
62                 self["key_red"] = StaticText(_("Cancel"))
63                 self["key_yellow"] = StaticText("")
64                 self["key_blue"] = StaticText("")
65                 self["help"] = StaticText()
66
67                 # Define Actions
68                 self["actions"] = ActionMap(["SetupActions", "ColorActions"],
69                         {
70                                 "cancel": self.keyCancel,
71                                 "save": self.keySave,
72                         }
73                 )
74
75                 # Trigger change
76                 self.changed()
77
78                 self.onLayoutFinish.append(self.setCustomTitle)
79
80         def setCustomTitle(self):
81                 self.setTitle(_("eCasa Setup"))
82
83         def updateHelp(self):
84                 cur = self["config"].getCurrent()
85                 if cur:
86                         self["help"].text = cur[2]
87
88         def changed(self):
89                 for x in self.onChangedEntry:
90                         x()
91
92         def getCurrentEntry(self):
93                 return self["config"].getCurrent()[0]
94
95         def getCurrentValue(self):
96                 return str(self["config"].getCurrent()[1].getText())
97
98         def createSummary(self):
99                 return SetupSummary