def _GenerateMouseEvent(self, eventName, *eventArgs): """ _GenerateMouseEvent(eventName, *eventArgs) For the backend to generate mouse events. """ if not self._enableUserInteraction: return # make lower eventName = eventName.lower() # get items now under the mouse items1 = [item() for item in self._underMouse if item()] # init list of events to fire events = [] if eventName.count("motion") or eventName.count("move"): # Set current mouse pos, so that it's up to date self._mousepos = eventArgs[0], eventArgs[1] # also get new version of items under the mouse items2 = self._pickerHelper.GetItemsUnderMouse(self) # init event list events = [] # analyse for enter and leave events for item in items1: if item not in items2: events.append(item.eventLeave) for item in items2: if item not in items1: events.append(item.eventEnter) # Generate motion events for any objects that have handlers # for the motion event. Note that this excludes "self". items = self.FindObjects(lambda i: i.eventMotion.hasHandlers) events.extend([item.eventMotion for item in items]) # Always generate motion event from figure events.append(self.eventMotion) # Update items under the mouse self._underMouse = [item.GetWeakref() for item in items2] # Note: how to handle motionEvents # It feels nicer (and is more Qt-ish) to fire the events only # from the objects that have their mouse pressed down. However, # someone may want to be notified of motion regardless of the # state of the mouse. Qt has setMouseTracking(True). # But then there's a problem. This version of eventMotion we *do* # want to propate to parent objects if not handled. But then # an object may get an event twice if the mouse is pressed down. # Surely these things can be overcome, but I think its easier # for everyone if we stick to the old approach: the eventMotion # is fired for all objects that have handlers registered to it. elif eventName.count("up"): # Find objects that are currently clicked down items = self.FindObjects(lambda i: i._mousePressedDown) if self._mousePressedDown: items.append(self) events.extend([item.eventMouseUp for item in items]) # todo: Also generate event where the mouse is now over - MouseDrop? #if items[-1] not in items: # events.append( items[-1].eventMouseDrop) elif items1 and eventName.count("down"): events.append(items1[-1].eventMouseDown) elif items1 and eventName.count("double"): # Note: we cannot detect double clicking by timing the down-events, # because the toolkit won't fire a down event for the second click. events.append(items1[-1].eventDoubleClick) elif items1 and eventName.count('scroll'): events.append(items1[-1].eventScroll) # Fire events for event in events: event.Fire(*eventArgs)
def _GenerateMouseEvent(self, eventName, *eventArgs): """ _GenerateMouseEvent(eventName, *eventArgs) For the backend to generate mouse events. """ if not self._enableUserInteraction: return # make lower eventName = eventName.lower() # get items now under the mouse items1 = [item() for item in self._underMouse if item()] # init list of events to fire events = [] eventToAlwaysFire = None if eventName.count("motion") or eventName.count("move"): # Set current mouse pos, so that it's up to date self._mousepos = eventArgs[0], eventArgs[1] # also get new version of items under the mouse items2 = self._pickerHelper.GetItemsUnderMouse(self) # init event list events = [] # analyse for enter and leave events for item in items1: if item not in items2: events.append(item.eventLeave) for item in items2: if item not in items1: events.append(item.eventEnter) # Generate motion events for any objects that have handlers # for the motion event. Note that this excludes "self". items = self.FindObjects(lambda i:i.eventMotion.hasHandlers) events.extend([item.eventMotion for item in items]) # Always generate motion event from figure events.append(self.eventMotion) # Update items under the mouse self._underMouse = [item.GetWeakref() for item in items2] # Note: how to handle motionEvents # It feels nicer (and is more Qt-ish) to fire the events only # from the objects that have their mouse pressed down. However, # someone may want to be notified of motion regardless of the # state of the mouse. Qt has setMouseTracking(True). # But then there's a problem. This version of eventMotion we *do* # want to propate to parent objects if not handled. But then # an object may get an event twice if the mouse is pressed down. # Surely these things can be overcome, but I think its easier # for everyone if we stick to the old approach: the eventMotion # is fired for all objects that have handlers registered to it. elif eventName.count("up"): # Find objects that are currently clicked down items = self.FindObjects(lambda i:i._mousePressedDown) if self._mousePressedDown: items.append(self) events.extend([item.eventMouseUp for item in items]) # todo: Also generate event where the mouse is now over - MouseDrop? #if items[-1] not in items: # events.append( items[-1].eventMouseDrop) elif items1 and eventName.count("down"): events.append(items1[-1].eventMouseDown) elif items1 and eventName.count("double"): # Note: we cannot detect double clicking by timing the down-events, # because the toolkit won't fire a down event for the second click. events.append(items1[-1].eventDoubleClick) elif items1 and eventName.count('scroll'): events.append(items1[-1].eventScroll) # Fire events for event in events: event.Fire(*eventArgs)
def _GenerateMouseEvent(self, eventName, absx, absy, button=0, modifiers=()): """ _GenerateMouseEvent(eventName, x, y, button=0) For the backend to generate mouse events. """ # make lower eventName = eventName.lower() # get items now under the mouse items1 = [item() for item in self._underMouse if item()] # init list of events to fire events = [] if eventName.count("motion") or eventName.count("move"): # Set current mouse pos, so that it's up to date self._mousepos = absx, absy # also get new version of items under the mouse items2 = self._pickerHelper.GetItemsUnderMouse(self) # init event list events = [] # analyse for enter and leave events for item in items1: if item not in items2: events.append((item, item.eventLeave)) for item in items2: if item not in items1: events.append((item, item.eventEnter)) # Always generate motion event from figure events.append((self, self.eventMotion)) # Generate motion events for any objects that have handlers # for the motion event items = self.FindObjects(lambda i: i._eventMotion._handlers) events.extend([(item, item._eventMotion) for item in items]) # Update items under the mouse self._underMouse = [item.GetWeakref() for item in items2] elif eventName.count("up"): # Find object that was clicked down items = self.FindObjects(lambda i: i._mousePressedDown) for item in items: events.append((item, item.eventMouseUp)) item._mousePressedDown = False elif items1 and eventName.count("down"): item = items1[-1] item._mousePressedDown = True events.append((item, item.eventMouseDown)) elif items1 and eventName.count("double"): # Note: we cannot detect double clicking by timing the down-events, # because the toolkit won't fire a down event for the second click. item = items1[-1] events.append((item, item.eventDoubleClick)) # Fire events for item, ev in events: ev.Set(absx, absy, button, modifiers) ev.Fire()