wxPython GUI与现有流程
我最初想用Python创建一个带有看门狗和进程的文件监控系统。在我的程序中,我有一个子类(wxPython GUI与现有流程,python,python-2.7,wxpython,multiprocessing,Python,Python 2.7,Wxpython,Multiprocessing,我最初想用Python创建一个带有看门狗和进程的文件监控系统。在我的程序中,我有一个子类(DirectoryMonitorHandler)来监视文件夹更改。声明全局队列,以便DirectoryMonitorHandler将项目插入队列。然后,队列可以处理用于处理由DirectoryMonitorHandler插入的对象的子类。以下是我的程序中的代码片段: if __name__ == "__main__": # The global queue that is shared by the
DirectoryMonitorHandler
)来监视文件夹更改。声明全局队列,以便DirectoryMonitorHandler
将项目插入队列。然后,队列可以处理用于处理由DirectoryMonitorHandler
插入的对象的子类。以下是我的程序中的代码片段:
if __name__ == "__main__":
# The global queue that is shared by the DirectoryMonitorHandler and BacklogManager is created
q = Queue()
# Check if source directory exists
if os.path.exists(source):
# DirectoryMonitorHandler is initialized with the global queue as the input
monitor_handler = DirectoryMonitorHandler(q)
monitor = polling.PollingObserver()
monitor.schedule(monitor_handler, source, recursive = True)
monitor.start()
# BacklogManager is initialized with the global queue as the input
mamanger = BacklogManager(q)
mamanger.start()
mamanger.join()
monitor.join()
else:
handleError('config.ini', Error.SourceError)
这个程序运行良好,但现在我决定向它添加一个GUI组件。以下是我到目前为止的情况:
class MonitorWindow(wx.Frame):
def __init__(self, parent):
super(MonitorWindow, self).__init__(parent, title='Monitor', size=(size_width, size_height))
staticBox = wx.StaticBox(self, label='Monitor Status:', pos=(5, 105), size=(size_width - 28, size_height/3))
self.statusLabel = wx.StaticText(staticBox, label='None', pos=(10, 35), size=(size_width, 20), style=wx.ALIGN_LEFT)
self.InitUI()
def InitUI(self):
panel = wx.Panel(self)
self.SetBackgroundColour(background_color)
self.Centre()
self.Show()
def updateStatus(self, status):
self.statusLabel.SetLabel('Update: ' + status)
if __name__ == '__main__':
app = wx.App()
window = MonitorWindow(None)
app.MainLoop()
此窗口工作正常,但我不确定如何将这两个组件集成在一起。wxpythongui应该作为一个单独的进程运行吗?我想我可以创建一个MonitorWindow
的实例,在启动之前将其传递到DirectoryMonitorHandler
和BacklogManager
我也读过这篇文章,它确实解释了wxPython窗口如何处理线程,但我需要它来处理进程。另一个可能的解决方案是,我必须从
窗口
类中创建并启动DirectoryMonitorHandler
和BacklogManager
的实例。你们认为呢?wxPython本身应该是主进程,它应该启动长时间运行的进程来监视您的文件系统。如果您使用的是多处理模块,那么您可能应该阅读以下内容之一: