-1
標題幾乎總結了這個問題。我有一個我已經編寫好的GUI,我試圖修改我的錯誤處理以更好地利用PyQt的信號和插槽。但是,我遇到了一些問題。我正在測試一個錯誤處理語句,如果用戶點擊某個特定的按鈕,會出現一個對話框,告訴他們他們還沒有輸入正確的信息。該對話框由信號和插槽控制,並在應有時出現。但是,如果我關閉對話框,然後再次單擊該按鈕,對話框將彈出兩次。這會發生疊加。也就是說,如果我第三次單擊該按鈕,則會出現三次對話框,依此類推。我不知道還有什麼要做。我試圖檢查以確保所有QThreads結束。我甚至去使用QThread.terminate(),你永遠不應該這樣做,我仍然以相同的結果結束。任何想法是什麼導致這一點?代碼snipet在下面。PyQt在每次點擊後創建添加對話框
def error_check_in_thread(self, method):
self.connect(method, QtCore.SIGNAL("selenium_error"), lambda: self.error_launch("selenium_error"))
self.connect(method, QtCore.SIGNAL("attribute_error"), lambda: self.error_launch("attribute_error"))
self.connect(method, QtCore.SIGNAL("name_error"), lambda: self.error_launch("name_error"))
self.connect(method, QtCore.SIGNAL("os_error"), lambda: self.error_launch("os_error"))
self.connect(method, QtCore.SIGNAL("finished()"), lambda: self.append_log(0))
self.connect(method, QtCore.SIGNAL("terminated()"), lambda: self.append_log(1))
method.start()
return
def error_launch(self, error):
dialog = ErrorDialogs()
if error == "selenium_error":
dialog.pipeline_pilot_automation_error()
elif error == "attribute_error":
dialog.attribute_error()
elif error == "os_error":
dialog.path_error()
elif error == "session_info_error":
dialog.session_info_error()
self.error_counter += 1
return
def append_log(self, exit_type):
if exit_type == 0:
self.log_edit_area.appendPlainText(str(MainGui.log_output[0]))
elif exit_type == 1:
self.log_edit_area.appendPlainText("THE METHOD WAS TERMINATED PREMATURELY\n" + "#"*50)
MainGui.log_output = []
class WorkingThread(QtCore.QThread):
def __init__(self, selector):
QtCore.QThread.__init__(self)
self.selector = selector
self.method_info = None
def __del__(self):
self.wait()
# Controls which function to launch in another thread based on button presses in MainGui
def run(self):
print("start")
try:
if self.selector == 1:
self.method_info = "DIRECTORIES AND SUBDIRECTORIES CREATION "
MainGui.log_output.append("ACTION AT: " + "[[" + str(datetime.datetime.now()) + "]]" + "\n" +
self.method_info + "SUCCESSFUL FOR: " + MainGui.da_batch_name + "\n" + "#"*50)
asa.mkdirsda(MainGui.hdg_da_path, MainGui.da_batch_folder, MainGui.da_batch_subfolders)
elif self.selector == 2:
self.method_info = "LIMS SAMPLE SHEET MOVEMENT TO AUTOSCORE SUBDIRECTORY "
MainGui.log_output.append("ACTION AT: " + "[[" + str(datetime.datetime.now()) + "]]" + "\n" +
self.method_info + "SUCCESSFUL FOR: " + MainGui.da_batch_name + "\n" + "#"*50)
asa.mvlims(MainGui.needs_gs_lims_file, MainGui.subfolder_autoscore,
MainGui.lims_samplesheet)
elif self.selector == 3:
self.method_info = "GENOMESTUDIO "
MainGui.log_output.append("ACTION AT: " + "[[" + str(datetime.datetime.now()) + "]]" + "\n" +
self.method_info + "STARTED FOR: " + MainGui.da_batch_name + "\n" + "#"*50)
asa.gsprocess(MainGui.subfolder_genomestudio, MainGui.da_batch_name,
MainGui.lims_samplesheet_file)
MainGui.log_output.append("ACTION AT: " + "[[" + str(datetime.datetime.now()) + "]]" + "\n" +
self.method_info + "SUCCESSFUL FOR: " + MainGui.da_batch_name + "\n" + "#"*50)
elif self.selector == 4:
self.method_info = "FINAL REPORT MOVEMENT TO AUTOSCORE SUBDIRECTORY "
MainGui.log_output.append("ACTION AT: " + "[[" + str(datetime.datetime.now()) + "]]" + "\n" +
self.method_info + "SUCCESSFUL FOR: " + MainGui.da_batch_name + "\n" + "#"*50)
asa.mvfinalreport(MainGui.subfolder_genomestudio, MainGui.da_batch_name,
MainGui.finalreport_file, MainGui.subfolder_autoscore)
elif self.selector == 5:
self.method_info = "PIPELINE PILOT AUTOMATION "
MainGui.log_output.append("ACTION AT: " + "[[" + str(datetime.datetime.now()) + "]]" + "\n" +
self.method_info + "STARTED FOR: " + MainGui.da_batch_name + "\n" + "#"*50)
asa.pipelineas(MainGui.userid, MainGui.userpass, MainGui.da_batch_name,
MainGui.raw_data_path)
MainGui.log_output.append("ACTION AT: " + "[[" + str(datetime.datetime.now()) + "]]" + "\n" +
self.method_info + "SUCCESSFUL FOR: " + MainGui.da_batch_name + "\n" + "#"*50)
elif self.selector == 6:
self.method_info = "GBS SET DIRECTORIES CREATION"
MainGui.log_output.append("ACTION AT: " + "[[" + str(datetime.datetime.now()) + "]]" + "\n" +
self.method_info + "SUCCESSFUL FOR: " + MainGui.gbs_set_name + "\n" + "#"*50)
asa.mkdirsgbs(MainGui.gbs_path, MainGui.gbs_set_name)
except (ElementNotVisibleException, ElementNotSelectableException, NoSuchElementException,
NoSuchWindowException, UnexpectedAlertPresentException):
MainGui.log_output.append("ACTION AT: " + "[[" + str(datetime.datetime.now()) + "]]" + "\n" +
self.method_info + "FAILED DUE TO SELENIUM ERROR\n" + "#"*50)
selenium_error = QtCore.pyqtSignal()
self.emit(QtCore.SIGNAL("selenium_error"))
return
except AttributeError:
MainGui.log_output.append("ACTION AT: " + "[[" + str(datetime.datetime.now()) + "]]" + "\n" +
self.method_info + "FAILED DUE TO ATTRIBUTE ERROR\n" + "#"*50)
attribute_error = QtCore.pyqtSignal()
self.emit(QtCore.SIGNAL("attribute_error"))
print("stop")
return
return