improve queue manager a little
[enigma2-plugins.git] / ftpbrowser / src / FTPQueueManager.py
1 # for localized messages
2 from . import _
3
4 # GUI (Screens)
5 from Screens.Screen import Screen
6
7 # GUI (Components)
8 from Components.ActionMap import ActionMap
9 from Components.Sources.List import List
10 from Components.Sources.StaticText import StaticText
11
12 # Tools
13 from Tools.LoadPixmap import LoadPixmap
14 from Tools.Directories import resolveFilename, SCOPE_PLUGINS
15
16 class FTPQueueManager(Screen):
17         skin = """
18                 <screen position="center,center" size="560,420" title="FTP Queue Manager" >
19                         <ePixmap pixmap="skin_default/buttons/red.png" position="0,0" size="140,40" transparent="1" alphatest="on" />
20                         <ePixmap pixmap="skin_default/buttons/green.png" position="140,0" size="140,40" transparent="1" alphatest="on" />
21                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="280,0" size="140,40" transparent="1" alphatest="on" />
22                         <ePixmap pixmap="skin_default/buttons/blue.png" position="420,0" size="140,40" transparent="1" alphatest="on" />
23                         <widget source="key_red" render="Label" position="0,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1" />
24                         <widget source="key_green" render="Label" position="140,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1" />
25                         <widget source="key_yellow" render="Label" position="280,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1" />
26                         <widget source="key_blue" render="Label"  position="420,0" zPosition="1" size="140,40" font="Regular;20" valign="center" halign="center" backgroundColor="#1f771f" transparent="1" />
27                         <widget source="list" render="Listbox" position="0,50" size="560,360" scrollbarMode="showAlways">
28                                 <convert type="TemplatedMultiContent">
29                                         {"template": [
30                                                         MultiContentEntryText(pos=(35,1), size=(510,19), text = 1, font = 0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
31                                                         MultiContentEntryText(pos=(35,20), size=(510,18), text = 2, font = 0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
32                                                         <!--MultiContentEntryPixmapAlphaTest(pos=(2,2), size=(32,32), png = 0),-->
33                                                 ],
34                                           "fonts": [gFont("Regular", 18)],
35                                           "itemHeight": 37
36                                          }
37                                 </convert>
38                         </widget>
39                 </screen>"""
40
41         def __init__(self, session, queue):
42                 Screen.__init__(self, session)
43                 self.queue = queue or []
44                 
45                 self["key_red"] = StaticText("")
46                 self["key_green"] = StaticText("")
47                 self["key_yellow"] = StaticText("")
48                 self["key_blue"] = StaticText("")
49                 self['list'] = List([])
50
51                 self.pixmaps = (
52                         0, #LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/FTPBrowser/images/up.png")),
53                         0 #LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/FTPBrowser/images/down.png"))
54                 )
55
56                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
57                         {
58                                 "cancel": self.exit,
59                                 "ok": self.ok,
60                         }, -1)
61                 
62                 self.onLayoutFinish.extend((
63                         self.layoutFinished,
64                         self.updateList,
65                 ))
66
67         def updateList(self, queue = None):
68                 if not queue:
69                         queue = self.queue
70
71                 pixmaps = self.pixmaps
72
73                 list = [(pixmaps[item[0]], item[1], "-> " + item[2]) for item in queue]
74
75                 # XXX: this is a little ugly but this way we have the least
76                 # visible distortion :-)
77                 index = min(self['list'].index, len(list)-1)
78                 self['list'].setList(list)
79                 self['list'].index = index
80
81         def layoutFinished(self):
82                 self.setTitle(_("FTP Queue Manager"))
83
84         def exit(self):
85                 self.close()
86
87         def ok(self):
88                 pass
89