Wed, 04 Aug 2021 15:35:49 +0200
Editor: prepared the editor to support mouse hover help.
eric7/QScintilla/Editor.py | file | annotate | diff | comparison | revisions |
--- a/eric7/QScintilla/Editor.py Wed Aug 04 14:28:04 2021 +0200 +++ b/eric7/QScintilla/Editor.py Wed Aug 04 15:35:49 2021 +0200 @@ -430,6 +430,11 @@ self.gotoLine(1) + # connect the mouse hover signals + self.SCN_DWELLSTART.connect(self.__showMouseHoverHelp) + self.SCN_DWELLEND.connect(self.__cancelMouseHoverHelp) + self.__mouseHoverHelp = None + # set the text display again self.__setTextDisplay() @@ -4693,6 +4698,13 @@ self.setVirtualSpaceOptions( Preferences.getEditor("VirtualSpaceOptions")) + if Preferences.getEditor("MouseHoverHelp"): + self.SendScintilla(QsciScintilla.SCI_SETMOUSEDWELLTIME, + Preferences.getEditor("MouseHoverTimeout")) + else: + self.SendScintilla(QsciScintilla.SCI_SETMOUSEDWELLTIME, + QsciScintilla.SC_TIME_FOREVER) + # to avoid errors due to line endings by pasting self.SendScintilla(QsciScintilla.SCI_SETPASTECONVERTENDINGS, True) @@ -8828,3 +8840,77 @@ docstringMenu.setActiveAction(act) docstringMenu.popup( self.mapToGlobal(self.getGlobalCursorPosition())) + + ####################################################################### + ## Methods implementing the mouse hover help interface + ####################################################################### + + @pyqtSlot(int, int, int) + def __showMouseHoverHelp(self, pos, x, y): + """ + Private slot showing code information about the symbol under the + cursor. + + @param pos mouse position into the document + @type int + @param x x-value of mouse screen position + @type int + @param y y-value of mouse screen position + @type int + """ + if self.__mouseHoverHelp is not None and pos >= 0: + line, index = self.lineIndexFromPosition(x) + if index > 0: + self.__mouseHoverHelp(self, line, index) + else: + self.__cancelMouseHoverHelp() + else: + self.__cancelMouseHoverHelp() + + def __cancelMouseHoverHelp(self): + """ + Private slot cancelling the display of mouse hover help. + """ + self.SendScintilla(QsciScintilla.SCI_CALLTIPCANCEL) + + def registerMouseHoverHelpFunction(self, func): + """ + Public method to register a mouse hover help function. + + Note: Only one plugin should provide this function. Otherwise + the last one wins. + + @param func function accepting a reference to the calling editor and + the line and column position (zero based each) + @type func + """ + self.__mouseHoverHelp = func + + def unregisterMouseHoverHelpFunction(self, func): + """ + Public method to unregister a mouse hover help function. + + @param func function accepting a reference to the calling editor and + the line and column position (zero based each) + @type func + """ + if self.__mouseHoverHelp is func: + self.__mouseHoverHelp = None + + def showMouseHoverHelpData(self, line, index, data): + """ + Public method to show the mouse hover help data. + + @param line line of mouse cursor position + @type int + @param index column of mouse cursor position + @type TYPE + @param data information text to be shown + @type str + """ + if data: + pos = self.positionFromLineIndex(line, index) + self.SendScintilla(QsciScintilla.SCI_CALLTIPSHOW, + pos, data) + else: + self.__cancelMouseHoverHelp()