372 self.__completionListHookFunctions = {} |
372 self.__completionListHookFunctions = {} |
373 self.__setAutoCompletion() |
373 self.__setAutoCompletion() |
374 self.__ctHookFunction = None |
374 self.__ctHookFunction = None |
375 self.__ctHookFunctions = {} |
375 self.__ctHookFunctions = {} |
376 self.__setCallTips() |
376 self.__setCallTips() |
|
377 |
|
378 # set the mouse click handlers (fired on mouse release) |
|
379 self.__mouseClickHandlers = {} |
|
380 # dictionary with tuple of keyboard modifier and mouse button as key |
|
381 # and tuple of plug-in name and function as value |
|
382 self.__modifier2String = { |
|
383 Qt.ShiftModifier: self.tr("Shift"), |
|
384 Qt.ControlModifier: self.tr("Ctrl"), |
|
385 Qt.AltModifier: self.tr("Alt"), |
|
386 Qt.MetaModifier: self.tr("Meta"), |
|
387 } |
|
388 self.__button2String = { |
|
389 Qt.LeftButton: self.tr("Left Button"), |
|
390 Qt.RightButton: self.tr("Right Button"), |
|
391 Qt.MidButton: self.tr("Middle Button"), |
|
392 Qt.XButton1: self.tr("X Button 1"), |
|
393 Qt.XButton2: self.tr("X Button 2"), |
|
394 } |
377 |
395 |
378 sh = self.sizeHint() |
396 sh = self.sizeHint() |
379 if sh.height() < 300: |
397 if sh.height() < 300: |
380 sh.setHeight(300) |
398 sh.setHeight(300) |
381 self.resize(sh) |
399 self.resize(sh) |
7562 |
7580 |
7563 # step 5: reset the rectangular selection |
7581 # step 5: reset the rectangular selection |
7564 self.setRectangularSelection(origStartLine, origStartIndex, |
7582 self.setRectangularSelection(origStartLine, origStartIndex, |
7565 origEndLine, origEndIndex) |
7583 origEndLine, origEndIndex) |
7566 self.selectionChanged.emit() |
7584 self.selectionChanged.emit() |
|
7585 |
|
7586 ####################################################################### |
|
7587 ## Mouse click handler related methods |
|
7588 ####################################################################### |
|
7589 |
|
7590 def __mouseClickToString(self, modifiers, button): |
|
7591 """ |
|
7592 Private method to generate a display string for the given modifiers |
|
7593 and button combination. |
|
7594 |
|
7595 @param modifiers keyboard modifiers of the handler |
|
7596 @type Qt.KeyboardModifiers |
|
7597 @param button mouse button of the handler |
|
7598 @type Qt.MouseButton |
|
7599 @return display string |
|
7600 @rtype str |
|
7601 """ |
|
7602 parts = [] |
|
7603 for mod in sorted(self.__modifier2String.keys()): |
|
7604 if modifiers & mod: |
|
7605 parts.append(self.__modifier2String[mod]) |
|
7606 parts.append(self.__button2String[button]) |
|
7607 return "+".join(parts) |
|
7608 |
|
7609 def mouseReleaseEvent(self, evt): |
|
7610 """ |
|
7611 Protected method calling a registered mouse click handler function. |
|
7612 |
|
7613 @param evt event object |
|
7614 @type QMouseEvent |
|
7615 """ |
|
7616 modifiers = evt.modifiers() |
|
7617 button = evt.button() |
|
7618 key = (modifiers, button) |
|
7619 |
|
7620 if button != Qt.NoButton and key in self.__mouseClickHandlers: |
|
7621 self.__mouseClickHandlers[key][1]() |
|
7622 evt.accept() |
|
7623 else: |
|
7624 self.vm.eventFilter(self, evt) |
|
7625 super(Editor, self).mouseReleaseEvent(evt) |
|
7626 |
|
7627 def setMouseClickHandler(self, name, modifiers, button, function): |
|
7628 """ |
|
7629 Public method to set a mouse click handler. |
|
7630 |
|
7631 @param name name of the plug-in (or 'internal') setting this handler |
|
7632 @type str |
|
7633 @param modifiers keyboard modifiers of the handler |
|
7634 @type Qt.KeyboardModifiers |
|
7635 @param button mouse button of the handler |
|
7636 @type Qt.MouseButton |
|
7637 @param function handler function |
|
7638 @type func |
|
7639 @return flag indicating success |
|
7640 @rtype bool |
|
7641 """ |
|
7642 key = (modifiers, button) |
|
7643 if key in self.__mouseClickHandlers: |
|
7644 E5MessageBox.warning( |
|
7645 self, |
|
7646 self.tr("Register Mouse Click Handler"), |
|
7647 self.tr("""A mouse click handler for "{0}" was already""" |
|
7648 """ registered by {1}". Aborting request by""" |
|
7649 """ "{2}"...""").format( |
|
7650 self.__mouseClickToString(modifiers, button), |
|
7651 self.__mouseClickHandlers[key][0], |
|
7652 name)) |
|
7653 return False |
|
7654 |
|
7655 self.__mouseClickHandlers[key] = (name, function) |
|
7656 return True |
|
7657 |
|
7658 def getMouseClickHandler(self, modifiers, button): |
|
7659 """ |
|
7660 Public method to get a registered mouse click handler. |
|
7661 |
|
7662 @param modifiers keyboard modifiers of the handler |
|
7663 @type Qt.KeyboardModifiers |
|
7664 @param button mouse button of the handler |
|
7665 @type Qt.MouseButton |
|
7666 @return plug-in name and registered function |
|
7667 @rtype tuple of str and func |
|
7668 """ |
|
7669 key = (modifiers, button) |
|
7670 if key in self.__mouseClickHandlers: |
|
7671 return self.__mouseClickHandlers[key] |
|
7672 else: |
|
7673 return ("", None) |
|
7674 |
|
7675 def getMouseClickHandlers(self, name): |
|
7676 """ |
|
7677 Public method to get all registered mouse click handlers of |
|
7678 a plug-in. |
|
7679 |
|
7680 @param name name of the plug-in |
|
7681 @type str |
|
7682 @return registered mouse click handlers as list of modifiers, |
|
7683 mouse button and function |
|
7684 @rtype list of tuple of (Qt.KeyboardModifiers, Qt.MouseButton,func) |
|
7685 """ |
|
7686 lst = [] |
|
7687 for key, value in self.__mouseClickHandlers.items(): |
|
7688 if value[0] == name: |
|
7689 lst.append((key[0], key[1], value[1])) |
|
7690 return lst |
|
7691 |
|
7692 def removeMouseClickHandler(self, modifiers, button): |
|
7693 """ |
|
7694 |
|
7695 """ |
|
7696 |
|
7697 def removeMouseClickHandlers(self, name): |
|
7698 """ |
|
7699 |
|
7700 """ |