Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rig builder io, Issue #388 #389

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion release/scripts/mgear/shifter/rig_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -188,3 +188,32 @@ def execute_build_logic(self, json_data, validate=True, passed_only=False):
pm.displayInfo(report_string)

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):
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=""):
if not file_path:
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
49 changes: 48 additions & 1 deletion release/scripts/mgear/shifter/rig_builder/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -23,14 +25,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)
Expand Down Expand Up @@ -131,6 +146,10 @@ def create_layout(self):

def create_connections(self):
"""Connects buttons to their functions."""

self.import_action.triggered.connect(partial(self.import_config, ""))
self.export_action.triggered.connect(self.export_config)

self.output_folder_button.clicked.connect(
self.on_output_folder_clicked
)
Expand Down Expand Up @@ -238,7 +257,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.
Expand Down Expand Up @@ -278,6 +297,34 @@ 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, 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"])

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):
data_string = self.collect_table_data()
builder.RigBuilder.write_config_data_to_file(data_string)


class ResultsPopupDialog(QtWidgets.QDialog):
Expand Down
Loading