2010-02-26 7 views
2

wxPython에 Application.DoEvents()가 있습니까?wxPython Application.DoEvents()와 동등한가요?

양식을 작성한 다음 느린 I/O 이벤트를 수행하고 양식이 이벤트가 완료 될 때까지 부분적으로 만 그려집니다. I/O가 시작되기 전에 양식을 완전히 그려야합니다.

나는 self.Refresh()을 시도했지만 아무런 효과가 없습니다.

답변

1

wx.Yield 또는 wx.SafeYield

당신이 정말로 I/O를 수행하는 별도의 스레드를 사용하여 GUI 스레드에 업데이트를 게시 할 wx.CallAfter을 사용해야하지만.

나는 보통이 같은 패턴을 사용 :

def start_work(self): 
    thread = threading.Thread(target=self.do_work, args=(args, go, here)) 
    thread.setDaemon(True) 
    thread.start() 
def do_work(self, args, go, here): 
    # do work here 
    # wx.CallAfter will call the specified function on the GUI thread 
    # and it's safe to call from a separate thread 
    wx.CallAfter(self.work_completed, result, args, here) 
def work_completed(self, result, args, here): 
    # use result args to update GUI controls here 
    self.text.SetLabel(result) 

당신은 일을 시작하기 위해 EVT_BUTTON 이벤트 예를 들어, GUI에서 start_work를 부를 것이다. do_work은 별도의 스레드에서 실행되지만 GUI 스레드에서 수행해야하므로 GUI 관련 작업을 수행 할 수 없습니다. 따라서 wx.CallAfter을 사용하여 GUI 스레드에서 함수를 실행하고 작업 스레드에서 인수를 전달할 수 있습니다.

+0

빠른 응답을 보내 주셔서 감사합니다. 별도의 스레드에서 I/O를 살펴 보겠습니다. – James

+0

대단히 감사합니다. wxpython에서 IO를 제대로 사용하는 방법을 설명하는 문서는 없습니다. 당신의 예제는 그것을 아주 잘 설명합니다. – Jah