0

我有一个想要添加“自动模式”的应用程序。

def start_stop_automode(self):
    self.set_auto()

   if not self.auto_mode_btn.isChecked() and self.observer.is_alive():
       self.observer.stop()
       self.observer.join()
       return
   else:
       self.observer.start()
       while True:
          try:
             time.sleep(1)
          except KeyboardInterrupt:
             self.observer.stop()
             self.observer.join()

它调用一个插槽来启动watchdog FileSystemEventHandler类,该类依次在文件上执行一些触发watchdog event.

class Event(FileSystemEventHandler):

    def on_created(self, event):   

    input_path = event.src_path
    if input_path.endswith('_1.CSV'):

        if self.file_creation_finished(input_path):
            file = os.path.split(input_path)[-1].rstrip('.CSV')
            file = file.split('_')[0]
            self.exec_funk(order=file)

通过调试,我看到FileSystemEventHandler类中的代码执行正确,除了在运行时缺少QMainWindow实际可操作的功能watchdog。我如何容纳他们两个?

4

1 回答 1

0

好的,所以我现在意识到解决方案是多么简单,只需删除while loop,您就可以使用QMainWindow.

于 2017-04-10T11:16:26.093 回答