PySide version:

#####################################################
from PySide import QtCore, QtGui
from shiboken import wrapInstance 
import maya.OpenMayaUI as mui

mainWin = wrapInstance(long(mui.MQtUtil.mainWindow()), QtGui.QWidget)

action = QtGui.QAction(mainWin)
action.setShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Tab))
action.setShortcutContext(QtCore.Qt.ApplicationShortcut)

def foo():
    print "TAB!"
    
action.triggered.connect(foo)
mainWin.addAction(action)
#####################################################

On Sunday, November 11, 2012 at 10:38:42 AM UTC-5, Marcus Ottosson wrote:
> Works perfectly, thanks Justin!
> 
> Marcus
> 
> Den onsdagen den 7:e november 2012 kl. 18:33:11 UTC skrev Justin Israel:Check 
> this out. You can create a QAction that is set to the Application context, 
> and then attach it to the MainWindow:
> 
> 
> ####
> 
> from PyQt4 import QtCore, QtGui
> import sip
> 
> 
> 
> import maya.OpenMayaUI as mui
> 
> 
> mainWin = sip.wrapinstance(long(mui.MQtUtil.mainWindow()), QtGui.QWidget)
> 
> 
> action = QtGui.QAction(mainWin)
> action.setShortcut(QtGui.QKeySequence(QtCore.Qt.Key_Tab))
> 
> action.setShortcutContext(QtCore.Qt.ApplicationShortcut)
> 
> 
> def foo():
>     print "TAB!"
>     
> action.triggered.connect(foo)
> mainWin.addAction(action)
> 
> ####
> 
> 
> Whenever I press TAB with the MainWindow in focus, I get the action 
> triggered. 
> Now you could either save the reference to the action and slot, and 
> disconnect/reconnect to new ones for hot key references...or..you could just 
> set this all up once and have the slot call a function on your class that you 
> can simply replace at any time. That way you never have to mess with the 
> action or original slot. You just update whatever function the slot calls.
> 
> 
> 
> -- justin
> 
> 
> 
> 
> 
> On Wed, Nov 7, 2012 at 9:43 AM, Judah Baron <[email protected]> wrote:
> 
> I'm guessing you need to go higher up in the object hierarchy with the event 
> filter. There is probably something else swallowing that event so you never 
> receive it.
> 
> 
> 
> 
> 
> 
> 
> On Wed, Nov 7, 2012 at 6:28 AM, Marcus Ottosson <[email protected]> wrote:
> 
> 
> Thanks for your response. I should've mentioned, I did try installing an 
> event filter, but it reported events from essentially ALL keys, EXCEPT tab. :)
> 
> 
> 
> I'll give it another go tonight. Can you think of any other way to hook into 
> the tab key?
> 
> 
> 
> 
> 
> --
> 
> view archives: http://groups.google.com/group/python_inside_maya
> 
> change your subscription settings: 
> http://groups.google.com/group/python_inside_maya/subscribe
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> view archives: http://groups.google.com/group/python_inside_maya
> 
> change your subscription settings: 
> http://groups.google.com/group/python_inside_maya/subscribe

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/555d810d-fb16-4e57-99d5-4b1e258f29d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to