def tab2_mainFunctableViewDelMenu(self, checked=False): """ 单击菜单 - 删除. :return: """ self.statusbar.showMessage("单击 [删除]") try: modelIndexList = self.tab2_mainFuntableView.selectionModel( ).selectedRows() if len(modelIndexList) > 0: # 考虑到移除行行索引会变,从后往前移行 for modexIndex in modelIndexList[::-1]: cindex = self.getIndexFromCaption( modexIndex.model(), self.funcShowLabel["rowId"]) idText = modexIndex.model().index(modexIndex.row(), cindex).data() self.tab2_mainFuntableView.model().removeRow( modexIndex.row()) self.xmlConf.delFunctionNode(idText) logtrace.logOut("%s %s" % (modexIndex.row(), idText), "delRow") # 重建行号 self.rebuildTableRowNum(self.tab2_mainFuntableView) else: QMessageBox.information(self, "提示信息", "未选中行数据!", QMessageBox.Ok) except Exception as e: traceback.print_exc()
def pyqtCaptureImgeSave(hwnd: int = 0, imagePath: str = None, imageName: str = None): """ pyqt5窗口截图保存方法,支持后台截图方式,窗口不能最小化. :param hwnd: 窗口句柄,0代表整个屏幕 :param imgePath: bmp图片路径 :param imageName: bmp图片文件名 :return: 图片路径字符串 """ # 窗口句柄校验 if hwnd != 0 and not win32gui.IsWindow(hwnd): raise Exception(str(hwnd) + "无效的窗口句柄。") # 图片路径校验,不存在则新建 if imagePath is None: imagePath = "./" else: if not os.path.exists(imagePath): os.mkdir(imagePath) # 图片文件名校验,不存在则生成随机名 if imageName is None: imageName = genRandomFileName("pyqt", "bmp") else: if not imageName.lower().endswith(".bmp"): raise Exception("文件扩展名无效,只支持bmp格式扩展名") # 图片完整路径拼接 imageURI = getFileAbsPath(imagePath + imageName) logtrace.logOut(imageURI) pyqtCaptureImge(hwnd).save(imageURI) return imageURI
def tab3_keySavepushButtonClick(self): """ 按键保存节点-单击. :return: """ self.statusbar.showMessage("单击 [%s]" % self.tab3_keySavepushButton.text()) try: # 存在成员属性且存在内容 if not hasattr(self, "currKeyNode"): return if len(self.currKeyNode) == 0: return keyName = self.tab3_keyNamelineEdit.text() keySelect = self.tab3_keySelectcomboBox.currentText() keyDelay = self.tab3_keyDelaylineEdit.text() keyDesc = "按键[%s] 延迟[%s]" % (keySelect, keyDelay) # 校验值 if keyName.strip() == "": QMessageBox.critical(self, "错误消息", "节点名称值无效!请重新输入!", QMessageBox.Ok) return elif keySelect.strip() == "": QMessageBox.critical(self, "错误消息", "按键值无效!请重新输入!", QMessageBox.Ok) return elif keyDelay.strip() == "": QMessageBox.critical(self, "错误消息", "延迟值无效!请重新输入!", QMessageBox.Ok) return self.currKeyNode["name"] = keyName self.currKeyNode["key"] = keySelect self.currKeyNode["delay"] = keyDelay self.currKeyNode["desc"] = keyDesc logtrace.logOut(self.currKeyNode) self.xmlConf.changeNodeNode(self.currKeyNode["rowId"], self.currKeyNode) self.refleshNodeModel() # 切换tab2显示 # self.tabWidget.setCurrentIndex(2) except Exception as e: traceback.print_exc() self.statusbar.showMessage("保存按键节点[%s]成功" % self.currKeyNode["rowId"])
def tab2_mainFunctableViewSaveMenu(self, checked=False): """ 单击菜单 - 保存. :return: """ self.statusbar.showMessage("单击 [保存]") try: modelIndexList = self.tab2_mainFuntableView.selectionModel( ).selectedRows() if len(modelIndexList) > 0: for modelIndex in modelIndexList: # 获取单元格值 - rowId rowIdIndex = self.getIndexFromCaption( modelIndex.model(), self.funcShowLabel["rowId"]) rowIdText = modelIndex.model().index( modelIndex.row(), rowIdIndex).data() # 获取单元格值 - name nameIndex = self.getIndexFromCaption( modelIndex.model(), self.funcShowLabel["name"]) nameText = modelIndex.model().index( modelIndex.row(), nameIndex).data() # 获取单元格值 - desc descIndex = self.getIndexFromCaption( modelIndex.model(), self.funcShowLabel["desc"]) descText = modelIndex.model().index( modelIndex.row(), descIndex).data() # 修改节点值 attrs = { "rowId": rowIdText, "name": nameText, "desc": descText } logtrace.logOut(attrs, "saveFunc") self.xmlConf.changeFunctionNode(rowIdText, attrs) self.refleshFunctionModel() else: QMessageBox.information(self, "提示信息", "未选中行数据!", QMessageBox.Ok) except Exception as e: traceback.print_exc()
def refleshNodeModel(self): nodeList = self.xmlConf.convertNodeToModel() logtrace.logOut("%s" % nodeList, "refleshNodeModel") # 显示列标题 if len(nodeList) > 0: model = self.tab2_nodetableView.model() # 设置行数据 model.setRowCount(len(nodeList)) for rindex, rowdata in enumerate(nodeList): model.setHeaderData(rindex, Qt.Vertical, rindex) for cindex, key in enumerate(self.nodeShowLabel.keys()): if key in rowdata: item = QStandardItem(rowdata[key]) item.setTextAlignment(Qt.AlignHCenter | Qt.AlignVCenter) else: item = QStandardItem("") model.setItem(rindex, cindex, item) else: # 清空tableview数据 model = self.tab2_nodetableView.model() model.removeRows(0, model.rowCount())
def win32CaptureImgSave(hwnd: int, imagePath: str = None, imageName: str = None): """ win32API窗口截图保存方法,支持后台截图,窗口不可最小化. :param hwnd: 窗口句柄 :param imgePath: bmp图片路径 :param imageName: bmp图片文件名 :return: 图片路径字符串 """ # 窗口句柄校验 if not win32gui.IsWindow(hwnd): raise Exception(str(hwnd) + "无效的窗口句柄。") # 图片路径校验,不存在则新建 if imagePath is None: imagePath = "./" else: if not os.path.exists(imagePath): os.mkdir(imagePath) # 图片文件名校验,不存在则生成随机名 if imageName is None: imageName = genRandomFileName("win32", "bmp") else: if not imageName.lower().endswith(".bmp"): raise Exception("文件扩展名无效,只支持bmp格式扩展名") # 图片完整路径拼接 imageURI = getFileAbsPath(imagePath + imageName) logtrace.logOut(imageURI) # 获取句柄窗口的大小信息 left, top, right, bot = win32gui.GetWindowRect(hwnd) width = right - left height = bot - top # 如果窗口处于最小化则激活窗口 # if left < 0 and right < 0 and top < 0 and bot < 0: # win32gui.SendMessage(hwnd, win32con.WM_SYSCOMMAND, win32con.SC_RESTORE, 0) # win32gui.SendMessage(hwnd, win32con.WM_SYSCOMMAND, win32con.SW_INVALIDATE, 0) # time.sleep(3) # 返回句柄窗口的设备环境,覆盖整个窗口,包括非客户区,标题栏,菜单,边框 hWndDC = win32gui.GetWindowDC(hwnd) # 创建设备描述表 mfcDC = win32ui.CreateDCFromHandle(hWndDC) # 创建内存设备描述表 saveDC = mfcDC.CreateCompatibleDC() # 创建位图对象准备保存图片 saveBitMap = win32ui.CreateBitmap() # 为bitmap开辟存储空间 saveBitMap.CreateCompatibleBitmap(mfcDC, width, height) # 将截图保存到saveBitMap中 saveDC.SelectObject(saveBitMap) # 保存bitmap到内存设备描述表 saveDC.BitBlt((0, 0), (width, height), mfcDC, (0, 0), win32con.SRCCOPY) ###保存bitmap到文件 saveBitMap.SaveBitmapFile(saveDC, imageURI) # 内存释放 win32gui.DeleteObject(saveBitMap.GetHandle()) saveDC.DeleteDC() mfcDC.DeleteDC() win32gui.ReleaseDC(hwnd, hWndDC) return imageURI