# -*- coding: utf-8 -*- from version import TVersion from frameUpdate import UpdateView import wx from DownloadFile import * import Util from wx.lib.pubsub import pub import subprocess import time import os class Update(object): """docstring for Update""" def __init__(self, version,frame): super(Update, self).__init__() self.version = version self.frame = frame self.downloadFile = None pub.subscribe(self.downloadSucess, "downloadSucess") pub.subscribe(self.cancelDownload, "cancelDownload") def cancelDownload(self,event): if(self.frame.percentDownload>= 100): if not (self.downloadFile == None): self.downloadFile.stop() self.frame.Destroy() response = self.frame.showMessageDialog() if (response == wx.ID_YES): if not (self.downloadFile == None): self.downloadFile.stop() self.frame.Destroy() self.frame.ShowMessage('Atualização Cancelada!') else: event.StopPropagation() def stopDownload(self): if not (self.downloadFile == None): self.downloadFile.stop() def startDownloadPlayer(self): # #inicia o download do arquivo self.downloadFile = DownloadFile2(version.url_download_player, Util.INSTALL_PLAYER_PATH) self.downloadFile.start() self.frame.txtInfo.SetLabel('Baixando a atualização...') def startDownloadDict(self): # #inicia o download do arquivo self.downloadFile = DownloadFile2(version.url_download_dict, Util.DICTIONARY_ZIP_PATH) self.downloadFile.start() self.frame.txtInfo.SetLabel('Baixando a atualização...') """funcao chamada pelo DownloadFile quando terminado o download tanto do dicionario quanto do player""" def downloadSucess(self, msg): self.frame.Hide() self.frame.txtInfo.SetLabel('Instalando Atualização...') if(self.version.isUpdateDict()): try: Util.extractDictZip() self.frame.ShowMessage('O Dicionário VLibras foi atualizado com sucesso!') Util.updateFileDictVersion(self.version.api_dict_version_full) except: self.frame.ShowMessageError('Houve um erro ao atualizar o VLibras!') elif (self.version.isUpdatePlayer()): process = subprocess.call(Util.INSTALL_PLAYER_PATH) time.sleep( 3 ) if os.path.isfile(Util.TEXT_CHECK_INSTALL): self.frame.ShowMessage('O VLibras foi atualizado com sucesso!') Util.updateFilePlayerVersion(self.version.api_player_version_full) else: self.frame.ShowMessageError('O VLibras não foi atualizado!') subprocess.Popen(Util.PATH_PLAYER) self.frame.Destroy() if __name__ == '__main__': app = wx.App(False) frame = UpdateView() version = TVersion() #version.start() frame.start() update = Update(version,frame) print version.checkVersion(); frame.closePulseDialog() if(version.isUpdatePlayer()): frame.Show() update.startDownloadPlayer() app.MainLoop() elif(version.isUpdateDict()): frame.Show() update.startDownloadDict() app.MainLoop() else: frame.ShowMessage('O VLibras está atualizado!')