4.5.0r6
[enigma2.git] / usr / lib / enigma2 / python / Plugins / SystemPlugins / NetworkManager / MultiInputBox.py
1 from Components.config import ConfigText, ConfigPassword, ConfigInteger, getConfigListEntry
2 from Components.ActionMap import ActionMap
3 from Components.ConfigList import ConfigListScreen
4 from Components.Sources.StaticText import StaticText
5 from Screens.Screen import Screen
6 from Tools.BoundFunction import boundFunction
7 from Tools.Log import Log
8
9
10 class MultiInputBox(Screen, ConfigListScreen):
11         TYPE_TEXT = 0
12         TYPE_PASSWORD = 1
13         TYPE_PIN = 2
14
15         skin = """
16                 <screen position="center,center" size="720,120"  title="Input">
17                         <widget source="title" render="Label" position="5,5" size="690,30" font="Regular;22" halign="left" valign="bottom" />
18                         <widget name="config" position="10,40" size="700,600" scrollbarMode="showOnDemand"/>
19                 </screen>"""
20
21         default_config = [
22                 {
23                         "key" : "User",
24                         "value" : "",
25                         "title" : _("User"),
26                         "required" : True,
27                         "type" : TYPE_TEXT,
28                         "alternative" : None
29                 },
30                 {
31                         "key" : "Password",
32                         "value" : "",
33                         "title" : _("Password"),
34                         "required" : True,
35                         "type" : TYPE_PASSWORD,
36                         "alternatives" : None
37                 },
38         ]
39
40         def __init__(self, session, title="", windowTitle=_("Input"), config=default_config):
41                 Screen.__init__(self, session)
42                 ConfigListScreen.__init__(self, [], session)
43
44                 self._config = config
45                 self._title = title
46
47                 self["title"] = StaticText(self._title)
48                 self["setupActions"] = ActionMap(["SetupActions"],
49                 {
50                         "save": self._ok,
51                         "cancel": self._cancel,
52                         "ok" : self._ok,
53                 }, -2)
54
55                 self._configElements = []
56                 self._createConfigElements()
57
58                 self.onExecBegin.append(self.__onExcecBegin)
59                 self.onShow.append(self._createSetup)
60                 self.onShown.append(boundFunction(self.setTitle, windowTitle))
61                 self.onClose.append(self.__onClose)
62
63         def __onExcecBegin(self):
64                 self.saveKeyboardMode()
65                 self.setKeyboardModeAscii()
66
67         def __onClose(self):
68                 self.restoreKeyboardMode()
69
70         def _createConfigElements(self):
71                 append = self._configElements.append
72                 for item in self._config:
73                         Log.i(item)
74                         if item["type"] == self.TYPE_TEXT:
75                                 append((ConfigText(default=item["value"], fixed_size=False), item))
76                         elif item["type"] == self.TYPE_PASSWORD:
77                                 append((ConfigPassword(default=item["value"], fixed_size=False), item))
78                         elif item["type"] == self.TYPE_PIN:
79                                 val = item["value"] or 0
80                                 append((ConfigInteger(default=int(val)), item))
81
82         def _createSetup(self):
83                 lst = []
84                 for config, item in self._configElements:
85                         lst.append(getConfigListEntry(item["title"], config))
86                 self["config"].setList(lst)
87
88         def _ok(self):
89                 if self._checkInput():
90                         ret = {}
91                         for config, item in self._configElements:
92                                 ret[item["key"]] = str(config.value)
93                         self.close(ret)
94                 else:
95                         self.close(None)
96
97         def _checkInput(self):
98                 return True
99
100         def _checkSingleInput(self, value, config):
101                 return value != None and value != ""
102
103         def _cancel(self):
104                 self.close(None)
105