Skip to content
Open
Changes from 4 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
49 changes: 40 additions & 9 deletions python/tk_houdini/ui_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -540,23 +546,34 @@ 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)
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)
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]:
if not cmd.favourite:
tool = self.create_tool(shelf_file, cmd)
if not cmd.favourite and not cmd.grouped:
tool = self.create_tool(shelf_file, cmd, [submenu])
shelf_tools.append(tool)

shelf.setTools(shelf_tools)
Expand All @@ -566,7 +583,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:
Expand All @@ -578,6 +595,9 @@ def create_tool(self, shelf_file, cmd):

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,
Expand All @@ -586,7 +606,12 @@ 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()[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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace before ':'

)
# 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
Expand Down Expand Up @@ -640,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:
Expand All @@ -659,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"]
Expand Down