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
| class mainFrame(wx.Frame):
def __init__(self, parent, id, title, param):
#initialisation de la frame#
self.tc = wx.TextCtrl(panel, -1, "/")
#[...]#
#Partie texte
self.Gt = wx.StaticText(panel, -1, 'Wait To Go')
#[...]#
#Partie Gauge
self.gauge = wx.Gauge(panel, -1, 100, size=(250, 25))
#[...]#
#Les Events des bouton selection et start
panel.Bind(wx.EVT_BUTTON, self.OnSelectFile, id=4)
panel.Bind(wx.EVT_BUTTON, self.OnStart, id=1)
#[...]#
def OnSelectFile(self, event): # wxGlade: MyFrame1.<event_handler>
wildcard = "All files (*.*)|*.*|" \
"Fichiers textes (*.txt)|*.txt"
dialog = wx.FileDialog(None, "Choose a file", os.getcwd(),
"", wildcard, wx.OPEN)
if dialog.ShowModal() == wx.ID_OK:
self.tc.SetValue(dialog.GetPath())
event.Skip()
def OnStart(self, event):
self.gauge.SetValue(1)
t = CryptAndUpload(args=(self.tc.GetValue(), self),kwargs={'option':True})
t.start()
time.sleep(0.1)
self.Gt.SetLabel("Upload en cours...")
self.gauge.SetValue(10)
def OnExit(self, event):
self.Close()
class CryptAndUpload(threading.Thread):
def __init__(self, args=None, kwargs=None):
threading.Thread.__init__(self)
self._args = args
self._kwargs = kwargs
def run(self):
fichierpath = self._args[0]
frame = self._args[1]
data = {'name': 'fichier_0',
'file': open(fichierpath)}
if(urllib2.urlopen(frame.param.serverUploadPath, data)):
frame.gauge.SetValue(99)
frame.Gt.SetLabel("Upload completed!")
class ShowFrame():
def __init__(self, parent):
app = wx.App()
MainWindow = mainFrame(None, -1, 'CryptUploader', parent)
app.MainLoop() |
Partager