Skip to content

Instantly share code, notes, and snippets.

@nkallen
Created March 12, 2020 11:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nkallen/71f28a3dad47ba5e5aa3be8574368d1f to your computer and use it in GitHub Desktop.
Save nkallen/71f28a3dad47ba5e5aa3be8574368d1f to your computer and use it in GitHub Desktop.
import hou, os, sys
from PySide2 import QtCore
from canvaseventtypes import KeyboardEvent
import utility_hotkey_system
import nodegraphstates as states
this = sys.modules[__name__]
__userdir = hou.getenv('HOUDINI_USER_PREF_DIR')
__pythonlibs = os.path.join(__userdir, "python2.7libs")
def __reload_pythonlibs():
print "Reloading libraries..."
reload(this)
reload(utility_hotkey_system)
fs_watcher = QtCore.QFileSystemWatcher()
fs_watcher.addPath(os.path.join(__pythonlibs, "nodegraphhooks.py"))
fs_watcher.addPath(os.path.join(__pythonlibs, "utility_hotkey_system.py"))
fs_watcher.fileChanged.connect(__reload_pythonlibs)
class MyBackgroundMouseHandler(base.EventHandler):
def handleEvent(self, uievent, pending_actions):
if isinstance(uievent, KeyboardEvent):
print "it works"
#utility_hotkey_system.invoke_action_from_key(uievent)
return self
if uievent.eventtype == 'mousedrag':
if self.start_uievent.mousestate.lmb:
return MyBoxPickHandler(self.start_uievent)
if uievent.eventtype == 'mouseup':
return None
return self
# copy paste all the other cases with your own subclasses
class MyBoxPickHandler(states.BoxPickHandler):
def handleEvent(self, uievent, pending_actions):
if isinstance(uievent, KeyboardEvent):
print "KEYBOARD 2"
#utility_hotkey_system.invoke_action_from_key(uievent)
return self
else:
return super(MyBoxPickHandler, self).handleEvent(uievent, pending_actions)
return None
def createEventHandler(uievent, pending_actions):
if not isinstance(uievent.editor, hou.NetworkEditor):
return None, False
if uievent.eventtype == 'mousedown':
return MyBackgroundMouseHandler(uievent), True
return None, False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment