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
| #-*- coding:utf-8 -*-
import wx
class Root(wx.Frame):
def __init__(self, titre):
wx.Frame.__init__(self, None, -1, title = titre, size = (180,180))
self.Center(True)
self.font2 = wx.Font(8, wx.FONTFAMILY_DECORATIVE, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False, 'Verdana')
#---------
wx.EVT_BUTTON(self, 101, self.fonction1)
wx.EVT_BUTTON(self, 102, self.fonction2)
self.panel = wx.Panel(self, -1)
self.btn3 = wx.Button(self.panel, 101, "Lancer la fonction 1", pos = (10, 10), size = (150,-1))
self.gauge = wx.Gauge(self.panel, -1, 50, pos = (10,80), size = (150, -1))
self.count = 0
def TimerHandler(self,evt):
self.count = self.count + 1
if self.count >= 50:
self.count = 0
self.gauge.SetValue(self.count)
def fonction1(self, evt):
self.Bind(wx.EVT_TIMER, self.TimerHandler)
self.timer = wx.Timer(self)
self.timer.Start(100)
nb = 300
for i in range(nb):
print u'position n° %s' % i
self.btn4 = wx.Button(self.panel, 102, "Lancer la fonction 2", pos = (10, 40), size = (150,-1))
evt.Skip()
def fonction2(self, evt):
self.Bind(wx.EVT_TIMER, self.TimerHandler)
self.timer = wx.Timer(self)
self.timer.Start(100)
nb = 3000
for i in range(nb):
print u'position n° %s' % i
evt.Skip()
self.btn4.Destroy()
self.gauge.SetValue(50)
self.timer.Stop()
self.gauge.SetValue(0)
evt.Skip()
class MonApp(wx.App):
def OnInit(self):
fen = Root('Essais Thread')
fen.Show(True)
self.SetTopWindow(fen)
return True
app = MonApp()
app.MainLoop() |
Partager