Skip to content

Commit 9a4312d

Browse files
authored
For #6747, allowed settings to be saved. (#4)
Allowed some settings to be saved and restored.
1 parent 98a28e8 commit 9a4312d

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

hooks/tk-multi-publish2/tk-maya/basic/publish_turntable.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,16 @@ class MayaUnrealTurntablePublishPlugin(HookBaseClass):
346346

347347
# NOTE: The plugin icon and name are defined by the base file plugin.
348348

349+
# List of settings to save and their save code
350+
_save_settings = (
351+
("Unreal Engine Version", "publish2.unreal_engine_version"),
352+
("Unreal Engine Path", "publish2.unreal_engine_path"),
353+
("Unreal Project Path", "publish2.turntable.unreal_project_path"),
354+
("Turntable Map Path", "publish2.turntable.map_path"),
355+
("Sequence Path", "publish2.turntable.sequence_path"),
356+
("Turntable Assets Path", "publish2.turntable.assets_path"),
357+
)
358+
349359
@property
350360
def description(self):
351361
"""
@@ -563,13 +573,60 @@ def set_ui_settings(self, widget, settings):
563573
unreal_versions,
564574
cur_settings["Unreal Engine Version"],
565575
)
576+
widget.unreal_setup_widget.unreal_engine_widget.set_path(
577+
cur_settings["Unreal Engine Path"]
578+
)
566579
widget.unreal_setup_widget.set_unreal_project_path_template(
567580
cur_settings["Unreal Project Path Template"]
568581
)
582+
widget.unreal_setup_widget.unreal_project_widget.set_path(
583+
cur_settings["Unreal Project Path"]
584+
)
569585
widget.unreal_turntable_map_widget.setText(cur_settings["Turntable Map Path"])
570586
widget.unreal_sequence_widget.setText(cur_settings["Sequence Path"])
571587
widget.unreal_turntable_asset_widget.setText(cur_settings["Turntable Assets Path"])
572588

589+
def load_saved_ui_settings(self, settings):
590+
"""
591+
Load saved settings and update the given settings dictionary with them.
592+
593+
:param settings: A dictionary where keys are settings names and
594+
values Settings instances.
595+
"""
596+
# Retrieve SG utils framework settings module and instantiate a manager
597+
fw = self.load_framework("tk-framework-shotgunutils_v5.x.x")
598+
module = fw.import_module("settings")
599+
settings_manager = module.UserSettings(self.parent)
600+
601+
# Retrieve saved settings
602+
for name, saved_name in self._save_settings:
603+
settings[name].value = settings_manager.retrieve(
604+
saved_name,
605+
settings[name].value,
606+
settings_manager.SCOPE_PROJECT,
607+
)
608+
self.logger.debug("Loaded settings %s" % settings[name])
609+
610+
def save_ui_settings(self, settings):
611+
"""
612+
Save UI settings.
613+
614+
:param settings: A dictionary of Settings instances.
615+
"""
616+
# Retrieve SG utils framework settings module and instantiate a manager
617+
fw = self.load_framework("tk-framework-shotgunutils_v5.x.x")
618+
module = fw.import_module("settings")
619+
settings_manager = module.UserSettings(self.parent)
620+
621+
# Save settings
622+
for name, saved_name in self._save_settings:
623+
value = settings[name].value
624+
settings_manager.store(
625+
saved_name,
626+
value,
627+
settings_manager.SCOPE_PROJECT
628+
)
629+
573630
def accept(self, settings, item):
574631
"""
575632
Method called by the publisher to determine if an item is of any
@@ -619,6 +676,8 @@ def accept(self, settings, item):
619676
item.context_change_allowed = False
620677
if accepted:
621678
self.logger.info("Accepting item %s" % item)
679+
self.load_saved_ui_settings(settings)
680+
622681
return {
623682
"accepted": accepted,
624683
"checked": True
@@ -755,6 +814,7 @@ def validate(self, settings, item):
755814
return False
756815
item.properties["turntable_assets_path"] = turntable_assets_path
757816

817+
self.save_ui_settings(settings)
758818
return True
759819

760820
def get_unreal_exec_property(self, settings, item):

0 commit comments

Comments
 (0)