from Screens.Screen import Screen from Components.Label import Label from Components.ProgressBar import ProgressBar from Components.ActionMap import ActionMap from Tools.Downloader import downloadWithProgress class MyMetrixUpdater(Screen): skin = """ <screen position="center,center" size="840,160" flags="wfNoBorder" backgroundColor="background"> <widget name="status" position="20,10" size="800,70" transparent="1" font="RegularLight;46" foregroundColor="foreground" backgroundColor="background" valign="center" halign="left" noWrap="1" /> <widget name="progress" position="0,88" size="840,6" transparent="1" borderWidth="0" /> <widget name="key_red" position="20,100" size="10,60" backgroundColor="red" /> <widget name="key_green" position="20,100" size="10,60" backgroundColor="green" /> </screen> """ def __init__(self, session): Screen.__init__(self, session) self["key_red"] = Label() self["key_red"].hide() self["key_green"] = Label() self["actions"] = ActionMap(["OkCancelActions","ColorActions"], { "ok": self.ok, "cancel": self.exit, "green": self.startUpdate, "red": self.stopUpdate }, -1) self["key"] = Label(_("Start update")) self["status"] = Label(_("Press green to start update!")) self["progress"] = ProgressBar() self["progress"].hide() def ok(self): self.close() def exit(self): self.close() def startUpdate(self): self["key"].setText(_("Abort")) self["key_red"].show() self["key_green"].hide() self["status"].setText(_("Download files...")) localurl = '/tmp/enigma2-plugin-skins-pvmc-skin_1.0_all.ipk' sourceurl = 'http://metrixfullhd.w1.ms5.eu/dl-counter/download/enigma2-plugin-skins-pvmc-skin_1.0_all.ipk' self.download = downloadWithProgress(sourceurl,localurl) self.download.addProgress(self.downloadProgress) self.download.start().addCallback(self.downloadFinished).addErrback(self.downloadFailed) def stopUpdate(self): self["status"].setText(_("Update is aborting...")) def downloadFinished(self, string=""): self["status"].setText(_("Download successfully!")) def downloadFailed(self, failure_instance=None, error_message=""): text = _("Error downloading files!") if error_message == "" and failure_instance is not None: error_message = failure_instance.getErrorMessage() text += ": " + error_message self["status"].setText(text) def downloadProgress(self, recvbytes, totalbytes): progress = int(100 * recvbytes / float(totalbytes)) self["progress"].setValue(int(progress)) self["progress"].show()