frameUpdate.py
3.31 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
# -*- 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 Util
from threading import Thread
class UpdateView(wx.Frame,Thread):
def __init__(self):
Thread.__init__(self)
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=(380,150))
self.SetIcon(wx.Icon(Util.ICON, wx.BITMAP_TYPE_ICO))
self.myPanel = wx.Panel(self, -1)
self.myPanel.SetBackgroundColour('#F5F5F5')
btnCancel = wx.Button(self.myPanel, label="Cancelar",pos=(270, 85), size=(80, 25))
self.txtInfo = wx.StaticText(self.myPanel, -1, pos=(5,105))
self.txtInfo.SetForegroundColour('#000000')
self.progress = wx.Gauge(self.myPanel, range=100,pos=(5,40),size=(365,23))
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)
pub.subscribe(self.erroDeConexao, "erroDeConexao")
pub.subscribe(self.updateProgress, "updateProgress")
self.percentDownload = 0;
self.register_close_callback(lambda: True)
self.dlg = wx.ProgressDialog("Atualização", "Verificando Atualização...", style = wx.PD_CAN_ABORT | wx.PD_APP_MODAL)
self.pulse = True
def run(self):
pulse =True
while self.pulse and pulse:
if(not pulse):
self.dlg.Destroy()
break
(pulse, skip) = self.dlg.Pulse()
self.dlg.Destroy()
""" chamado quando termina de verificacao de atualização """
def closePulseDialog(self):
self.pulse = False
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):
wx.CallAfter(pub.sendMessage, "cancelDownload",event = event)
# self.OnCloseFrame(event);
def onBtnCancelClick(self, event):
print 'cancel'
wx.CallAfter(pub.sendMessage, "cancelDownload",event = event)
def updateProgress(self, msg):
value = msg
self.percentDownload = value
self.progress.SetValue(value)
def ShowMessage(self, mesagem):
dialog = wx.MessageDialog(self, message = mesagem, caption = "Atualização",
style = wx.OK | wx.ICON_INFORMATION)
dialog.ShowModal()
def ShowMessageError(self, mesagem):
wx.MessageBox(mesagem, 'Informação',
wx.OK | wx.ICON_ERROR)
# self.downloadFile.stop()
self.Destroy()
def showMessageDialog(self):
dialog = wx.MessageDialog(self, message = "Tem certeza que deseja cancelar a atualização?", caption = "Cancelar Atualização",
style = wx.YES_NO | wx.ICON_QUESTION)
return dialog.ShowModal()