def f_main(): """主程序,保证程序单实例运行""" app = QtWidgets.QApplication(sys.argv) app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5()) servername = "TransTools" socket = QLocalSocket() socket.connectToServer(servername) if socket.waitForConnected(500): # 程序只允许单例运行 showmsg("程序已运行!") return(app.quit()) # 没有实例运行,创建服务器 localServer = QLocalServer() localServer.listen(servername) try: main = Main() main.show() sys.exit(app.exec_()) except Exception as e: showmsg(str(e), type=QMessageBox.Critical) finally: localServer.close()
def manual(self): """手动传输""" try: self._manual = TransManual(self.transinfo_list) self._manual.show() except Exception as e: showmsg(str(e), type=QMessageBox.Critical)
def run(self): """异步获取,获取运行时信息""" _provider = TransDataProvider() # 数据库数据提供对象 try: translist = _provider.get_trans_list() # 获取传输列表 translog = _provider.get_trans_log(self.translog_parm) signal = dict(translist=translist, translog=translog) self.trigger.emit(signal) except Exception as e: showmsg(str(e), type=QMessageBox.Critical)
def display_post(self, signal): if not signal: return try: translist = signal.get("translist", None) translog = signal.get("translog", None) if translist: # 设置传输列表 self.set_transinfo(translist) if translog: # 设置传输日志 self.set_translog(translog_list=translog) except Exception as e: showmsg(str(e))
def closeEvent(self, event): """关闭事件,只有窗口隐藏状态下才能关闭串口""" if not self.isHidden(): self.hide() self.trayicon.show() event.ignore() else: try: ret = showmsg("程序正在运行,是否关闭?", type=QMessageBox.Question) if ret != QMessageBox.Ok: event.ignore() else: event.accept() except Exception as e: showmsg(str(e), QMessageBox.Critical)
def trans(self): """手动传输""" if not self.listviews: return True, '' for listview in self.listviews: for i in range(listview.count()): item = listview.item(i) if not item.checkState(): continue sheetid = item.data(1) try: begin_task(sheetid) except Exception as e: print(str(e)) showmsg("传输完成")
def save(self): """保存设置""" try: transtype_list = [] for transgroupbox in self.transgroupbox_list: transgroupbox.save() transtype_list.append(transgroupbox.transtype) result, data = self._provider.set_trans_list(transtype_list) if result: showmsg("保存成功") else: showmsg(data) except Exception as e: showmsg(repr(e))