VlibrasUpdateInstallDict.py
4.65 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
# -*- coding: utf-8 -*-
import wx
import subprocess
import time
import os.path
from wx.lib.pubsub import pub
from DownloadFile import *
from VlibrasCheckVersion import *
import zipfile
import Util
##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'
##JSON_LOCAL_NAME = PATH_RESOURCE+'version/version.json'
##JSON_API_NAME = PATH_RESOURCE+'download/versionApi.json'
class UpdateView(wx.Frame):
def __init__(self,_listUrlDictVersionFull):
self.length_dict = 0;
self.listDictVersionDictLength = Util.checkDictVersion()
if self.listDictVersionDictLength == 2:
self.length_dict =listDictVersionDictLength[1]
self.listUrlDictVersionFull = _listUrlDictVersionFull
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))
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(listUrlDictVersionFull[0], Util.DICTIONARY_ZIP_PATH)
self.downloadFile.start()
self.myText.SetLabel('Baixando dicionário')
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);
def onBtnCancelClick(self, event):
self.OnCloseFrame(event);
def downloadSucess(self, msg):
self.percentDownload = 100.0
time.sleep( 2 )
with zipfile.ZipFile(Util.DICTIONARY_ZIP_PATH, "r") as z:
z.extractall(Util.DICTIONARY_EXTRACT_PATH)
if Util.checkDictSucess(self.lenght_dict):
self.ShowMessage('Vlibras Atualizado com sucesso!')
Util.updateFileDictVersion(listUrlDictVersionFull[1])
else:
self.ShowMessageError('Houve um erro ao atualizar dicionário!')
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_QUESTION)
response = dialog.ShowModal()
if (response == wx.ID_YES):
self.downloadFile.stop()
self.Destroy()
else:
event.StopPropagation()
if __name__ == '__main__':
listUrlDictVersionFull = Util.getUrlDict()
if len(listUrlDictVersionFull)== 2:
app = wx.App(False)
frame = UpdateView(listUrlDictVersionFull)
frame.register_close_callback(lambda: True)
frame.Show()
app.MainLoop()