def export_csv(self, path=None):
        if not path:
            path, _ = QFileDialog.getSaveFileName(
                self, caption=u"输出设置", filter=u"csv (*.csv)"
            )
            if not path:
                return

        csv = ""
        row_count = self.model.rowCount()
        column_count = self.model.columnCount()
        for i in range(row_count):
            col_list = [
                self.model.itemData(self.model.index(i, j))[0]
                for j in range(column_count)
            ]
            csv += ",".join(col_list) + "\n"

        with open(path, "w", encoding="gbk") as f:
            f.write(csv)

        # NOTE 打开输出的路径
        subprocess.Popen(
            ["start", "", os.path.dirname(path)], creationflags=0x08000000, shell=True
        )
    def exportJsonSetting(self, path=None):
        """
        exportJsonSetting 导出Json
        
        Keyword Arguments:
            path {str} -- 导出路径 为空则弹出选择窗口获取 (default: {None})
        """
        if not path:
            path, _ = QFileDialog.getSaveFileName(self,
                                                  caption=u"输出设置",
                                                  filter=u"json (*.json)")
            if not path: return

        self.setting_data["Horizontal_RB"] = self.Horizontal_RB.isChecked()
        self.setting_data["Maya_RB"] = self.Maya_RB.isChecked()
        self.setting_data["Crop_CB"] = self.Crop_CB.isChecked()
        self.setting_data["Limit_CB"] = self.Limit_CB.isChecked()
        self.setting_data["Width_SP"] = self.Width_SP.value()
        self.setting_data["Height_SP"] = self.Height_SP.value()
        self.setting_data["Fit_SP"] = self.Fit_SP.value()

        try:
            with open(path, 'w') as f:
                json.dump(self.setting_data, f, indent=4)
        except:
            QtWidgets.QMessageBox.warning(self, "Warning", "保存失败")
Example #3
0
 def export_setting(self):
     path, _ = QFileDialog.getSaveFileName(self,
                                           caption=u"输出设置",
                                           filter=u"ini (*.ini)")
     if not path:
         return
     copyfile(self.settings.fileName(), path)
     toast(u"导出成功", "info")
    def exportJsonSetting(self):
        """
        exportJsonSetting 导出 Json 设置
        """
        path, _ = QFileDialog.getSaveFileName(self,
                                              caption=u"输出摄像机设置",
                                              filter=u"json (*.json)")
        if not path: return

        try:
            with open(path, 'w') as f:
                json.dump(self.camera_setting, f, indent=4)
        except:
            QtWidgets.QMessageBox.warning(self, "Warning", "保存失败")
Example #5
0
    def exportJsonSetting(self, path=None):
        """
        exportJsonSetting 导出Json
        
        Keyword Arguments:
            path {str} -- 导出路径 为空则弹出选择窗口获取 (default: {None})
        """
        if not path:
            path, _ = QFileDialog.getSaveFileName(self,
                                                  caption=u"输出设置",
                                                  filter=u"json (*.json)")
            if not path: return

        with open(path, 'w') as f:
            json.dump(self.setting, f, indent=4)
Example #6
0
    def capture(self):
        """
        capture 截取图片输出
        """
        file_path, _ = QFileDialog.getSaveFileName(
            self, caption=u"获取输出图片路径", filter=u"png (*.png);;jpg (*.jpg)")

        # NOTE 判断是否是空路径
        if not file_path:
            return

        # NOTE 获取当前激活的面板 (modelPanel4)
        for panel in pm.getPanel(type="modelPanel"):
            if pm.modelEditor(panel, q=1, av=1):
                active_cam = pm.modelEditor(panel, q=1, camera=1)
                active_panel = panel
                break

        # NOTE 获取当前 HUD 相关的显示状态
        display_1 = pm.modelEditor(active_panel, q=1, hud=1)
        display_2 = pm.modelEditor(active_panel, q=1, grid=1)
        display_3 = pm.modelEditor(active_panel, q=1, m=1)
        display_4 = pm.modelEditor(active_panel, q=1, hos=1)
        display_5 = pm.modelEditor(active_panel, q=1, sel=1)

        # NOTE 隐藏界面显示
        pm.modelEditor(active_panel, e=1, hud=0)
        pm.modelEditor(active_panel, e=1, grid=0)
        pm.modelEditor(active_panel, e=1, m=0)
        pm.modelEditor(active_panel, e=1, hos=0)
        pm.modelEditor(active_panel, e=1, sel=0)

        # NOTE 触发截屏处理
        self.cam_setting = self.manager.cam_setting
        self.setting = self.manager.setting
        # NOTE 根据设置窗口的选项 获取图片处理的API
        API = self.setting.Maya_RB.isChecked()
        if API:
            self.util = MayaImageUtil()
        else:
            self.util = QtImageUtil()

        # NOTE 创建临时摄像机组
        self.cam_setting.showProcess()

        # NOTE 获取摄像机截取的画面
        img_list = []
        for cam in self.cam_setting.camera_setting:
            pm.lookThru(cam)
            img = self.captureImage()
            if img: img_list.append(img)

        # Note 合并图片
        img = self.util.mergeImage(
            img_list, horizontal=self.setting.Horizontal_RB.isChecked())

        ext = os.path.splitext(file_path)[-1][1:]
        # Note 不同API的输出指令不一样进行区分
        if API:
            img.writeToFile(file_path, ext)
        else:
            img.save(file_path, format=ext)

        # NOTE 恢复HUD显示
        pm.modelEditor(active_panel, e=1, hud=display_1)
        pm.modelEditor(active_panel, e=1, grid=display_2)
        pm.modelEditor(active_panel, e=1, m=display_3)
        pm.modelEditor(active_panel, e=1, hos=display_4)
        pm.modelEditor(active_panel, e=1, sel=display_5)

        # NOTE 恢复之前的摄像机视角并删除临时的摄像机组
        pm.lookThru(active_cam)
        pm.delete(self.cam_setting.grp)

        # NOTE 输出成功信息
        QtWidgets.QMessageBox.information(self, u"输出完成",
                                          u"图片输出成功\n输出路径:%s" % file_path)