From d9afaad23bb6fdb1fe848a65da5ce7e4f8cd8874 Mon Sep 17 00:00:00 2001 From: Oscar Juarez Date: Fri, 15 Feb 2019 13:44:38 +0100 Subject: [PATCH 1/6] Shelf tools get added to Houdini Tab Menu --- python/tk_houdini/ui_generation.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/python/tk_houdini/ui_generation.py b/python/tk_houdini/ui_generation.py index d4d911b..e7e054e 100644 --- a/python/tk_houdini/ui_generation.py +++ b/python/tk_houdini/ui_generation.py @@ -544,19 +544,22 @@ def create_shelf(self, shelf_file): # add the context menu tools first for cmd in context_cmds: - tool = self.create_tool(shelf_file, cmd) + tool = self.create_tool(shelf_file, cmd, "/Current Context") shelf_tools.append(tool) # now add the favourites for cmd in favourite_cmds: - tool = self.create_tool(shelf_file, cmd) + tool = self.create_tool(shelf_file, cmd, "/Favourites") shelf_tools.append(tool) # create tools for the remaining commands for app_name in sorted(cmds_by_app.keys()): for cmd in cmds_by_app[app_name]: if not cmd.favourite: - tool = self.create_tool(shelf_file, cmd) + submenu = "" + if (len(cmds_by_app[app_name])) > 1: + submenu = "/" + app_name + tool = self.create_tool(shelf_file, cmd, submenu) shelf_tools.append(tool) shelf.setTools(shelf_tools) @@ -566,7 +569,7 @@ def create_shelf(self, shelf_file): # sesi to see what they recommend. If there is a way, this is probably # where the shelf would need to be added. - def create_tool(self, shelf_file, cmd): + def create_tool(self, shelf_file, cmd, submenu=""): """Create a new shelf tool. cmd: @@ -586,7 +589,11 @@ def create_tool(self, shelf_file, cmd): script=_g_launch_script % cmd.get_id(), #help=cmd.get_description(), #help_url=cmd.get_documentation_url_str(), - icon=cmd.get_icon() + icon=cmd.get_icon(), + viewer_categories=[hou.nodeTypeCategories()["Object"], + hou.nodeTypeCategories()["Sop"], + hou.nodeTypeCategories()["Dop"]], + locations=["Shotgun%s" % submenu] ) # NOTE: there seems to be a bug in houdini where the 'help' does # not display in the tool's tooltip even though the tool's help From 18d08adc0405b1085e5b5ac701788e023fa05f84 Mon Sep 17 00:00:00 2001 From: Oscar Juarez Date: Fri, 15 Feb 2019 16:58:23 +0100 Subject: [PATCH 2/6] Shotgun appears in TAB menu in all contexts Favorites also get added to their corresponding app submenu --- python/tk_houdini/ui_generation.py | 32 +++++++++++++++++------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/python/tk_houdini/ui_generation.py b/python/tk_houdini/ui_generation.py index e7e054e..b74c760 100644 --- a/python/tk_houdini/ui_generation.py +++ b/python/tk_houdini/ui_generation.py @@ -541,27 +541,27 @@ def create_shelf(self, shelf_file): cmds_by_app = {} (context_cmds, cmds_by_app, favourite_cmds) = self._group_commands() - # add the context menu tools first for cmd in context_cmds: - tool = self.create_tool(shelf_file, cmd, "/Current Context") + tool = self.create_tool(shelf_file, cmd, ["/Current Context"]) shelf_tools.append(tool) # now add the favourites for cmd in favourite_cmds: - tool = self.create_tool(shelf_file, cmd, "/Favourites") + app_name = cmd.properties["app"].display_name + tool = self.create_tool(shelf_file, cmd, ["/Favourites", "/" + app_name]) shelf_tools.append(tool) # create tools for the remaining commands for app_name in sorted(cmds_by_app.keys()): for cmd in cmds_by_app[app_name]: + submenu = "" + if (len(cmds_by_app[app_name])) > 1: + submenu = "/" + app_name if not cmd.favourite: - submenu = "" - if (len(cmds_by_app[app_name])) > 1: - submenu = "/" + app_name - tool = self.create_tool(shelf_file, cmd, submenu) + tool = self.create_tool(shelf_file, cmd, [submenu]) shelf_tools.append(tool) - + shelf.setTools(shelf_tools) # TODO: Currently there doesn't appear to be a way to add the sg shelf @@ -569,7 +569,7 @@ def create_shelf(self, shelf_file): # sesi to see what they recommend. If there is a way, this is probably # where the shelf would need to be added. - def create_tool(self, shelf_file, cmd, submenu=""): + def create_tool(self, shelf_file, cmd, submenu=[]): """Create a new shelf tool. cmd: @@ -578,9 +578,12 @@ def create_tool(self, shelf_file, cmd, submenu=""): shelf_file: The shelf file to write the tool definition to. """ - + import hou + viewer_categories = ["Object", "Sop", "Chop"] + network_categories = ["Object", "Sop", "Chop", "Driver", "Shop", "Cop2", "Vop", "VopNet", "Dop"] + self._engine.logger.debug("Creating tool: %s" % cmd.name) tool = hou.shelves.newTool( file_path=shelf_file, @@ -590,10 +593,11 @@ def create_tool(self, shelf_file, cmd, submenu=""): #help=cmd.get_description(), #help_url=cmd.get_documentation_url_str(), icon=cmd.get_icon(), - viewer_categories=[hou.nodeTypeCategories()["Object"], - hou.nodeTypeCategories()["Sop"], - hou.nodeTypeCategories()["Dop"]], - locations=["Shotgun%s" % submenu] + viewer_categories=[hou.nodeTypeCategories()[cat] for cat in hou.nodeTypeCategories().keys() + if cat in viewer_categories], + network_categories=[hou.nodeTypeCategories()[cat] for cat in hou.nodeTypeCategories().keys() + if cat in network_categories], + locations=map(lambda x : "Shotgun" + x, submenu) ) # NOTE: there seems to be a bug in houdini where the 'help' does # not display in the tool's tooltip even though the tool's help From 1957c4cc5f2879737b44aae3bd47a59c094bbd2e Mon Sep 17 00:00:00 2001 From: Oscar Juarez Date: Mon, 18 Feb 2019 11:11:38 +0100 Subject: [PATCH 3/6] If there is a group property in the cmd, use it for the Tab menu --- python/tk_houdini/ui_generation.py | 34 ++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/python/tk_houdini/ui_generation.py b/python/tk_houdini/ui_generation.py index b74c760..124c6c2 100644 --- a/python/tk_houdini/ui_generation.py +++ b/python/tk_houdini/ui_generation.py @@ -69,6 +69,7 @@ def _group_commands(self): favourite_cmds = [] context_cmds = [] cmds_by_app = {} + cmds_by_grp = {} # favourites for fav in self._engine.get_setting("menu_favourites"): @@ -96,8 +97,13 @@ def _group_commands(self): app_name = "Other Items" cmds_by_app.setdefault(app_name, []).append(cmd) + grp_name = cmd.get_app_grp() + if grp_name: + cmd.grouped = True + cmds_by_grp.setdefault(grp_name, []).append(cmd) + self._engine.logger.debug("Grouped registered commands.") - self._grouped_commands = (context_cmds, cmds_by_app, favourite_cmds) + self._grouped_commands = (context_cmds, cmds_by_app, favourite_cmds, cmds_by_grp) return self._grouped_commands @@ -540,7 +546,7 @@ def create_shelf(self, shelf_file): shelf_tools = [] cmds_by_app = {} - (context_cmds, cmds_by_app, favourite_cmds) = self._group_commands() + (context_cmds, cmds_by_app, favourite_cmds, cmds_by_grp) = self._group_commands() # add the context menu tools first for cmd in context_cmds: tool = self.create_tool(shelf_file, cmd, ["/Current Context"]) @@ -548,17 +554,25 @@ def create_shelf(self, shelf_file): # now add the favourites for cmd in favourite_cmds: - app_name = cmd.properties["app"].display_name + app_name = cmd.get_app_name() tool = self.create_tool(shelf_file, cmd, ["/Favourites", "/" + app_name]) shelf_tools.append(tool) + # create tools for grouped apps + for grp_name in sorted(cmds_by_grp.keys()): + for cmd in cmds_by_grp[grp_name]: + grp_name = cmd.get_app_grp() + tool = self.create_tool(shelf_file, cmd, ["/" + grp_name]) + shelf_tools.append(tool) + # create tools for the remaining commands for app_name in sorted(cmds_by_app.keys()): + # if the app register several commands, group them in the tab menu + submenu = "" + if (len(cmds_by_app[app_name])) > 1: + submenu = "/" + app_name for cmd in cmds_by_app[app_name]: - submenu = "" - if (len(cmds_by_app[app_name])) > 1: - submenu = "/" + app_name - if not cmd.favourite: + if not cmd.favourite and not cmd.grouped: tool = self.create_tool(shelf_file, cmd, [submenu]) shelf_tools.append(tool) @@ -651,6 +665,7 @@ def __init__(self, name, command_dict): self.properties = command_dict["properties"] self.callback = command_dict["callback"] self.favourite = False + self.grouped = False def get_app_name(self): if "app" in self.properties: @@ -670,6 +685,11 @@ def get_app_instance_name(self): return None + def get_app_grp(self): + if "group" in self.properties: + return self.properties["group"] + return None + def get_description(self): if "description" in self.properties: return self.properties["description"] From 06dbb87d772aca179d4d0f0df8c5cf37b238f609 Mon Sep 17 00:00:00 2001 From: Oscar Juarez Date: Mon, 18 Feb 2019 11:50:17 +0100 Subject: [PATCH 4/6] Remove whitespace --- python/tk_houdini/ui_generation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/tk_houdini/ui_generation.py b/python/tk_houdini/ui_generation.py index 124c6c2..8187dca 100644 --- a/python/tk_houdini/ui_generation.py +++ b/python/tk_houdini/ui_generation.py @@ -575,7 +575,7 @@ def create_shelf(self, shelf_file): if not cmd.favourite and not cmd.grouped: tool = self.create_tool(shelf_file, cmd, [submenu]) shelf_tools.append(tool) - + shelf.setTools(shelf_tools) # TODO: Currently there doesn't appear to be a way to add the sg shelf @@ -592,7 +592,7 @@ def create_tool(self, shelf_file, cmd, submenu=[]): shelf_file: The shelf file to write the tool definition to. """ - + import hou viewer_categories = ["Object", "Sop", "Chop"] From 1e7226976cb4ae0c84e9040b68d8634ebaa503bc Mon Sep 17 00:00:00 2001 From: Oscar Juarez Date: Wed, 27 Feb 2019 10:18:50 +0100 Subject: [PATCH 5/6] Fix bug in Shotgun menu generation which would not unpack all grouped commands. --- python/tk_houdini/ui_generation.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/tk_houdini/ui_generation.py b/python/tk_houdini/ui_generation.py index 8187dca..9b20518 100644 --- a/python/tk_houdini/ui_generation.py +++ b/python/tk_houdini/ui_generation.py @@ -152,7 +152,7 @@ def _get_context_commands(self): if not hasattr(self, '_context_commands'): # get the registered commands, grouped in the usual way. - (context_cmds, cmds_by_app, favourite_cmds) = self._group_commands() + (context_cmds, cmds_by_app, favourite_cmds, cmds_by_grp) = self._group_commands() # ideally we'd mimic the static menu and have a context item # that contained a submenu with context-specific commands. this @@ -200,7 +200,7 @@ def _get_commands_by_app(self): # the dynamic menu is rebuilt on each click. if not hasattr(self, '_commands_by_app'): - (context_cmds, cmds_by_app, favourite_cmds) = self._group_commands() + (context_cmds, cmds_by_app, favourite_cmds, cmds_by_grp) = self._group_commands() cmds = favourite_cmds @@ -320,7 +320,7 @@ def _create_static_menu(self, xml_path): ctx_menu = self._menuNode(shotgun_menu, ctx_name, "tk.context") ET.SubElement(ctx_menu, "separatorItem") - (context_cmds, cmds_by_app, favourite_cmds) = self._group_commands() + (context_cmds, cmds_by_app, favourite_cmds, cmds_by_grp) = self._group_commands() # favourites ET.SubElement(shotgun_menu, "separatorItem") From 28f081c37990f3de74b1497c376b3841d7f7aba2 Mon Sep 17 00:00:00 2001 From: Oscar Juarez Date: Wed, 27 Feb 2019 10:20:11 +0100 Subject: [PATCH 6/6] Remove whitespace in line 614 --- python/tk_houdini/ui_generation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/python/tk_houdini/ui_generation.py b/python/tk_houdini/ui_generation.py index 9b20518..bd64808 100644 --- a/python/tk_houdini/ui_generation.py +++ b/python/tk_houdini/ui_generation.py @@ -611,7 +611,7 @@ def create_tool(self, shelf_file, cmd, submenu=[]): if cat in viewer_categories], network_categories=[hou.nodeTypeCategories()[cat] for cat in hou.nodeTypeCategories().keys() if cat in network_categories], - locations=map(lambda x : "Shotgun" + x, submenu) + locations=map(lambda x: "Shotgun" + x, submenu) ) # NOTE: there seems to be a bug in houdini where the 'help' does # not display in the tool's tooltip even though the tool's help