update plugin icons (and some minor cleanups)
[enigma2-plugins.git] / ftpbrowser / src / FTPQueueManager.py
1 # GUI (Screens)
2 from Screens.Screen import Screen
3
4 # GUI (Components)
5 from Components.ActionMap import ActionMap
6 from Components.Sources.List import List
7 from Components.Sources.StaticText import StaticText
8
9 # Tools
10 from Tools.LoadPixmap import LoadPixmap
11 from Tools.Directories import resolveFilename, SCOPE_PLUGINS
12
13 class FTPQueueManagerSummary(Screen):
14         skin = (
15         """<screen id="1" position="0,0" size="132,64">
16                 <widget source="parent.Title" render="Label" position="6,4" size="120,21" font="Regular;18" />
17                 <widget source="parent.list" render="Label" position="6,25" size="120,21" font="Regular;16">
18                         <convert type="StringListSelection" />
19                 </widget>
20                 <widget source="global.CurrentTime" render="Label" position="56,46" size="82,18" font="Regular;16" >
21                         <convert type="ClockToText">WithSeconds</convert>
22                 </widget>
23         </screen>""",
24         """<screen id="3" position="0,0" size="400,240">
25                 <ePixmap position="0,0" size="400,240" pixmap="skin_default/display_bg.png" zPosition="-1"/>
26                 <widget font="Display;40" position="10,5" render="Label" size="380,42" source="parent.Title" transparent="1"/>
27                 <widget font="Display;60" halign="center" position="10,50" render="Label" size="380,120" source="parent.list" valign="center" transparent="1">
28                         <convert type="StringListSelection" />
29                 </widget>
30                 <widget source="global.CurrentTime" halign="right" render="Label" position="90,180" size="300,50" font="Regular;50" transparent="1">
31                         <convert type="ClockToText">WithSeconds</convert>
32                 </widget>
33         </screen>""")
34
35 class FTPQueueManager(Screen):
36         skin = """
37                 <screen position="center,120" size="820,520" title="FTP Queue Manager" >
38                         <ePixmap pixmap="skin_default/buttons/red.png" position="10,5" size="200,40" />
39                         <ePixmap pixmap="skin_default/buttons/green.png" position="210,5" size="200,40" />
40                         <ePixmap pixmap="skin_default/buttons/yellow.png" position="410,5" size="200,40" />
41                         <ePixmap pixmap="skin_default/buttons/blue.png" position="610,5" size="200,40" />
42                         <widget source="key_red" render="Label" position="10,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#9f1313" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" />
43                         <widget source="key_green" render="Label" position="210,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#1f771f" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" />
44                         <widget source="key_yellow" render="Label" position="410,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#a08500" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" />
45                         <widget source="key_blue" render="Label" position="610,5" size="200,40" zPosition="1" font="Regular;20" halign="center" valign="center" backgroundColor="#18188b" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-2,-2" />
46                         <eLabel position="10,50" size="800,1" backgroundColor="grey" />
47                         <widget source="list" render="Listbox" position="10,60" size="800,450" enableWrapAround="1" scrollbarMode="showOnDemand">
48                                 <convert type="TemplatedMultiContent">
49                                         {"template": [
50                                                         MultiContentEntryText(pos=(55,2), size=(740,24), text = 0, font = 0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
51                                                         MultiContentEntryText(pos=(55,26), size=(740,24), text = 1, font = 0, flags = RT_HALIGN_LEFT|RT_VALIGN_CENTER),
52                                                         MultiContentEntryPixmapAlphaTest(pos=(5,5), size=(40,40), png = 2),
53                                                 ],
54                                           "fonts": [gFont("Regular", 18)],
55                                           "itemHeight": 50
56                                          }
57                                 </convert>
58                         </widget>
59                 </screen>"""
60
61         def __init__(self, session, queue):
62                 Screen.__init__(self, session)
63                 self.queue = queue or []
64                 
65                 self["key_red"] = StaticText("")
66                 self["key_green"] = StaticText("")
67                 self["key_yellow"] = StaticText("")
68                 self["key_blue"] = StaticText("")
69                 self['list'] = List([])
70
71                 self.pixmaps = (
72                         LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/FTPBrowser/images/up.svg")),
73                         LoadPixmap(resolveFilename(SCOPE_PLUGINS, "Extensions/FTPBrowser/images/down.svg"))
74                 )
75
76                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
77                         {
78                                 "cancel": self.exit,
79                                 "ok": self.ok,
80                         }, -1)
81                 
82                 self.onLayoutFinish.extend((
83                         self.layoutFinished,
84                         self.updateList,
85                 ))
86
87         def createSummary(self):
88                 return FTPQueueManagerSummary
89
90         def updateList(self, queue = None):
91                 if not queue:
92                         queue = self.queue
93
94                 pixmaps = self.pixmaps
95
96                 list = [(item[1], "-> " + item[2], pixmaps[item[0]]) for item in queue]
97
98                 # XXX: this is a little ugly but this way we have the least
99                 # visible distortion :-)
100                 index = min(self['list'].index, len(list)-1)
101                 self['list'].setList(list)
102                 self['list'].index = index
103
104         def layoutFinished(self):
105                 self.setTitle(_("FTP Queue Manager"))
106
107         def exit(self):
108                 self.close()
109
110         def ok(self):
111                 pass