Skip to content

Commit

Permalink
interactions: Add postQuickTip/clearQuickTip helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed May 24, 2024
1 parent 5cc5834 commit a19f7e3
Showing 1 changed file with 23 additions and 32 deletions.
55 changes: 23 additions & 32 deletions orangecanvas/document/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down Expand Up @@ -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('<h3>Create new link</h3>'
'<p>Drag a link to an existing node or release on '
'an empty spot to create a new node.</p>'
Expand All @@ -460,7 +470,6 @@ def mousePressEvent(self, event):
# 'More ...</a>'
)
)
QCoreApplication.postEvent(self.document, helpevent)
return True
else:
# Whoever put us in charge did not know what he was doing.
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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('<h3>New arrow annotation</h3>'
'<p>Click and drag to create a new arrow annotation</p>'
# '<a href="help://orange-canvas/arrow-annotations>'
# 'More ...</a>'
)
)
QCoreApplication.postEvent(self.document, helpevent)

super().start()

def setColor(self, color):
Expand Down Expand Up @@ -1428,11 +1432,7 @@ def end(self):
self.arrow_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()


Expand Down Expand Up @@ -1465,18 +1465,16 @@ def setFont(self, font):
def start(self):
# type: () -> None
self.document.view().setCursor(Qt.CrossCursor)

helpevent = QuickHelpTipEvent(
self.tr("Click to create a new text annotation"),
self.postQuickTip(
self.tr('<h3>New text annotation</h3>'
'<p>Click (and drag to resize) on the canvas to create '
'a new text annotation item.</p>'
'<p>Right click on the annotation to change how it is '
'rendered (Markdown, HTML, ...).</p>'
# '<a href="help://orange-canvas/text-annotations">'
# 'More ...</a>'
)
)
QCoreApplication.postEvent(self.document, helpevent)

super().start()

def createNewAnnotation(self, rect):
Expand Down Expand Up @@ -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()


Expand Down Expand Up @@ -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('<h3>Edit Text Annotation</h3>'
'<p>Drag control points to resize the annotation.</p>'
'<p>Right click on the annotation to change how it is '
'rendered.</p>')
'rendered (Markdown, HTML, ...).</p>')
)
QCoreApplication.postEvent(self.document, helpevent)

def cancel(self, reason=UserInteraction.OtherReason):
# type: (int) -> None
Expand All @@ -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()


Expand Down

0 comments on commit a19f7e3

Please sign in to comment.