[출처 : http://www.imp17.com/tc/myevan/42?category=10]
import time
from threading import Thread
class WorkThread(Thread):
def __init__(self, onCurrentPos, onTotalCount):
Thread.__init__(self)
self.onCurrentPos = onCurrentPos
self.onTotalCount = onTotalCount
def run(self):
self.onTotalCount(100)
print "!!"
for i in range(100):
self.onCurrentPos(i+1)
time.sleep(0.3)
import wx
class GagePanel(wx.Panel):
MAX = 1000
def __init__(self, parent, title):
wx.Panel.__init__(self, parent, -1)
self.title = title
self.text = wx.StaticText(self, -1, title, (10, 10))
gage = wx.Gauge(self, -1, self.MAX, (10, 30), (250, 25),
wx.GA_HORIZONTAL|wx.GA_SMOOTH)
self.runButton = wx.Button(self, -1, "RUN", (210, 70))
self.Bind(wx.EVT_BUTTON, self.OnRun, self.runButton)
gage.SetBezelFace(5)
gage.SetShadowWidth(5)
self.gage = gage
self.pos = 0
self.count = 1
self.workThread = None
def OnCurrentPos(self, pos):
self.pos = pos + 1
self.gage.SetValue(self.MAX * self.pos / self.count)
self.text.SetLabel("%s (%d/%d)" % (self.title, self.pos, self.count))
def OnTotalCount(self, count):
self.count = count
def OnRun(self, event):
if self.workThread:
return
self.workThread = WorkThread(self.OnCurrentPos, self.OnTotalCount)
self.workThread.start()
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Progress",
pos = (0, 0), size = (320, 240))
self.CentreOnScreen(wx.BOTH)
self.panel = GagePanel(self, "progress")
self.panel.Layout()
class App(wx.App):
def OnInit(self):
frame = MainFrame()
self.SetTopWindow(frame)
frame.Show()
return True
App(redirect = False).MainLoop()
from threading import Thread
class WorkThread(Thread):
def __init__(self, onCurrentPos, onTotalCount):
Thread.__init__(self)
self.onCurrentPos = onCurrentPos
self.onTotalCount = onTotalCount
def run(self):
self.onTotalCount(100)
print "!!"
for i in range(100):
self.onCurrentPos(i+1)
time.sleep(0.3)
import wx
class GagePanel(wx.Panel):
MAX = 1000
def __init__(self, parent, title):
wx.Panel.__init__(self, parent, -1)
self.title = title
self.text = wx.StaticText(self, -1, title, (10, 10))
gage = wx.Gauge(self, -1, self.MAX, (10, 30), (250, 25),
wx.GA_HORIZONTAL|wx.GA_SMOOTH)
self.runButton = wx.Button(self, -1, "RUN", (210, 70))
self.Bind(wx.EVT_BUTTON, self.OnRun, self.runButton)
gage.SetBezelFace(5)
gage.SetShadowWidth(5)
self.gage = gage
self.pos = 0
self.count = 1
self.workThread = None
def OnCurrentPos(self, pos):
self.pos = pos + 1
self.gage.SetValue(self.MAX * self.pos / self.count)
self.text.SetLabel("%s (%d/%d)" % (self.title, self.pos, self.count))
def OnTotalCount(self, count):
self.count = count
def OnRun(self, event):
if self.workThread:
return
self.workThread = WorkThread(self.OnCurrentPos, self.OnTotalCount)
self.workThread.start()
class MainFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "Progress",
pos = (0, 0), size = (320, 240))
self.CentreOnScreen(wx.BOTH)
self.panel = GagePanel(self, "progress")
self.panel.Layout()
class App(wx.App):
def OnInit(self):
frame = MainFrame()
self.SetTopWindow(frame)
frame.Show()
return True
App(redirect = False).MainLoop()