show progress and current time in servicelist event information instead of
[enigma2.git] / lib / python / Screens / Ipkg.py
1 from Components.ActionMap import ActionMap
2 from Components.Ipkg import IpkgComponent
3 from Components.Label import Label
4 from Components.Slider import Slider
5 from Screens.Screen import Screen
6 from enigma import eTimer
7
8 class Ipkg(Screen):
9         def __init__(self, session, cmdList = []):
10                 Screen.__init__(self, session)
11                 
12                 self.cmdList = cmdList
13
14                 self.sliderPackages = {}
15                 
16                 self.slider = Slider(0, len(cmdList))
17                 self["slider"] = self.slider
18                 self.activityslider = Slider(0, 100)
19                 self["activityslider"] = self.activityslider
20                 self.status = Label(_("Preparing... Please wait"))
21                 self["status"] = self.status
22                 self.package = Label()
23                 self["package"] = self.package
24                 
25                 self.packages = 0
26                 self.error = 0
27                 
28                 self.activity = 0
29                 self.activityTimer = eTimer()
30                 self.activityTimer.timeout.get().append(self.doActivityTimer)
31                 #self.activityTimer.start(100, False)
32                                 
33                 self.ipkg = IpkgComponent()
34                 self.ipkg.addCallback(self.ipkgCallback)
35                 
36                 self.runningCmd = None
37                 self.runNextCmd()
38                 
39                 self["actions"] = ActionMap(["WizardActions"], 
40                 {
41                         "ok": self.exit, 
42                         "back": self.exit
43                 }, -1)
44                 
45         def runNextCmd(self):
46                 if self.runningCmd is None:
47                         self.runningCmd = 0
48                 else:
49                         self.runningCmd += 1
50                 print len(self.cmdList), self.runningCmd
51                 if len(self.cmdList) - 1 < self.runningCmd:
52                         self.activityslider.setValue(0)
53                         self.slider.setValue(len(self.cmdList))
54                                 
55                         self.package.setText("")
56                         self.status.setText(_("Done - Installed or upgraded %d packages with %d errors") % (self.packages, self.error))
57                         return False
58                 else:
59                         cmd = self.cmdList[self.runningCmd]
60                         self.slider.setValue(self.runningCmd)
61                         self.ipkg.startCmd(cmd[0], args = cmd[1])
62                         self.startActivityTimer()
63                         
64         def doActivityTimer(self):
65                 if not self.ipkg.isRunning():
66                         self.stopActivityTimer()
67                 else:
68                         self.activity += 1
69                         if self.activity == 100:
70                                 self.activity = 0
71                         self.activityslider.setValue(self.activity)
72                 
73         def startActivityTimer(self):
74                 self.activityTimer.start(100, False)
75                 
76         def stopActivityTimer(self):
77                 self.activityTimer.stop()
78                 
79         def ipkgCallback(self, event, param):
80                 if event == IpkgComponent.EVENT_DOWNLOAD:
81                         self.status.setText(_("Downloading"))
82                 elif event == IpkgComponent.EVENT_UPGRADE:
83                         if self.sliderPackages.has_key(param):
84                                 self.slider.setValue(self.sliderPackages[param])
85                         self.package.setText(param)
86                         self.status.setText(_("Upgrading"))
87                         self.packages += 1
88                 elif event == IpkgComponent.EVENT_INSTALL:
89                         self.package.setText(param)
90                         self.status.setText(_("Installing"))
91                         self.packages += 1
92                 elif event == IpkgComponent.EVENT_CONFIGURING:
93                         self.package.setText(param)
94                         self.status.setText(_("Configuring"))
95                 elif event == IpkgComponent.EVENT_ERROR:
96                         self.error += 1
97                 elif event == IpkgComponent.EVENT_DONE:
98                         self.runNextCmd()
99         
100         def exit(self):
101                 if not self.ipkg.isRunning():
102                         self.close()