Skip to content

Commit

Permalink
Merge pull request #395 from MonsieurGallo/rig_builder_updates
Browse files Browse the repository at this point in the history
Rig builder updates
  • Loading branch information
miquelcampos committed Mar 20, 2024
2 parents 527c137 + d156257 commit fdd28db
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 18 deletions.
30 changes: 29 additions & 1 deletion release/scripts/mgear/shifter/rig_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,14 @@ def execute_build_logic(self, json_data, validate=True, passed_only=False):
output_folder = data.get("output_folder")
if not output_folder:
output_folder = os.path.dirname(file_path)

custom_output_path = row.get("custom_output_path")

# if row has a custom path, override output folder with custom path
if custom_output_path:
print(f"custom output{custom_output_path}")
output_folder = custom_output_path


output_name = row.get("output_name")
maya_file_name = "{}.ma".format(output_name)
Expand All @@ -140,7 +148,7 @@ def execute_build_logic(self, json_data, validate=True, passed_only=False):
if guide_root:
guide_root = guide_root[0]
pm.displayInfo(
"Updating the guide with: {}".format(pre_script_path)
"Updating the guide with pre-script: {}".format(pre_script_path)
)
with open(pre_script_path, "r") as file:
try:
Expand All @@ -166,6 +174,26 @@ def execute_build_logic(self, json_data, validate=True, passed_only=False):
pm.displayInfo("Building rig '{}'...".format(output_name))
io.build_from_file(file_path)

post_script_path = data.get("post_script")

if post_script_path:
pm.displayInfo(
"Updating the guide with post-script: {}".format(post_script_path)
)
with open(post_script_path, "r") as file:
try:
exec(file.read())
except Exception as e:
error_message = str(e)
full_traceback = traceback.format_exc()
pm.displayWarning(
"Update script failed, check error log"
)
pm.displayError(
"Exception message:", error_message
)
pm.displayError("Full traceback:", full_traceback)

context = None
save_build = True
report_string = self.format_report_header()
Expand Down
69 changes: 52 additions & 17 deletions release/scripts/mgear/shifter/rig_builder/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self):
self.setWindowTitle("mGear Rig Builder")
self.setMinimumWidth(400)
self.setAcceptDrops(True)
self.resize(550, 650)
self.resize(900, 650)

self.builder = builder.RigBuilder()
self.create_actions()
Expand Down Expand Up @@ -90,9 +90,9 @@ def create_layout(self):

# File Table UI
self.table_widget = QtWidgets.QTableWidget()
self.table_widget.setColumnCount(2)
self.table_widget.setColumnCount(4)
self.table_widget.setHorizontalHeaderLabels(
[".sgt File", "Output Name"]
[".sgt File", "Output Name", "Custom Output Path", " "]
)

self.table_widget.setEditTriggers(
Expand All @@ -106,6 +106,14 @@ def create_layout(self):
self.table_widget.horizontalHeader().setSectionResizeMode(
1, QtWidgets.QHeaderView.Stretch
)
self.table_widget.horizontalHeader().setSectionResizeMode(
2, QtWidgets.QHeaderView.ResizeToContents
)
self.table_widget.horizontalHeader().setSectionResizeMode(
3, QtWidgets.QHeaderView.ResizeToContents
)



self.layout.addWidget(self.table_widget)

Expand All @@ -123,17 +131,17 @@ def create_layout(self):
pre_script_layout.addWidget(self.pre_script_button)

# Post-scrtip
# post_script_layout = QtWidgets.QHBoxLayout()
# self.layout.addLayout(post_script_layout)
post_script_layout = QtWidgets.QHBoxLayout()
self.layout.addLayout(post_script_layout)

# self.post_script_line_edit = QtWidgets.QLineEdit()
# self.post_script_button = widgets.create_button(
# icon="mgear_folder", width=25
# )
self.post_script_line_edit = QtWidgets.QLineEdit()
self.post_script_button = widgets.create_button(
icon="mgear_folder", width=25
)

# post_script_layout.addWidget(QtWidgets.QLabel("Post Script"))
# post_script_layout.addWidget(self.post_script_line_edit)
# post_script_layout.addWidget(self.post_script_button)
post_script_layout.addWidget(QtWidgets.QLabel("Post Script"))
post_script_layout.addWidget(self.post_script_line_edit)
post_script_layout.addWidget(self.post_script_button)

# Add, Remove, and Build buttons
self.add_button = QtWidgets.QPushButton("Add")
Expand Down Expand Up @@ -161,7 +169,7 @@ def create_connections(self):
self.build_button.clicked.connect(self.on_build_button_clicked)

self.pre_script_button.clicked.connect(self.set_pre_script)
# self.post_script_button.clicked.connect(self.set_post_script)
self.post_script_button.clicked.connect(self.set_post_script)

def set_script(self, lineEdit):
"""Sets the output folder for exported builds."""
Expand All @@ -176,8 +184,8 @@ def set_script(self, lineEdit):
def set_pre_script(self):
self.set_script(self.pre_script_line_edit)

# def set_post_script(self):
# self.set_script(self.post_script_line_edit)
def set_post_script(self):
self.set_script(self.post_script_line_edit)

def on_output_folder_clicked(self):
"""Sets the output folder for exported builds."""
Expand Down Expand Up @@ -241,20 +249,22 @@ def collect_table_data(self):
row_count = self.table_widget.rowCount()
data["output_folder"] = self.output_folder_line_edit.text().strip()
data["pre_script"] = self.pre_script_line_edit.text().strip()
# data["post_script"] = self.post_script_line_edit.text().strip()
data["post_script"] = self.post_script_line_edit.text().strip()
data["rows"] = []

for i in range(row_count):
file_path_item = self.table_widget.item(i, 0)
output_name_item = self.table_widget.item(i, 1)
custom_output_path_item = self.table_widget.item(i, 2)

file_path = file_path_item.text().strip() if file_path_item else ""
output_name = (
output_name_item.text().strip() if output_name_item else ""
)
custom_output_path = custom_output_path_item.text().strip() if custom_output_path_item else ""

data["rows"].append(
{"file_path": file_path, "output_name": output_name}
{"file_path": file_path, "output_name": output_name, "custom_output_path":custom_output_path}
)

return json.dumps(data, indent=4)
Expand All @@ -277,6 +287,13 @@ def add_file(self, file_path):
output_item = QtWidgets.QTableWidgetItem(output_name)
self.table_widget.setItem(row_position, 1, output_item)

custom_output_path = QtWidgets.QTableWidgetItem("")
self.table_widget.setItem(row_position, 2, custom_output_path)

set_custom_output_bttn = widgets.create_button(icon="mgear_folder", width=40, size=45)
self.table_widget.setCellWidget(row_position, 3, set_custom_output_bttn)
set_custom_output_bttn.clicked.connect(partial(self.on_custom_path_clicked, custom_output_path))

def create_results_popup(self, results_dict):
"""Launches a pop-up containing validator results.
Expand Down Expand Up @@ -307,6 +324,7 @@ def import_config(self, file_path=""):

self.output_folder_line_edit.setText(data["output_folder"])
self.pre_script_line_edit.setText(data["pre_script"])
self.post_script_line_edit.setText(data["post_script"])

self.table_widget.clearContents()
data_rows = data["rows"]
Expand All @@ -323,10 +341,27 @@ def import_config(self, file_path=""):
output_item = QtWidgets.QTableWidgetItem(output_name)
self.table_widget.setItem(row_position, 1, output_item)

custom_output_path = row["custom_output_path"]
custom_output_path_item = QtWidgets.QTableWidgetItem(custom_output_path)
self.table_widget.setItem(row_position, 2, custom_output_path_item)

set_custom_output_bttn = widgets.create_button(icon="mgear_folder", width=40, size=45)
self.table_widget.setCellWidget(row_position, 3, set_custom_output_bttn)
set_custom_output_bttn.clicked.connect(partial(self.on_custom_path_clicked, custom_output_path))

def export_config(self):
data_string = self.collect_table_data()
builder.RigBuilder.write_config_data_to_file(data_string)

def on_custom_path_clicked(self, custom_path_widget):
"""Sets the output folder for exported builds."""
folder_path = QtWidgets.QFileDialog.getExistingDirectory(
self, "Select Output Folder"
)
if folder_path:
custom_path_widget.setText(folder_path)



class ResultsPopupDialog(QtWidgets.QDialog):
"""
Expand Down

0 comments on commit fdd28db

Please sign in to comment.