diff --git a/orangecanvas/document/interactions.py b/orangecanvas/document/interactions.py index e5895e0c..507c22d4 100644 --- a/orangecanvas/document/interactions.py +++ b/orangecanvas/document/interactions.py @@ -189,6 +189,18 @@ def cancelReason(self): """ return self.__cancelReason + def postQuickTip(self, contents: str) -> None: + """ + Post a QuickHelpTipEvent with rich text `contents` to the document + editor. + """ + hevent = QuickHelpTipEvent("", contents) + QApplication.postEvent(self.document, hevent) + + def clearQuickTip(self): + """Clear the quick tip help event.""" + self.postQuickTip("") + def mousePressEvent(self, event): # type: (QGraphicsSceneMouseEvent) -> bool """ @@ -448,9 +460,7 @@ def mousePressEvent(self, event): self.direction = NewLinkAction.FROM_SINK event.accept() - - helpevent = QuickHelpTipEvent( - self.tr("Create a new link"), + self.postQuickTip( self.tr('
Drag a link to an existing node or release on ' 'an empty spot to create a new node.
' @@ -460,7 +470,6 @@ def mousePressEvent(self, event): # 'More ...' ) ) - QCoreApplication.postEvent(self.document, helpevent) return True else: # Whoever put us in charge did not know what he was doing. @@ -875,8 +884,7 @@ def end(self): self.reset_open_anchor() # Remove the help tip set in mousePressEvent self.macro = None - helpevent = QuickHelpTipEvent("", "") - QCoreApplication.postEvent(self.document, helpevent) + self.clearQuickTip() super().end() def cancel(self, reason=UserInteraction.OtherReason): @@ -1340,17 +1348,13 @@ def __init__(self, document, *args, **kwargs): def start(self): # type: () -> None self.document.view().setCursor(Qt.CrossCursor) - - helpevent = QuickHelpTipEvent( - self.tr("Click and drag to create a new arrow"), + self.postQuickTip( self.tr('Click and drag to create a new arrow annotation
' # ' None self.document.view().setCursor(Qt.CrossCursor) - - helpevent = QuickHelpTipEvent( - self.tr("Click to create a new text annotation"), + self.postQuickTip( self.tr('Click (and drag to resize) on the canvas to create ' 'a new text annotation item.
' + 'Right click on the annotation to change how it is ' + 'rendered (Markdown, HTML, ...).
' # '' # 'More ...' ) ) - QCoreApplication.postEvent(self.document, helpevent) - super().start() def createNewAnnotation(self, rect): @@ -1590,11 +1588,7 @@ def end(self): self.annotation_item = None self.annotation = None self.document.view().setCursor(Qt.ArrowCursor) - - # Clear the help tip - helpevent = QuickHelpTipEvent("", "") - QCoreApplication.postEvent(self.document, helpevent) - + self.clearQuickTip() super().end() @@ -1678,14 +1672,12 @@ def __on_textGeometryChanged(self): def start(self) -> None: super().start() - helpevent = QuickHelpTipEvent( - self.tr("Edit Text Annotation"), + self.postQuickTip( self.tr('Drag control points to resize the annotation.
' 'Right click on the annotation to change how it is ' - 'rendered.
') + 'rendered (Markdown, HTML, ...).') ) - QCoreApplication.postEvent(self.document, helpevent) def cancel(self, reason=UserInteraction.OtherReason): # type: (int) -> None @@ -1705,8 +1697,7 @@ def end(self): self.item = None self.annotation = None self.control = None - helpevent = QuickHelpTipEvent("", "") - QCoreApplication.postEvent(self.document, helpevent) + self.clearQuickTip() super().end()