def createEventHandler(uievent, pending_actions): """Create an event handler for Houdini's network editor. :param uievent: The occurring event. :type uievent: canvaseventtypes.KeyboardEvent :param pending_actions: Pending actions. :type pending_actions: list :return: Handler event information. :rtype: tuple """ if isinstance(uievent, KeyboardEvent) and uievent.eventtype in KEY_HIT_TYPES: editor = uievent.editor eventtype = uievent.eventtype key = uievent.key if setKeyPrompt(editor, key, "h.tool:copy_items", eventtype): return paste.copy_items_from_graph(editor) elif setKeyPrompt(editor, key, "h.tool:paste_items", eventtype): return paste.paste_items_to_graph(eventtype, editor, uievent) return None, False
def createEventHandler(uievent, pending_actions): """Create an event handler for Houdini's network editor.""" if isinstance(uievent, KeyboardEvent) and uievent.eventtype in ('keyhit', 'menukeyhit', 'parentkeyhit'): editor = uievent.editor eventtype = uievent.eventtype key = uievent.key if setKeyPrompt(editor, key, "h.tool:copy_items", eventtype): return paste.copy_items_from_graph(editor) elif setKeyPrompt(editor, key, "h.tool:paste_items", eventtype): return paste.paste_items_to_graph(eventtype, editor, uievent) return None, False
def createEventHandler(uievent, pending_actions): """Create an event handler for Houdini's network editor.""" if isinstance(uievent, KeyboardEvent) and uievent.eventtype in ( 'keyhit', 'menukeyhit', 'parentkeyhit'): editor = uievent.editor eventtype = uievent.eventtype key = uievent.key if setKeyPrompt(editor, key, "h.tool:copy_items", eventtype): return paste.copy_items_from_graph(editor) elif setKeyPrompt(editor, key, "h.tool:paste_items", eventtype): return paste.paste_items_to_graph(eventtype, editor, uievent) return None, False
def handleEventCoroutine(): visiblebounds = hou.BoundingRect() halfsize = utils.getNewNodeHalfSize() minsize = min(halfsize.x(), halfsize.y()) maxsize = max(halfsize.x(), halfsize.y()) inputnames = ('input', 'multiinput', 'dotinput') outputnames = ('output', 'indirectinputoutput', 'dotoutput') alignrects = [] shapes = [] nodecenter = None locatedconn = None locatedinput = None locatedoutput = None handler = None editor = None olddefaultcursor = None while True: uievent = yield if editor is None: editor = uievent.editor olddefaultcursor = editor.defaultCursor() if handler is not None: handler = sendEventToHandler(handler, uievent, shapes) if handler is None: editor.setDefaultCursor(olddefaultcursor) continue newvisiblebounds = editor.visibleBounds() if visiblebounds != newvisiblebounds: alignrects = editor.allVisibleRects([]) visiblebounds = newvisiblebounds if (isinstance(uievent, KeyboardEvent) or \ isinstance(uievent, MouseEvent)): if nodecenter is None: nodecenter = uievent.mousepos nodecenter = editor.posFromScreen(nodecenter) # Check for a wire to drop the node on, if that pref is enabled. # Don't update the target on a mouse up event. We want to keep # the located/selected target from the last mouse event, since the # selected value gets cleared on the mouseup event. if prefs.allowDropOnWire(editor) and uievent.eventtype != 'mouseup': target = None if isinstance(uievent, MouseEvent) and \ uievent.selected.item is not None: target = uievent.selected elif uievent.located.item is not None: target = uievent.located locatedconn = None locatedinput = None locatedoutput = None if target is not None: if isinstance(target.item, hou.NodeConnection): locatedconn = target elif target.name in inputnames: locatedinput = target elif target.name in outputnames: locatedoutput = target if locatedconn is None and \ locatedinput is None and \ locatedoutput is None: editor.setDefaultCursor(None) else: editor.setDefaultCursor(utils.theCursorDragDropOn) if isinstance(uievent, KeyboardEvent): if uievent.eventtype.endswith('keyhit') and \ display.setKeyPrompt(editor, uievent.key, 'h.pane.wsheet.cancel', uievent.eventtype): break if uievent.eventtype.endswith('keyhit') and \ display.setKeyPrompt(editor, uievent.key, 'h.pane.wsheet.add_op', uievent.eventtype): # Indicate that the keyboard event should be sent again, which # will allow it to be handled by the parent context (and open # up the tab menu). editor.handleCurrentKeyboardEvent(True) break elif uievent.eventtype == 'keyhit' and uievent.key == 'Enter': editor.eventContextData()['pos'] = nodecenter - halfsize setEventContextData(editor.eventContextData(), locatedconn, locatedinput, locatedoutput) break elif uievent.eventtype == 'keyhit' and uievent.key == 'Shift+Enter': editor.eventContextData()['pos'] = None setEventContextData(editor.eventContextData(), locatedconn, locatedinput, locatedoutput) break elif isinstance(uievent, MouseEvent): if uievent.eventtype == 'mousewheel': view.scaleWithMouseWheel(uievent) elif uievent.eventtype == 'mousedown': if uievent.selected.name.startswith('overview'): handler = base.OverviewMouseHandler(uievent) elif base.isPanEvent(uievent): handler = base.ViewPanHandler(uievent) elif base.isScaleEvent(uievent): handler = base.ViewScaleHandler(uievent) if handler is not None: editor.setDefaultCursor(olddefaultcursor) handler = sendEventToHandler(handler, uievent, shapes) elif uievent.eventtype == 'mouseup': editor.eventContextData()['pos'] = nodecenter - halfsize setEventContextData(editor.eventContextData(), locatedconn, locatedinput, locatedoutput) break else: nodecenter = uievent.mousepos nodecenter = editor.posFromScreen(nodecenter) category = editor.pwd().childTypeCategory() # If we are showing a preview of the node shape, we need to # pass a large square to ensure the shape draws at the # expected size. if prefs.showNodeShapes(editor) and \ category != hou.vopNodeTypeCategory(): halfmaxsize = hou.Vector2(maxsize, maxsize) rect = hou.BoundingRect(nodecenter - halfmaxsize, nodecenter + halfmaxsize) else: rect = hou.BoundingRect(nodecenter - halfsize, nodecenter + halfsize) snapresult = snap.snap(editor, None, rect, alignrects) if snapresult.isValid(): nodecenter += snapresult.delta() rect.translate(snapresult.delta()) ''' if prefs.showNodeShapes(editor): nodeshape = '' nodetypename = editor.eventContextData()['nodetypename'] if category is not None: nodetype = category.nodeType(nodetypename) if nodetype is not None: nodeshape = nodetype.defaultShape() shapes = [hou.NetworkShapeNodeShape(rect, nodeshape, hou.ui.colorFromName('GraphPreSelection'), 0.5, True, False)] else: shapes = [hou.NetworkShapeBox(rect, hou.ui.colorFromName('GraphPreSelection'), 0.5, True, False)]''' shapes = snapresult.shapes(editor) shapes.extend(buildPendingWires(editor, nodecenter, locatedconn, locatedinput, locatedoutput)) editor.setOverlayShapes(shapes) if editor is not None: editor.setDefaultCursor(olddefaultcursor) editor.setOverlayShapes([]) editor.popEventContext()