Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] Text Annotations quick tip text #298

Merged
merged 2 commits into from
May 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 30 additions & 27 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 @@ -1676,6 +1670,15 @@ def __on_textGeometryChanged(self):
rect = self.item.geometry()
self.control.setRect(rect)

def start(self) -> None:
super().start()
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 (Markdown, HTML, ...).</p>')
)

def cancel(self, reason=UserInteraction.OtherReason):
# type: (int) -> None
log.debug("ResizeTextAnnotation.cancel(%s)", reason)
Expand All @@ -1694,7 +1697,7 @@ def end(self):
self.item = None
self.annotation = None
self.control = None

self.clearQuickTip()
super().end()


Expand Down
Loading