VlibrasUpdateInstallPlayer.py
5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# -*- coding: utf-8 -*-
import wx
import subprocess
import time
import os
from wx.lib.pubsub import pub
from DownloadFile import *
from VlibrasCheckVersion import *
import zipfile
import Util
class UpdateView(wx.Frame):
def __init__(self,_listPlayerVersion):
self.listPlayerVersion = _listPlayerVersion
style = wx.SYSTEM_MENU | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX
wx.Frame.__init__(self, None, title='Atualização do VLibras', style=style,size=(480,250))
# Define o ícone para a janela
self.SetIcon(wx.Icon("c:/vlibras-libs/icons/icon_vlibras.ico", wx.BITMAP_TYPE_ICO))
self.myPanel = wx.Panel(self, -1)
self.myPanel.SetBackgroundColour('#F5F5F5')
btnCancel = wx.Button(self.myPanel, label="Cancelar",pos=(365, 180), size=(80, 25))
self.myText = wx.StaticText(self.myPanel, -1, pos=(5,105))
self.myText.SetForegroundColour('#000000')
self.progress = wx.Gauge(self.myPanel, range=100,pos=(5,80),size=(463,25))
self.Center()
# Anexa um evento ao botão
self.Bind(wx.EVT_BUTTON, self.onBtnCancelClick, btnCancel)
self.__close_callback = None
self.Bind(wx.EVT_CLOSE, self._when_closed)
#registra listeners na classe DownloadFile
pub.subscribe(self.downloadSucess, "downloadSucess")
pub.subscribe(self.erroDeConexao, "erroDeConexao")
pub.subscribe(self.updateProgress, "updateProgress")
self.percentDownload = 0;
#inicia o download do arquivo
self.downloadFile = DownloadFile2(self.listPlayerVersion[0], Util.INSTALL_PLAYER_PATH)
self.downloadFile.start()
self.myText.SetLabel('Baixando atualização do VLibras. Aguarde... ')
def erroDeConexao(self, msg):
wx.MessageBox('Ocorreu um erro ao tentar baixar atualização. \n Por favor verifique sua conexão e tente novamente.', 'Informação',wx.OK | wx.ICON_INFORMATION)
self.Destroy()
def register_close_callback(self, callback):
self.__close_callback = callback
def _when_closed(self, event):
self.OnCloseFrame(event);
def onBtnCancelClick(self, event):
self.OnCloseFrame(event);
def downloadSucess(self, msg):
self.percentDownload = 100.0
time.sleep( 5 )
self.Hide()
process = subprocess.call(Util.INSTALL_PLAYER_PATH)
time.sleep( 3 )
if os.path.isfile(Util.TEXT_CHECK_INSTALL):
self.ShowMessage('Vlibras Atualizado com sucesso!')
Util.updateFilePlayerVersion(self.listPlayerVersion[1])
subprocess.Popen(Util.PATH_PLAYER)
else:
self.ShowMessageError('O Vlibras não foi atualizado!')
Util.updateFilePlayerVersion(self.listPlayerVersion[2])
subprocess.Popen(Util.PATH_PLAYER)
self.downloadFile.stop()
self.Destroy()
def updateProgress(self, msg):
value = msg
self.percentDownload = value
self.progress.SetValue(value)
def ShowMessage(self, mesagem):
wx.MessageBox(mesagem, 'Informação',
wx.OK | wx.ICON_INFORMATION)
def ShowMessageError(self, mesagem):
wx.MessageBox(mesagem, 'Informação',
wx.OK | wx.ICON_ERROR)
self.downloadFile.stop()
self.Destroy()
# monitora a interação do usuário no botão de fechar
def OnCloseFrame(self, event):
if(self.percentDownload>= 100):
self.downloadFile.stop()
self.Destroy()
dialog = wx.MessageDialog(self, message = "Tem certeza que deseja cancelar a atualização?", caption = "Cancelar Atualização",
style = wx.YES_NO | wx.ICON_INFORMATION)
response = dialog.ShowModal()
if (response == wx.ID_YES):
self.downloadFile.stop()
time.sleep( 0.5 )
os.remove(Util.INSTALL_PLAYER_PATH)
Util.updateFilePlayerVersion(self.listPlayerVersion[2])
self.Destroy()
else:
event.StopPropagation()
class ShowInfo(wx.Frame):
def __init__(self,_mesagem):
self.mesagem = _mesagem
style = wx.SYSTEM_MENU | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX
wx.Frame.__init__(self, None, title='Atualização do VLibras', style=style,size=(480,250))
def ShowMessage(self):
wx.MessageBox(self.mesagem, 'Informação',
wx.OK | wx.ICON_INFORMATION)
def ShowMessageError(self):
wx.MessageBox(self.mesagem, 'Informação',
wx.OK | wx.ICON_ERROR)
if __name__ == '__main__':
app = wx.App(False)
listPlayerVersion = Util.getUrlDictPlayer()
if os.path.isfile(Util.TEXT_CHECK_INSTALL):
os.remove(Util.TEXT_CHECK_INSTALL)
if len(listPlayerVersion) > 2:
if(listPlayerVersion[0].endswith('.exe')):
frame = UpdateView(listPlayerVersion)
frame.register_close_callback(lambda: True)
frame.Show()
app.MainLoop()
else:
ShowInfo('Ocorreu um erro ao tentar atualizar o VLibras!').ShowMessageError()
else:
ShowInfo('Atualização não disponível!').ShowMessageError()