Skip to content

Commit 005dc69

Browse files
authored
Merge pull request #333 from ales-erjavec/annotations-in-menu
schemeedit: Add Text and Arrow annotations to Edit menu
2 parents f3c167a + b682c49 commit 005dc69

File tree

3 files changed

+75
-2
lines changed

3 files changed

+75
-2
lines changed

i18n/si/msgs.jaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1914,6 +1914,8 @@ document/schemeedit.py:
19141914
Add a text annotation to the workflow.: V delotok dodaj besedilno oznako.
19151915
Font Size: Velikost pisave
19161916
%ipx: false
1917+
Text Annotation: Besedilna oznaka
1918+
new-quick-text-annotation-action: false
19171919
Arrow: Puščica
19181920
new-arrow-action: false
19191921
Add a arrow annotation to the workflow.: V delotok dodaj oznako s puščico.
@@ -1923,6 +1925,8 @@ document/schemeedit.py:
19231925
'#662D91': false
19241926
'#1F9CDF': false
19251927
'#39B54A': false
1928+
Arrow Annotation: Puščična oznaka
1929+
new-quick-arrow-annotation-action: false
19261930
undo-action: false
19271931
redo-action: false
19281932
Select all: Izberi vse
@@ -2018,6 +2022,8 @@ document/schemeedit.py:
20182022
Canceled new arrow annotation: false
20192023
def `__toggleNewTextAnnotation`:
20202024
Canceled new text annotation: false
2025+
def `__triggerNewTextAnnotation`:
2026+
text/markdown: false
20212027
def `__onHelpAction`:
20222028
help://search?: false
20232029
id: false

orangecanvas/document/schemeedit.py

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
QWhatsThisClickedEvent, QKeyEvent, QPalette
3636
)
3737
from AnyQt.QtCore import (
38-
Qt, QObject, QEvent, QSignalMapper, QCoreApplication, QPointF,
38+
Qt, QObject, QEvent, QSignalMapper, QCoreApplication, QPointF, QRectF,
3939
QMimeData, Slot)
4040
from AnyQt.QtCore import pyqtProperty as Property, pyqtSignal as Signal
4141

@@ -51,7 +51,7 @@
5151
)
5252
from ..scheme import (
5353
scheme, signalmanager, Scheme, SchemeNode, SchemeLink,
54-
BaseSchemeAnnotation, SchemeTextAnnotation, WorkflowEvent
54+
BaseSchemeAnnotation, SchemeTextAnnotation, WorkflowEvent, SchemeArrowAnnotation
5555
)
5656
from ..scheme.widgetmanager import WidgetManager
5757
from ..canvas.scene import CanvasScene
@@ -224,6 +224,9 @@ def __init__(self, parent=None, ):
224224
self.__editMenu.addAction(self.__copySelectedAction)
225225
self.__editMenu.addAction(self.__pasteAction)
226226
self.__editMenu.addAction(self.__selectAllAction)
227+
self.__editMenu.addSeparator()
228+
self.__editMenu.addAction(self.__newQuickTextAnnotationAction)
229+
self.__editMenu.addAction(self.__newQuickArrowAnnotationAction)
227230

228231
# Widget context menu
229232
self.__widgetMenu = QMenu(self.tr("Widget"), self)
@@ -293,6 +296,13 @@ def font(size):
293296

294297
self.__newTextAnnotationAction.setMenu(self.__fontMenu)
295298

299+
self.__newQuickTextAnnotationAction = QAction(
300+
self.tr("Text Annotation"), self,
301+
objectName="new-quick-text-annotation-action",
302+
toolTip=self.tr("Add a text annotation to the workflow."),
303+
triggered=self.__triggerNewTextAnnotation
304+
)
305+
296306
self.__newArrowAnnotationAction = QAction(
297307
self.tr("Arrow"), self,
298308
objectName="new-arrow-action",
@@ -332,6 +342,13 @@ def color_icon(color):
332342

333343
self.__newArrowAnnotationAction.setMenu(self.__arrowColorMenu)
334344

345+
self.__newQuickArrowAnnotationAction = QAction(
346+
self.tr("Arrow Annotation"), self,
347+
objectName="new-quick-arrow-annotation-action",
348+
toolTip=self.tr("Add a arrow annotation to the workflow."),
349+
triggered=self.__triggerNewArrowAnnotation,
350+
)
351+
335352
self.__undoAction = self.__undoStack.createUndoAction(self)
336353
self.__undoAction.setShortcut(QKeySequence.Undo)
337354
self.__undoAction.setObjectName("undo-action")
@@ -1959,6 +1976,38 @@ def __onArrowColorTriggered(self, action):
19591976
if isinstance(handler, interactions.NewArrowAnnotation):
19601977
handler.setColor(action.data())
19611978

1979+
def __triggerNewTextAnnotation(self):
1980+
"""Place a text annotation at the center of the view"""
1981+
center = self.view().viewport().rect().center()
1982+
center = self.view().mapToScene(center)
1983+
rect = QRectF(0, 0, 300, 150)
1984+
rect.moveCenter(center)
1985+
annotation = SchemeTextAnnotation(
1986+
(rect.x(), rect.y(), rect.width(), rect.height()),
1987+
content_type="text/markdown",
1988+
)
1989+
self.addAnnotation(annotation)
1990+
# Give edit focus
1991+
item = self.scene().item_for_annotation(annotation)
1992+
item.setFocus(Qt.OtherFocusReason)
1993+
item.setSelected(True)
1994+
item.startEdit()
1995+
1996+
def __triggerNewArrowAnnotation(self):
1997+
"""Place an arrow annotation at the center of the view"""
1998+
center = self.view().viewport().rect().center()
1999+
center = self.view().mapToScene(center)
2000+
2001+
annotation = SchemeArrowAnnotation(
2002+
(center.x() - 100, center.y()), (center.x() + 100, center.y()),
2003+
color=self.__arrowColorActionGroup.checkedAction().data()
2004+
)
2005+
self.addAnnotation(annotation)
2006+
# Give edit focus
2007+
item = self.scene().item_for_annotation(annotation)
2008+
item.setFocus(Qt.OtherFocusReason)
2009+
item.setSelected(True)
2010+
19622011
def __onRenameAction(self):
19632012
# type: () -> None
19642013
"""

orangecanvas/document/tests/test_schemeedit.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,24 @@ def test_text_annotation_action_cancel(self):
310310
w.scene().setFocusItem(None)
311311
self.assertEqual(workflow.annotations, [])
312312

313+
def test_quick_text_annotation_action(self):
314+
w = self.w
315+
workflow = w.scheme()
316+
edit_menu, *_ = w.menuBarActions()
317+
actions = edit_menu.menu().actions()
318+
action = action_by_name(actions, "new-quick-text-annotation-action")
319+
action.trigger()
320+
self.assertEqual(len(workflow.annotations), 1)
321+
322+
def test_quick_arrow_annotation_action(self):
323+
w = self.w
324+
workflow = w.scheme()
325+
edit_menu, *_ = w.menuBarActions()
326+
actions = edit_menu.menu().actions()
327+
action = action_by_name(actions, "new-quick-arrow-annotation-action")
328+
action.trigger()
329+
self.assertEqual(len(workflow.annotations), 1)
330+
313331
def test_path(self):
314332
w = self.w
315333
spy = QSignalSpy(w.pathChanged)

0 commit comments

Comments
 (0)