Đây là ở ngã ba Phoenix của wxPython.Các chủ đề wxPython chặn
Tôi đang cố gắng chạy một vài luồng vì lợi ích của việc không chặn GUI.
Hai chủ đề của tôi hoạt động tốt, nhưng một trong số các chủ đề khác dường như không bao giờ đạt đến hàm kết quả bị ràng buộc. Tôi có thể nói rằng nó đang chạy, nó dường như không đúng để đăng sự kiện.
Dưới đây là các chức năng kết quả cho chủ đề tính chính:
def on_status_result(self, event):
if not self.panel.progress_bar.GetRange():
self.panel.progress_bar.SetRange(event.data.parcel_count)
self.panel.progress_bar.SetValue(event.data.current_parcel)
self.panel.status_label.SetLabel(event.data.message)
Đây là cách tôi đang ràng buộc họ:
from wx.lib.pubsub.core import Publisher
PUB = Publisher()
Đây là cách tôi đang ràng buộc phương pháp:
def post_event(message, data):
wx.CallAfter(lambda *a: Publisher().sendMessage(message, data=data))
Và đây là các chủ đề. Người đầu tiên không làm việc, nhưng thứ hai hai làm:
class PrepareThread(threading.Thread):
def __init__(self, notify_window):
threading.Thread.__init__(self)
self._notify_window = notify_window
self._want_abort = False
def run(self):
while not self._want_abort:
for status in prepare_collection(DATABASE, self._previous_id, self._current_id, self._year, self._col_type,
self._lock):
post_event('prepare.running', status)
post_event('prepare.complete', None)
return None
def abort(self):
self._want_abort = True
class SetupThread(threading.Thread):
def __init__(self, notify_window):
threading.Thread.__init__(self)
self._notify_window = notify_window
self._want_abort = False
def run(self):
while not self._want_abort:
do_more_stuff_with_the_database()
return None
def abort(self):
self._want_abort = True
class LatestCollectionsThread(threading.Thread):
def __init__(self, notify_window):
threading.Thread.__init__(self)
self._notify_window = notify_window
self._want_abort = False
def run(self):
while not self._want_abort:
do_stuff_with_my_database()
return None
def abort(self):
self._want_abort = True
prepare_collection
là một chức năng mà mang lại Status
đối tượng trông như thế này:
class Status:
def __init__(self, parcel_count, current_parcel, total, message):
self.parcel_count = parcel_count
self.current_parcel = current_parcel
self.total = total
self.message = message
Đây là cách tôi đang tạo/bắt đầu/đăng ký các PrepareThread:
MainForm(wx.Form):
prepare_thread = PrepareThread(self)
prepare_thread.start()
self.pub = Publisher()
self.pub.subscribe(self.on_status_result, 'prepare.running')
self.pub.subscribe(self.on_status_result, 'prepare.complete')
def on_status_result(self, event):
if not self.panel.progress_bar.GetRange():
self.panel.progress_bar.SetRange(event.data.parcel_count)
self.panel.progress_bar.SetValue(event.data.current_parcel)
self.panel.status_label.SetLabel(event.data.message)
tôi đã cố gắng loại bỏ dần từng prepare_collection
với range(10)
, nhưng tôi vẫn không bao giờ nhấn eve nt xử lý.
hey morgan xin lỗi ... tôi có lẽ sẽ không có cơ hội tối nay để xem xét điều này ... chỉ siêu bận rộn:/ –
@joran Đó là tất cả tốt. –
oh dang ... xin lỗi ... Tôi sẽ cố gắng và giúp đỡ cuối tuần này của bạn chỉ là một tuần điên rồ –