VlibrasUpdateInstall.py
6.78 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# -*- coding: utf-8 -*-
import wx
import subprocess
import time
from wx.lib.pubsub import pub
from DownloadFile import *
from VlibrasCheckVersion import *
import zipfile
PATH_RESOURCE = 'C:/vlibras-libs/update/'
DICTIONARY_NAME = 'download/vlibras_dicionario.zip'
INSTALL_PLAYER_NAME = 'download/Vlibras_Up.exe'
DICTIONARY_EXTRACT_PATH = 'C:/vlibras-libs/Player/VLibrasPlayer_Data/Bundles'
class UpdateView(wx.Frame):
def __init__(self,_downloadFile,_serv_type):
self.serv_type = _serv_type
self.downloadFile = _downloadFile
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')
## btnOk = wx.Button(self.myPanel, label="OK",pos=(365, 180), size=(80, 25))
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.SetBackgroundColour('#123456')
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.onBtnOkClick, btnOk)
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
if(self.serv_type != ''):
self.downloadFile.start()
def erroDeConexao(self, msg):
wx.MessageBox('Ocorreu um erro ao tentar fazer atualização. \n Por favor tente mais tarde.', '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);
## event.Skip()
## def onBtnOkClick(self, event):
## self.downloadFile.start()
def onBtnCancelClick(self, event):
self.OnCloseFrame(event);
def downloadSucess(self, msg):
self.percentDownload = 100.0
time.sleep( 2 )
if (self.serv_type == 'dict'):
with zipfile.ZipFile(PATH_RESOURCE+DICTIONARY_NAME, "r") as z:
z.extractall(DICTIONARY_EXTRACT_PATH)
self.update_json_file()
self.ShowMessage('Vlibras Atualizado com sucesso!')
else:
self.Hide()
process = subprocess.call(PATH_RESOURCE+INSTALL_PLAYER_NAME+' /SILENT /SUPPRESSMSGBOXES /NORESTART')
self.update_json_file()
self.ShowMessage('Vlibras Atualizado com sucesso!')
self.downloadFile.stop()
self.Destroy()
def updateProgress(self, msg):
value = msg
val = 'Baixando'
self.percentDownload = value
self.myText.SetLabel(val)
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_QUESTION)
response = dialog.ShowModal()
if (response == wx.ID_YES):
self.downloadFile.stop()
self.Destroy()
else:
event.StopPropagation()
# atualiza o json local com as informações da api
def update_json_file(self):
with open(PATH_RESOURCE+JSON_API_NAME) as data:
json_data = json.load(data)
jsonFile = open(PATH_RESOURCE+JSON_LOCAL_NAME, "w+")
jsonFile.write(json.dumps(json_data))
jsonFile.close()
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)
def installDictionary(_url):
app = wx.App(False)
downloadFile2 = DownloadFile2(_url, PATH_RESOURCE+DICTIONARY_NAME)
frame = UpdateView(downloadFile2,'dict')
frame.register_close_callback(lambda: True)
frame.Show()
app.MainLoop()
print _url
return 'OK'
def installPlayer(_url):
app = wx.App(False)
downloadFile2 = DownloadFile2(_url, PATH_RESOURCE+INSTALL_PLAYER_NAME)
frame = UpdateView(downloadFile2,'player')
frame.register_close_callback(lambda: True)
frame.Show()
app.MainLoop()
print _url
return 'OK'
if __name__ == '__main__':
app = wx.App(False)
result = check()
if result.endswith('.zip'):
installDictionary(result)
elif result.endswith('.exe'):
installPlayer(result)
elif (result == 'atualizado'):
## up.Show()
ShowInfo('O VLibras já está atualizado!').ShowMessage()
else:
## up.Show()
ShowInfo('Ocorreu um erro ao tentar atualizar o VLibras!').ShowMessageError()
## app.MainLoop()
def initInstall():
app = wx.App(False)
result = check()
if result.endswith('.zip'):
installDictionary(result)
elif result.endswith('.exe'):
installPlayer(result)
elif (result == 'atualizado'):
## up.Show()
ShowInfo('O VLibras já está atualizado!').ShowMessage()
else:
## up.Show()
ShowInfo('Ocorreu um erro ao tentar atualizar o VLibras!').ShowMessageError()
## app.MainLoop()