def do_add_command(self, menu, name, cmd, hot_key=None, icon=None): # TODO add hot key # From the PyQt documentation: # PySide.QtGui.QAction.triggered([checked = false]) # Parameters: checked – PySide.QtCore.bool # If your callback signature is cmd(*args), the signal sent will have an arg, False, which corresponds # to the checked state of the menu item. But if it's cmd(), then it won't. # since the apps registered commands are defined as wrappers, callback_wrapper(*args, **kwargs) # (see /rdo/rodeo/repositories/tank/studio/install/core/python/tank/platform/engine.py, # register_command function), they will pass the False argument to the callbacks registered by the # apps, for example for tk-multi-contextSwitcher: # menu_callback = lambda : app_payload.contextSwitcher.show_dialog(self) # this will fail since the callback does not take any arguments. # By "wrapping the wrapper" with this lambda, the function attached to triggered has no args and # everything works. cb = lambda: cmd() if hot_key: action = QtGui.QAction(name, menu, triggered=cb, icon=icon) else: if icon: new_icon = QtGui.QIcon(icon) action = QtGui.QAction(name, menu, triggered=cb, icon=new_icon) else: action = QtGui.QAction(name, menu, triggered=cb) menu.addAction(action)
def do_add_command(self, menu, name, cmd, hot_key=None, icon=None): # TODO add hot key if hot_key: action = QtGui.QAction(name, menu, triggered=cmd, icon=icon) else: if icon: new_icon = QtGui.QIcon(icon) action = QtGui.QAction(name, menu, triggered=cmd, icon=new_icon) else: action = QtGui.QAction(name, menu, triggered=cmd) menu.addAction(action)
def __create_tank_error_menu(): """ Creates a std "error" tank menu and grabs the current context. Make sure that this is called from inside an except clause. """ (exc_type, exc_value, exc_traceback) = sys.exc_info() message = "" message += "Message: Shotgun encountered a problem starting the Engine.\n" message += "Please contact [email protected]\n\n" message += "Exception: %s - %s\n" % (exc_type, exc_value) message += "Traceback (most recent call last):\n" message += "\n".join(traceback.format_tb(exc_traceback)) if Configuration.get("KATANA_UI_MODE"): sg_menu = MenuGenerator.get_or_create_root_menu("Shotgun") if sg_menu is not None: sg_menu.clear() cmd = lambda m=message: __show_tank_message( "Shotgun Pipeline Toolkit caught an error", m) action = QtGui.QAction("[Shotgun Error - Click for details]", sg_menu, triggered=cmd) sg_menu.addAction(action) else: print("The Shotgun Pipeline Toolkit caught an error: %s" % message)
def _add_context_menu(self, menu_handle): """ Adds a context menu which displays the current context """ ctx = self._engine.context ctx_name = str(ctx) # create the menu object ctx_menu = menu_handle.addMenu(ctx_name) action = QtGui.QAction('Jump to Shotgun', self.root_menu,triggered=self._jump_to_sg) ctx_menu.addAction(action) action = QtGui.QAction('Jump to File System', self.root_menu,triggered=self._jump_to_fs) ctx_menu.addAction(action) ctx_menu.addSeparator() return ctx_menu
def __create_tank_disabled_menu(details): """ Creates a std "disabled" shotgun menu """ if Configuration.get("KATANA_UI_MODE"): sg_menu = MenuGenerator.get_or_create_root_menu("Shotgun") if sg_menu is not None: sg_menu.clear() cmd = lambda d=details: __show_tank_disabled_message(d) action = QtGui.QAction("Toolkit is disabled", sg_menu, triggered=cmd) sg_menu.addAction(action) else: print("The Shotgun Pipeline Toolkit is disabled: %s" % details)