def run(self): print('run') AtpBat.setAtpConf('1') time.sleep(0.1) with concurrent.futures.ThreadPoolExecutor( max_workers=os.cpu_count()) as executor: futures = [] for i in range(len(self.path)): futures.append( executor.submit(self.runJob, self.path[i], self.fname[i], self.dic[i])) # futures[executor.submit(self.runJob, self.path[i], self.fname[i], self.dic)] = i for future in concurrent.futures.as_completed(futures): try: data = future.result() print('run result: ' + data) except Exception as exc: print('Generated an exception: %s' % exc) else: if data: self.progress += 1 print("progress: %d" % self.progress) self.progressUpdated.emit( int(self.progress / len(self.path) * 100)) self.progressUpdated.emit(100) self.clear()
def on_set_runATP_clicked(self): """ 设置runatp的路径 :return: """ file, n_1 = QFileDialog.getOpenFileName(self, "请选取runATP_G.bat脚本文件", '', 'BAT(*.bat)') # 没有选择文件 if not file: return AtpBat.modify_bat(file)
def load_ADPfile(self): # 先配置脚本 if not AtpBat.isBatExists(): QMessageBox.warning(self, "错误", '请先配置runATP_G.bat脚本文件') return file = QFileDialog.getOpenFileName(self, "选取项目文件", '', 'ADP or ACP Files(*.adp *.acp)') if not file: return path = str(file[0]) # 选中后 if path: # 处理存储最近项目的txt文件 self.recent_item_list= RecentItemRW.read_recent_items() count = len(self.recent_item_list) if count == 0: self.recent_item_list.append(path) else: if self.recent_item_list[count - 1] != path: if count == 6: del self.recent_item_list[0] self.recent_item_list.append(path) RecentItemRW.write_recent_items(self.recent_item_list) # 接口,将file传递给menu->mainwindow self.show_MenuBar_MainWindow(path)
def on_atp_run_clicked(self): """ 运行按钮 :return: """ print('on_atp_run_clicked') # 先更新atp # 更新路径,对比不一致项 self.on_atp_update_clicked() # 修改配置文件 AtpBat.setAtpConf('1') time.sleep(1) # 发送F2键 win32api.PostMessage(self.handle_atpdraw, win32con.WM_KEYDOWN, win32con.VK_F2, 0)
def on_atp_update_clicked(self): """ 更新按钮 :return: """ print("on_atp_refresh_clicked") # 修改配置文件内容 AtpBat.setAtpConf('0') time.sleep(1) # 发送F2键 win32api.PostMessage(self.handle_atpdraw, win32con.WM_KEYDOWN, win32con.VK_F2, 0) # 等待atp生成 time.sleep(2) # 更新atp路径 path = AtpBat.getAtpPath() self.__atp_file = path self.parse_atp(self.__atp_file)
def __init__(self): QThread.__init__(self) # self.moveToThread(self) # runATP.exe的路径 self.__runATPPath = AtpBat.getBatPath() # RunATP.__runATPPath = 'D:/ATPDraw/runATP_G.bat' # 进度条进度 self.progress = 0 # atp文件路径 self.path = [] # atp文件名 self.fname = [] # 分析pl4的dic self.dic = []
def setting_runATPexe(self): file, n_1 = QFileDialog.getOpenFileName(self, "请选取runATP_G.bat脚本文件", '', 'BAT(*.bat)') if not file: return # 设置apt路径接口 AtpBat.modify_bat(file)
def create(self, total, argDic): """ 生成atp文件的方法 :param total: 总次数 :param argDic: 所有参数设置的字典 {“switch”:swtich_arg_set} :return: """ for time in range(total): # 初始化本地的组件列表 branch = self.__handler.branch lightning = self.__handler.lightning lcc = [] switch = [] source = [] output = [] # 开关参数设置 entities = argDic["switch"].getEntities() for k, v in self.__handler.switch.items(): # 没有设置参数 if k not in entities: switch.append(v.clone()) continue # 针对一个元件多个结点参数设置情况 # 如果该结点在参数设置中存在 while k in entities: # 获取结点index,删除该结点,获取arglist index = entities.index(k) argList = ArgvToList.toList(argDic['switch'].getArg(index), total, time) entities.pop(index) # 获取参数设置后的结点 argSwitch = [] for i in range(len(argList)): # 第奇数个参数,闭合 if i % 2 == 0: temp = v.clone() temp.tclose = Convert.offsetRandom(Convert.toDecimal(argList[i])) argSwitch.append(temp) # 第偶数个参数,断开 elif i % 2 == 1: argSwitch[i // 2].top = Convert.offsetRandom(Convert.toDecimal(argList[i])) # temp.top = Convert.toDecimal(argList[i]) # 参数个数多余两个,并且为奇数,即最后一个的top没有值 if (len(argList) > 2) and (len(argSwitch) // 2 == 1): argSwitch[-1].top = AtpSetting.get_time_max() switch.extend(argSwitch) # 新建目录和文件 dir = self.__path + '/' + self.__fileName + "_%d" % time if not os.path.exists(dir): os.mkdir(dir) shutil.copy(AtpBat.getAtpPath(), dir) self.__file = open(dir + "/" + self.__fileName + '.atp', 'w+') # 写入文件开头部分 self.__file.write('BEGIN NEW DATA CASE\n') self.__infoWrite(self.__handler.info) self.__headWrite(self.__handler.head) self.__branchWrite(self.__handler.branch.values()) self.__lightningWrite(self.__handler.lightning) self.__lccWrite(self.__handler.lcc) self.__switchWrite(switch) self.__sourceWrite(self.__handler.source.values()) self.__outputWrite(self.__handler.output) # 写入文件结尾 self.__file.writelines( ["BLANK BRANCH\n", "BLANK SWITCH\n", "BLANK SOURCE\n", "BLANK OUTPUT\n", "BLANK PLOT\n", "BEGIN NEW DATA CASE\n", "BLANK\n"]) self.__file.close()