def __init__(self, port, config, logger): super(TreeWidget, self).__init__() self.config = config self.logger = logger surpac_scl_cfg = self.config.get('master', 'surpac_language_cfg') self.treeWidget_load(surpac_scl_cfg=surpac_scl_cfg) self.shortcut = ShortCuts(config=self.config, logger=self.logger) surpacs = self.shortcut.get_surpac_cmd_list() self.choice_surpac_dialog = ChoiceSurpacDialog(config=self.config, logger=self.logger, title='请选择Surpac版本', surpacs=surpacs) surpac_languages = str(self.config.get('master', 'surpac_languages')).split(';') self.choice_language_dialog = ChoiceLanguageDialog( config=config, logger=logger, title="请选择Surpac语言", languages=surpac_languages)
def __init__(self, config: ConfigFactory, logger: LoggerFactory): super(MasterWidget, self).__init__() self.logger = logger self.config = config self.setOrientation(Qt.Horizontal) self.surpac_ports = None self.tree_widget = None self.short_cuts = ShortCuts(config=config, logger=logger) # 生成surpac_widget界面组件 self.surpac = Surpac(config=config, logger=logger) self.surpac.startSurpacDialog.start_surpac_signal.connect(self.start_surpac_listener) # 读取配置文件,检查surpac是否已经正确配置 self.surpac_cmd_list = [] if (self.surpac.check_surpac_location_config()): self.surpac_cmd_list = [self.config.get('master', 'surpac_location')] self.start_surpac_listener(self.surpac_cmd_list[0]) else: # 如果配置不正确,则从系统快捷方式获取surpac命令行列表 self.surpac.startSurpacDialog.set_surpacs(self.short_cuts.get_surpac_cmd_list()) self.surpac.startSurpacDialog.show()
def __init__(self, config: ConfigFactory, logger: LoggerFactory): self.logger = logger self.config = config self.surpac_pid = -1 self.shortcuts = ShortCuts(config=config, logger=logger) self.py_win32 = PY_Win32(config=config, logger=logger) # 生成surpac不同版本选择窗口 self.startSurpacDialog = StartSurpacDialog(config=config, logger=logger, title='请选择Surpac版本') # 清理旧surpac进程 if self.config.get('master', 'surpac_kill_other_process'): pids = self.py_win32.getPidsFromPName(pname='surpac', indexName='surpac2.exe', begin=11, end=24) self.py_win32.killProcess(pids=pids)
def __init__(self, config, logger): self.logger = logger self.config = config self.shortCut = ShortCuts(config=config, logger=logger) self.py_win32 = PY_Win32(config=config, logger=logger) # 生成版本选择窗口 self.startMineSchedDialog = StartMineSchedDialog( config=config, logger=logger, title='请选择MineSched版本') # 是否kill当前环境中所有已经启动的minesched进程 if self.config.get('minesched', 'minesched_kill_other_process'): pids = self.py_win32.getPidsFromPName(pname='MineSched', indexName='MineSched.exe', begin=13, end=22) self.py_win32.killProcess(pids=pids)
class TreeWidget(QTreeWidget): # 树形点击定义消息 treeItem_tbc_clicked_signal = Signal(str) treeItem_tcl_clicked_signal = Signal(str) treeItem_py_clicked_signal = Signal(str) treeItem_func_clicked_signal = Signal(str) # 初始化 def __init__(self, port, config, logger): super(TreeWidget, self).__init__() self.config = config self.logger = logger surpac_scl_cfg = self.config.get('master', 'surpac_language_cfg') self.treeWidget_load(surpac_scl_cfg=surpac_scl_cfg) self.shortcut = ShortCuts(config=self.config, logger=self.logger) surpacs = self.shortcut.get_surpac_cmd_list() self.choice_surpac_dialog = ChoiceSurpacDialog(config=self.config, logger=self.logger, title='请选择Surpac版本', surpacs=surpacs) surpac_languages = str(self.config.get('master', 'surpac_languages')).split(';') self.choice_language_dialog = ChoiceLanguageDialog( config=config, logger=logger, title="请选择Surpac语言", languages=surpac_languages) # 重构Tree组件 def treeWidget_load(self, surpac_scl_cfg): self.clear() self.treeWidget = QTreeWidgetItem(self) self.setColumnCount(1) self.setHeaderHidden(True) self.itemClicked.connect(self.__on_item_clicked) # 加入相对路径,处理pyinstaller打包后yml导入错误问题 self.scl_path = Path.get_resource_path(surpac_scl_cfg) # 加入menu菜单配置yml文件 menus = self.build_toplevel_menu(surpac_scl_cfg=self.scl_path) for item in menus: self.addTopLevelItem(item) self.setItemExpanded(item, True) # 树形菜单单击处理 def __on_item_clicked(self, item): # print(item.text(2)) print('==========插入读取软件锁代码============') # msg = item.text(2) if (msg): if '.tbc' in msg: self.treeItem_tbc_clicked_signal.emit(msg) elif '.tcl' in msg: self.treeItem_tcl_clicked_signal.emit(msg) elif '.py' in msg: self.treeItem_py_clicked_signal.emit(msg) elif 'choice_surpac' in msg: self.choice_surpac_dialog.show() elif 'choice_language' in msg: self.choice_language_dialog.show() else: self.treeItem_func_clicked_signal.emit(msg) # 构建Tree组件 def build_toplevel_menu(self, surpac_scl_cfg: str): # Tree递归构建 def build_menu_by_recursive(root: QTreeWidgetItem, menu_dict: dict): for key in menu_dict: item = QTreeWidgetItem() item_font = QFont() item_font.setPointSize( self.config.getint('master', 'master_item_font_size')) try: text = str(menu_dict[key]['text']) item.setText(0, text) item.setFont(0, item_font) except KeyError: pass try: descript = str(menu_dict[key]['descript']) item.setToolTip(0, descript) except KeyError: pass try: scl = str(menu_dict[key]['scl']) item.setText(2, scl) except KeyError: pass try: children = menu_dict[key]['children'] build_menu_by_recursive(item, children) except KeyError: pass try: expanded = menu_dict[key]['expanded'] item.setExpanded(expanded) except KeyError: pass root.addChild(item) surpac_scl_encoding = self.config.get('master', 'surpac_scl_encoding') menus = [] with open(file=surpac_scl_cfg, encoding=surpac_scl_encoding) as _f: menu_dict = yaml.load(_f, yaml.loader.FullLoader) for key in menu_dict: menu_toplevel_item = QTreeWidgetItem() menu_toplevel_item_font = QFont() menu_toplevel_item_font.setPointSize( self.config.getint('master', 'master_root_font_size')) try: text = str(menu_dict[key]['text']) menu_toplevel_item.setText(0, text) menu_toplevel_item.setFont(0, menu_toplevel_item_font) except KeyError: pass try: descript = str(menu_dict[key]['descript']) menu_toplevel_item.setToolTip(0, descript) except KeyError: pass try: scl = str(menu_dict[key]['scl']) menu_toplevel_item.setText(2, scl) except KeyError: pass try: expanded = menu_dict[key]['expanded'] menu_toplevel_item.setExpanded(expanded) except KeyError: pass try: children = menu_dict[key]['children'] build_menu_by_recursive(menu_toplevel_item, children) except KeyError: pass menus.append(menu_toplevel_item) return menus
class MasterWidget(QSplitter): def __init__(self, config: ConfigFactory, logger: LoggerFactory): super(MasterWidget, self).__init__() self.logger = logger self.config = config self.setOrientation(Qt.Horizontal) self.surpac_ports = None self.tree_widget = None self.short_cuts = ShortCuts(config=config, logger=logger) # 生成surpac_widget界面组件 self.surpac = Surpac(config=config, logger=logger) self.surpac.startSurpacDialog.start_surpac_signal.connect(self.start_surpac_listener) # 读取配置文件,检查surpac是否已经正确配置 self.surpac_cmd_list = [] if (self.surpac.check_surpac_location_config()): self.surpac_cmd_list = [self.config.get('master', 'surpac_location')] self.start_surpac_listener(self.surpac_cmd_list[0]) else: # 如果配置不正确,则从系统快捷方式获取surpac命令行列表 self.surpac.startSurpacDialog.set_surpacs(self.short_cuts.get_surpac_cmd_list()) self.surpac.startSurpacDialog.show() # 语言选择信号接收槽 @Slot(str) def change_language_listener(self, result): self.tree_widget.treeWidget_load(result) # 命令与执行脚本对应(待优化) if ('_cn' in result): client = SurpacChangeLanguageWorker(logger=self.logger, config=self.config, port=self.surpac_ports[0], msg='test_language_cn.tcl') client.start() elif ('_en' in result): client = SurpacChangeLanguageWorker(logger=self.logger, config=self.config, port=self.surpac_ports[0], msg='test_language_en.tcl') client.start() # Surpac启动信号接收槽 @Slot(str) def start_surpac_listener(self, result): # 构建surpac界面widget self.surpac_widget, self.surpac_ports, self.surpac_pid = self.surpac.build_surpac_widget(result) # Menu_widget配置 menu_widget = QWidget() menu_widget_layout = QVBoxLayout() menu_widget.setLayout(menu_widget_layout) # 构建tree界面widget self.tree_widget = TreeWidget(config=self.config, logger=self.logger, port=self.surpac_ports[0]) menu_widget_layout.addWidget(self.tree_widget) # 将改变surpac版本的消息与surpac更改监听器关联 self.tree_widget.choice_surpac_dialog.choices_surpac_signal.connect(self.change_surpac_listener) # 将改变语言的消息与语言改变监听器关联 self.tree_widget.choice_language_dialog.choices_language_dialog_signal.connect(self.change_language_listener) self.tree_widget.treeItem_func_clicked_signal.connect(self.treeItem_func_clicked_listener) self.tree_widget.treeItem_tcl_clicked_signal.connect(self.treeItem_tcl_clicked_listener) self.tree_widget.treeItem_tbc_clicked_signal.connect(self.treeItem_tbc_clicked_listener) self.tree_widget.treeItem_py_clicked_signal.connect(self.treeItem_py_clicked_listener) # 在工作区中加入surpac和menu组件 self.addWidget(self.surpac_widget) self.addWidget(menu_widget) # Surpac版本选择信号接收槽 @Slot(str) def change_surpac_listener(self, result): self.surpac.py_win32.killProcess([self.surpac_pid]) self.surpac_widget, self.surpac_ports, self.surpac_pid = self.surpac.build_surpac_widget(result) self.replaceWidget(0, self.surpac_widget) # 运行func类脚本 @Slot(str) def treeItem_func_clicked_listener(self, result): client = FunScriptWorker(logger=self.logger, config=self.config, port=self.surpac_ports[0], msg=result) client.start() # 运行tcl类脚本 @Slot(str) def treeItem_tcl_clicked_listener(self, result): client = TclScriptWorker(config=self.config, logger=self.logger, port=self.surpac_ports[0], msg=result) client.start() # 运行tbc类脚本 @Slot(str) def treeItem_tbc_clicked_listener(self, result): client = TbcScriptWorker(logger=self.logger, config=self.config, port=self.surpac_ports[0], msg=result) client.start() # 运行py类脚本 @Slot(str) def treeItem_py_clicked_listener(self, result): client = PyScriptWorker(logger=self.logger, config=self.config, port=self.surpac_ports[0], msg=result) client.start()
def __init__(self, config: ConfigFactory, logger: LoggerFactory): super(MainWindow, self).__init__() self.config = config self.logger = logger self.setWindowTitle(config.get('default', 'title')) self.resize(self.config.getint('default', 'width'), self.config.getint('default', 'height')) self.py_win32 = PY_Win32(logger=logger, config=config) self.short_cuts = ShortCuts(logger=logger, config=config) self.mineched_widget = None self.minesched_pid = 0 self.whittle_widget = None self.whittle_pid = 0 # tab_widget界面组件 self.tab_widget = TabWidget() font = self.tab_widget.tabBar().font() font.setPointSize(18) self.tab_widget.tabBar().setFont(font) # 构建web_widget界面组件 try: web_widget_url: str = config.get('web', 'web_url') web_widget = WebEngineView(config=config, logger=logger, tabWidget=self.tab_widget) web_widget.load(QUrl(web_widget_url)) web_tag_title = config.get('web', 'web_tag_title') web_widget_index = self.tab_widget.add_tab_item(widget=web_widget, item_title=web_tag_title) self.tab_widget.tabBar().setTabButton(web_widget_index, QTabBar.RightSide, None) except NoSectionError: self.logger.debug("No 'Web Section' Configuration") # 构建master_widget界面组件 try: self.master_widget = MasterWidget(config=config, logger=logger) master_tag_title = config.get('master', 'master_tag_title') master_widget_index = self.tab_widget.add_tab_item(widget=self.master_widget, item_title=master_tag_title) self.tab_widget.tabBar().setTabButton(master_widget_index, QTabBar.RightSide, None) except NoSectionError: self.logger.debug("No 'Master Section' Configuration") try: threejs_widget_url: str = config.get('threejs', 'threejs_url') threejs_widget = WebEngineView(config=config, logger=logger, tabWidget=self.tab_widget) threejs_widget.load(QUrl(threejs_widget_url)) threejs_tag_title = config.get('threejs', 'threejs_tag_title') threejs_widget_index = self.tab_widget.add_tab_item(widget=threejs_widget, item_title=threejs_tag_title) self.tab_widget.tabBar().setTabButton(threejs_widget_index, QTabBar.RightSide, None) except NoSectionError: self.logger.debug("No 'Threejs Section' Configuration") # 生成minesched_widget组件 try: minesched_location = self.config.get('minesched', 'minesched_location') self.minesched = MineschedWidget(config=self.config, logger=self.logger) self.minesched.startMineSchedDialog.start_minesched_signal.connect(self.star_minesched_listener) # 检查minesched路径是否配置正确 self.minesched_cmd_list = [] if self.minesched.check_minesched_location_config(): self.minesched_cmd_list = [minesched_location] self.star_minesched_listener(result=self.minesched_cmd_list[0]) else: self.minesched.startMineSchedDialog.set_minescheds(self.short_cuts.get_minesched_cmd_list()) self.minesched.startMineSchedDialog.show() except NoSectionError: self.logger.debug("No 'MineSched Section' Configuration") # 生成whittle_widget界面组件 try: whittle_location = self.config.get('whittle', 'whittle_location') self.whittle = WhittleWidget(config=config, logger=logger) self.whittle.startWhittleDialog.start_whittle_signal.connect(self.star_whittle_listener) # 检查mwhittle路径是否配置正确 self.whittle_cmd_list = [] if self.whittle.check_whittle_location_config(): self.whittle_cmd_list = [whittle_location] self.star_whittle_listener(result=self.whittle_cmd_list[0]) else: self.whittle.startWhittleDialog.set_whittles(self.short_cuts.get_whittle_cmd_list()) self.whittle.startWhittleDialog.show() except NoSectionError: self.logger.debug("No 'Whittle Section' Configuration") # 指定当前tab index_tab = config.getint('default', 'index_tab') self.tab_widget.setCurrentIndex(index_tab) self.tab_widget.update() # 在窗口中央显示tab self.setCentralWidget(self.tab_widget)
class MainWindow(QMainWindow): # 初始化 def __init__(self, config: ConfigFactory, logger: LoggerFactory): super(MainWindow, self).__init__() self.config = config self.logger = logger self.setWindowTitle(config.get('default', 'title')) self.resize(self.config.getint('default', 'width'), self.config.getint('default', 'height')) self.py_win32 = PY_Win32(logger=logger, config=config) self.short_cuts = ShortCuts(logger=logger, config=config) self.mineched_widget = None self.minesched_pid = 0 self.whittle_widget = None self.whittle_pid = 0 # tab_widget界面组件 self.tab_widget = TabWidget() font = self.tab_widget.tabBar().font() font.setPointSize(18) self.tab_widget.tabBar().setFont(font) # 构建web_widget界面组件 try: web_widget_url: str = config.get('web', 'web_url') web_widget = WebEngineView(config=config, logger=logger, tabWidget=self.tab_widget) web_widget.load(QUrl(web_widget_url)) web_tag_title = config.get('web', 'web_tag_title') web_widget_index = self.tab_widget.add_tab_item(widget=web_widget, item_title=web_tag_title) self.tab_widget.tabBar().setTabButton(web_widget_index, QTabBar.RightSide, None) except NoSectionError: self.logger.debug("No 'Web Section' Configuration") # 构建master_widget界面组件 try: self.master_widget = MasterWidget(config=config, logger=logger) master_tag_title = config.get('master', 'master_tag_title') master_widget_index = self.tab_widget.add_tab_item(widget=self.master_widget, item_title=master_tag_title) self.tab_widget.tabBar().setTabButton(master_widget_index, QTabBar.RightSide, None) except NoSectionError: self.logger.debug("No 'Master Section' Configuration") try: threejs_widget_url: str = config.get('threejs', 'threejs_url') threejs_widget = WebEngineView(config=config, logger=logger, tabWidget=self.tab_widget) threejs_widget.load(QUrl(threejs_widget_url)) threejs_tag_title = config.get('threejs', 'threejs_tag_title') threejs_widget_index = self.tab_widget.add_tab_item(widget=threejs_widget, item_title=threejs_tag_title) self.tab_widget.tabBar().setTabButton(threejs_widget_index, QTabBar.RightSide, None) except NoSectionError: self.logger.debug("No 'Threejs Section' Configuration") # 生成minesched_widget组件 try: minesched_location = self.config.get('minesched', 'minesched_location') self.minesched = MineschedWidget(config=self.config, logger=self.logger) self.minesched.startMineSchedDialog.start_minesched_signal.connect(self.star_minesched_listener) # 检查minesched路径是否配置正确 self.minesched_cmd_list = [] if self.minesched.check_minesched_location_config(): self.minesched_cmd_list = [minesched_location] self.star_minesched_listener(result=self.minesched_cmd_list[0]) else: self.minesched.startMineSchedDialog.set_minescheds(self.short_cuts.get_minesched_cmd_list()) self.minesched.startMineSchedDialog.show() except NoSectionError: self.logger.debug("No 'MineSched Section' Configuration") # 生成whittle_widget界面组件 try: whittle_location = self.config.get('whittle', 'whittle_location') self.whittle = WhittleWidget(config=config, logger=logger) self.whittle.startWhittleDialog.start_whittle_signal.connect(self.star_whittle_listener) # 检查mwhittle路径是否配置正确 self.whittle_cmd_list = [] if self.whittle.check_whittle_location_config(): self.whittle_cmd_list = [whittle_location] self.star_whittle_listener(result=self.whittle_cmd_list[0]) else: self.whittle.startWhittleDialog.set_whittles(self.short_cuts.get_whittle_cmd_list()) self.whittle.startWhittleDialog.show() except NoSectionError: self.logger.debug("No 'Whittle Section' Configuration") # 指定当前tab index_tab = config.getint('default', 'index_tab') self.tab_widget.setCurrentIndex(index_tab) self.tab_widget.update() # 在窗口中央显示tab self.setCentralWidget(self.tab_widget) @Slot(str) def star_minesched_listener(self, result): self.minesched_cmd_list = [result] self.mineched_widget, self.minesched_pid = self.minesched.build_minesched_widget(cmd=self.minesched_cmd_list[0]) minesched_tag_title = self.config.get('minesched', 'minesched_tag_title') minesched_widget_index = self.tab_widget.add_tab_item(widget=self.mineched_widget, item_title=minesched_tag_title) self.tab_widget.tabBar().setTabButton(minesched_widget_index, QTabBar.RightSide, None) @Slot(str) def star_whittle_listener(self, result): self.whittle_cmd_list = [result] self.whittle_widget, self.whittle_pid = self.whittle.build_whittle_widget(self.whittle_cmd_list[0]) whittle_tag_title = self.config.get('whittle', 'whittle_tag_title') whittle_widget_index = self.tab_widget.add_tab_item(widget=self.whittle_widget, item_title=whittle_tag_title) self.tab_widget.tabBar().setTabButton(whittle_widget_index, QTabBar.RightSide, None) # 窗口关闭 def closeEvent(self, event): replay = QMessageBox.question(self, '操作提示', '是否退出应用?', QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if replay == QMessageBox.Yes: event.accept() # 获取surpac进程id surpac_id = self.master_widget.surpac.surpac_pid # 如果surpac已经启动,则清除surpac进程 if surpac_id > 0: self.py_win32.killProcess([surpac_id]) if self.whittle_pid > 0: self.py_win32.killProcess([self.whittle_pid]) if self.minesched_pid > 0: self.py_win32.killProcess([self.minesched_pid]) super().closeEvent(event) else: event.ignore()