Skip to content

Instantly share code, notes, and snippets.

@oglops
Last active October 15, 2017 21:29
Show Gist options
  • Save oglops/eeea894afe372895eb2d3a46715b3237 to your computer and use it in GitHub Desktop.
Save oglops/eeea894afe372895eb2d3a46715b3237 to your computer and use it in GitHub Desktop.
install an event filter to main maya window, and only intercept the ctrl+/ key when mouse pointer is on top of script editor
from PyQt4.QtCore import *
from PyQt4.QtGui import *
import maya.cmds as mc
import maya.mel as mel
class CustomFilter(QObject):
def eventFilter(self, obj, event):
if event.type() == QEvent.KeyPress:
if 'scriptEditorPanel' in mc.getPanel(up=1):
if event.key() == Qt.Key_Slash and event.modifiers() == Qt.ControlModifier:
print 'ctrl+/ pressed'
# what is current tab?
tabIdx = mc.tabLayout(gCommandExecuterTabs, q=1, st=1)
print 'current tab:', tabIdx
return True
return False
def get_mel_global(var):
return mel.eval('$tmp_var=%s' % var)
gCommandExecuterTabs = get_mel_global('$gCommandExecuterTabs')
filter = CustomFilter()
qApp.installEventFilter(filter)
# This will remove the filter we installed
# qApp.removeEventFilter(filter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment