import os import time import wx import wx.xrc import wx_gui as w def runLater(handler): wx.CallAfter(handler) def runThread(handler): import threading thread = threading.Thread(target=handler) thread.start() class FileDrop(wx.FileDropTarget): def __init__(self, window): wx.FileDropTarget.__init__(self) self.window = window def OnDropFiles(self, x, y, filenames): self.window.OnDropFile(filenames) return True class Timer(): def __init__(self,parent,handler): self.timer = wx.Timer(parent) parent.Bind( wx.EVT_TIMER, handler, self.timer ) def start(self,msec): self.timer.Start(msec) def stop(self): self.timer.Stop() class Frame(w.Frame): def __init__(self): w.Frame.__init__(self,None) self.SetFileDropHandler() self.SetTimerHandler() self.SetListColumn( ("File Name", "Size", "Status"), ( 360, 80, 80 ), ( -1, 1, wx.LIST_FORMAT_CENTER ) ) self.timerCount = 0 self.threadCount = 0 def SetFileDropHandler(self): dropTarget = FileDrop(self) self.m_textFile.SetDropTarget(dropTarget) self.m_listData.SetDropTarget(dropTarget) def SetTimerHandler(self): self.timer = Timer( self, self.TimerHandler ) def TimerHandler(self,event): self.m_statusBar.SetStatusText( " " + str(self.timerCount), 0 ) self.timerCount = self.timerCount + 1 def ThreadAction(self): self.m_statusBar.SetStatusText( " " + str(self.threadCount), 1 ) self.threadCount = self.threadCount + 1 def ThreadHandler(self): for i in range(100): runLater(self.ThreadAction) time.sleep(0.5) def SetListColumn(self,labels,widths,aligns): for i in range(len(labels)): self.m_listData.AppendColumn( labels[i], format=aligns[i], width=widths[i] ) def AddListRow(self,row): self.m_listData.Append( row ) def OnDropFile(self,filenames): for f in filenames: if os.path.isfile(f): self.AddListRow( (f, os.path.getsize(f), "-") ) def m_buttonStartOnButtonClick( self, event ): self.timer.start(1000) runThread(self.ThreadHandler) event.Skip() def m_buttonStopOnButtonClick( self, event ): self.timer.stop() event.Skip() class App(wx.App): def OnInit(self): frame = Frame() frame.Show() self.SetTopWindow(frame) return True if __name__ == "__main__": app = App() app.MainLoop()
2020년 8월 6일 목요일
wxPython App Example II
1. wxPython App Example
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기