[PYSIDE] shortCut behavior on buttons in different tabs

Hi,
I have a UI with a few Tabs and in these tabs I have some buttons and I’ve assigned these buttons shortCuts.
My problem is that the shortCuts only seem to work when the Tab is active or being shown. If I go to another tab that same shortCut does not want to work. It’s only when I activate the tab does the shortCut work.
Any suggestions on getting the behavior to work across all tabs?

Cheers,
-Sean

Forget it. I’m going to go down a different route.
Thinking of doing some module inspection and setting up Maya hotkey namedCommands on the fly.
That way the UI doesn’t need to be loaded at runtime.

So I thought I’d share a bit of code I came up with. Like I said above I needed to create shorctCuts for my buttons and menus but instead of using shortCuts on buttons I’d rather have Maya shortCuts for the ACTUAL function call.

I ended up creating an EchoCommand decorator and used this decorator for each button function call.

Here I have a simple function say stored in myModule.py:

def saySomething(s):
    print "You said {}".format(s)

For my button I have this.

self.myButton.clicked.connect(lambda *args: self.saySomething("I'm handsome"))

So you click the button and it prints “You said I’m handsome”. Thanks, you’re so nice!

Now here is the decorator code (I’ve been putting all my decorator code in a decorator.py file and import the commands I need)

class EchoCommand(object):
    """
    Similar to Maya's echo commands
    Prints out the module and function with arguments
    """
    def __init__(self, function):
        self.function = function
        self.function_call = self.function.__name__
        self.module = inspect.getmodule(self.function).__name__

    def echo(self, *arguments, **namedArguments):
        print "from {} import {}".format(self.module, self.function_call)
        print "{}{}".format(self.function.func_name, arguments)
        self.function.__call__(*arguments, **namedArguments)


def d_echoCommand(function):
    """
    Echo Command
    """
    return EchoCommand(function).echo

Let’s implement the decorator now:

@d_echoCommand
def saySomething(s):
    print "You said {}".format(s)

Now when you hit the button you should get the echoed command

from myModule import saySomething
saySomething("I'm handsome",)

So now the user can take that bit of code and create a Maya Hotkey, make it repeatable or run it manually.

Hope you find it helpful!

Cheers,
-Sean