From b85ab99e6eb711d730fb83fdd2c2e7b2bbdfa731 Mon Sep 17 00:00:00 2001 From: Cesar Gallo Date: Tue, 20 Feb 2024 13:22:39 -0600 Subject: [PATCH 1/4] Adds import and export actions to rigbuilder ui --- .../scripts/mgear/shifter/rig_builder/ui.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/release/scripts/mgear/shifter/rig_builder/ui.py b/release/scripts/mgear/shifter/rig_builder/ui.py index 5c4e9aea..2f7aa268 100644 --- a/release/scripts/mgear/shifter/rig_builder/ui.py +++ b/release/scripts/mgear/shifter/rig_builder/ui.py @@ -23,14 +23,27 @@ def __init__(self): self.resize(550, 650) self.builder = builder.RigBuilder() + self.create_actions() self.create_layout() self.create_connections() + def create_actions(self): + self.import_action = QtWidgets.QAction("Import Config") + self.export_action = QtWidgets.QAction("Export Config") + def create_layout(self): """Creates the main layout widgets of the tool.""" + + self.menu_bar = QtWidgets.QMenuBar() + self.file_menu = self.menu_bar.addMenu("File") + self.file_menu.addAction(self.import_action) + self.file_menu.addAction(self.export_action) + self.layout = QtWidgets.QVBoxLayout() self.setLayout(self.layout) + self.layout.setMenuBar(self.menu_bar) + # Output Folder UI output_folder_layout = QtWidgets.QHBoxLayout() self.layout.addLayout(output_folder_layout) @@ -131,6 +144,10 @@ def create_layout(self): def create_connections(self): """Connects buttons to their functions.""" + + self.import_action.triggered.connect(self.import_config) + self.export_action.triggered.connect(self.export_config) + self.output_folder_button.clicked.connect( self.on_output_folder_clicked ) @@ -279,6 +296,12 @@ def dropEvent(self, e): if file_path.lower().endswith(".sgt"): self.add_file(file_path) + def import_config(self): + print("Calling import config") + + def export_config(self): + print("Calling export config") + class ResultsPopupDialog(QtWidgets.QDialog): """ From da24b28a9ae68579c62827365dca016ebfad2853 Mon Sep 17 00:00:00 2001 From: Cesar Gallo Date: Tue, 20 Feb 2024 15:00:29 -0600 Subject: [PATCH 2/4] Adds import/export functionality --- .../mgear/shifter/rig_builder/builder.py | 23 ++++++++++++++++++ .../scripts/mgear/shifter/rig_builder/ui.py | 24 ++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/release/scripts/mgear/shifter/rig_builder/builder.py b/release/scripts/mgear/shifter/rig_builder/builder.py index 171c9b31..f8564a6a 100644 --- a/release/scripts/mgear/shifter/rig_builder/builder.py +++ b/release/scripts/mgear/shifter/rig_builder/builder.py @@ -188,3 +188,26 @@ def execute_build_logic(self, json_data, validate=True, passed_only=False): pm.displayInfo(report_string) return self.results_dict + + @classmethod + def write_config_data_to_file(cls, data_string): + print("Writing data to file") + file_path = pm.fileDialog2(fileMode=0, fileFilter="*.srb")[0] + if not file_path: + return + + with open(file_path, "w") as fp: + fp.write(data_string) + + + @classmethod + def load_config_data_from_file(cls): + file_path = pm.fileDialog2(fileMode=1, fileFilter="*.srb")[0] + if not file_path: + return + + data = "" + with open(file_path, "r") as fp: + data = json.load(fp) + + return data \ No newline at end of file diff --git a/release/scripts/mgear/shifter/rig_builder/ui.py b/release/scripts/mgear/shifter/rig_builder/ui.py index 2f7aa268..692c8f06 100644 --- a/release/scripts/mgear/shifter/rig_builder/ui.py +++ b/release/scripts/mgear/shifter/rig_builder/ui.py @@ -255,7 +255,7 @@ def collect_table_data(self): {"file_path": file_path, "output_name": output_name} ) - return json.dumps(data) + return json.dumps(data, indent=4) def add_file(self, file_path): """Adds a .sgt file to the main table. @@ -298,9 +298,31 @@ def dropEvent(self, e): def import_config(self): print("Calling import config") + data = builder.RigBuilder.load_config_data_from_file() + + self.output_folder_line_edit.setText(data["output_folder"]) + self.pre_script_line_edit.setText(data["pre_script"]) + + self.table_widget.clearContents() + data_rows = data["rows"] + + for row in data_rows: + row_position = self.table_widget.rowCount() + self.table_widget.insertRow(row_position) + + file_item = QtWidgets.QTableWidgetItem(row["file_path"]) + self.table_widget.setItem(row_position, 0, file_item) + + # For Output Name + output_name = row["output_name"] + output_item = QtWidgets.QTableWidgetItem(output_name) + self.table_widget.setItem(row_position, 1, output_item) + def export_config(self): print("Calling export config") + data_string = self.collect_table_data() + builder.RigBuilder.write_config_data_to_file(data_string) class ResultsPopupDialog(QtWidgets.QDialog): From ecf1df48df27e9e007c84728d05d4063a8db4378 Mon Sep 17 00:00:00 2001 From: Cesar Gallo Date: Tue, 20 Feb 2024 15:24:27 -0600 Subject: [PATCH 3/4] adds build_from_file function --- .../scripts/mgear/shifter/rig_builder/builder.py | 14 ++++++++++---- release/scripts/mgear/shifter/rig_builder/ui.py | 2 -- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/release/scripts/mgear/shifter/rig_builder/builder.py b/release/scripts/mgear/shifter/rig_builder/builder.py index f8564a6a..89d661ca 100644 --- a/release/scripts/mgear/shifter/rig_builder/builder.py +++ b/release/scripts/mgear/shifter/rig_builder/builder.py @@ -111,7 +111,7 @@ def execute_build_logic(self, json_data, validate=True, passed_only=False): validate (bool): Option to run Pyblish validators passed_only (bool): Option to publish only rigs that pass validation """ - data = json.loads(json_data) + data = json_data data_rows = data.get("rows") if not data_rows: @@ -189,9 +189,13 @@ def execute_build_logic(self, json_data, validate=True, passed_only=False): return self.results_dict + def build_from_file(self, file_path): + json_data = self.load_config_data_from_file(file_path) + self.execute_build_logic(json_data) + + @classmethod def write_config_data_to_file(cls, data_string): - print("Writing data to file") file_path = pm.fileDialog2(fileMode=0, fileFilter="*.srb")[0] if not file_path: return @@ -201,8 +205,10 @@ def write_config_data_to_file(cls, data_string): @classmethod - def load_config_data_from_file(cls): - file_path = pm.fileDialog2(fileMode=1, fileFilter="*.srb")[0] + def load_config_data_from_file(cls, file_path=""): + if not file_path: + file_path = pm.fileDialog2(fileMode=1, fileFilter="*.srb")[0] + if not file_path: return diff --git a/release/scripts/mgear/shifter/rig_builder/ui.py b/release/scripts/mgear/shifter/rig_builder/ui.py index 692c8f06..12d2f515 100644 --- a/release/scripts/mgear/shifter/rig_builder/ui.py +++ b/release/scripts/mgear/shifter/rig_builder/ui.py @@ -297,7 +297,6 @@ def dropEvent(self, e): self.add_file(file_path) def import_config(self): - print("Calling import config") data = builder.RigBuilder.load_config_data_from_file() self.output_folder_line_edit.setText(data["output_folder"]) @@ -320,7 +319,6 @@ def import_config(self): def export_config(self): - print("Calling export config") data_string = self.collect_table_data() builder.RigBuilder.write_config_data_to_file(data_string) From 87233a4f6864dda69458316cab058ca5e6ade046 Mon Sep 17 00:00:00 2001 From: Cesar Gallo Date: Tue, 20 Feb 2024 15:42:43 -0600 Subject: [PATCH 4/4] Adds drag n drop functionality for srb files --- release/scripts/mgear/shifter/rig_builder/ui.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/release/scripts/mgear/shifter/rig_builder/ui.py b/release/scripts/mgear/shifter/rig_builder/ui.py index 12d2f515..995bbb38 100644 --- a/release/scripts/mgear/shifter/rig_builder/ui.py +++ b/release/scripts/mgear/shifter/rig_builder/ui.py @@ -7,6 +7,8 @@ from mgear.core import pyqt, widgets from mgear.shifter.rig_builder import builder +from functools import partial + class RigBuilderUI( MayaQWidgetDockableMixin, QtWidgets.QDialog, pyqt.SettingsMixin @@ -145,7 +147,7 @@ def create_layout(self): def create_connections(self): """Connects buttons to their functions.""" - self.import_action.triggered.connect(self.import_config) + self.import_action.triggered.connect(partial(self.import_config, "")) self.export_action.triggered.connect(self.export_config) self.output_folder_button.clicked.connect( @@ -295,9 +297,11 @@ def dropEvent(self, e): file_path = str(url.toLocalFile()) if file_path.lower().endswith(".sgt"): self.add_file(file_path) + if file_path.lower().endswith(".srb"): + self.import_config(file_path=file_path) - def import_config(self): - data = builder.RigBuilder.load_config_data_from_file() + def import_config(self, file_path=""): + data = builder.RigBuilder.load_config_data_from_file(file_path=file_path) self.output_folder_line_edit.setText(data["output_folder"]) self.pre_script_line_edit.setText(data["pre_script"])