Skip to content

Commit ef62ee4

Browse files
committed
canvas/annotations: Change context menu
1 parent b188589 commit ef62ee4

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

Orange/canvas/canvas/items/annotationitem.py

+33-12
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from AnyQt.QtWidgets import (
1010
QGraphicsItem, QGraphicsPathItem, QGraphicsWidget, QGraphicsTextItem,
11-
QGraphicsDropShadowEffect, QMenu
11+
QGraphicsDropShadowEffect, QMenu, QAction, QActionGroup
1212
)
1313
from AnyQt.QtGui import (
1414
QPainterPath, QPainterPathStroker, QPolygonF, QColor, QPen
@@ -496,20 +496,41 @@ def contextMenuEvent(self, event):
496496
if event.modifiers() & Qt.AltModifier:
497497
menu = QMenu(event.widget())
498498
menu.setAttribute(Qt.WA_DeleteOnClose)
499+
formatmenu = menu.addMenu("Render as")
500+
group = QActionGroup(self, exclusive=True)
501+
502+
def makeaction(text, parent, data=None, **kwargs):
503+
action = QAction(text, parent, **kwargs)
504+
if data is not None:
505+
action.setData(data)
506+
return action
507+
508+
formatactions = [
509+
makeaction("Plain Text", group, checkable=True,
510+
toolTip=self.tr("Render contents as plain text"),
511+
data="text/plain"),
512+
makeaction("HTML", group, checkable=True,
513+
toolTip=self.tr("Render contents as HTML"),
514+
data="text/html"),
515+
makeaction("RST", group, checkable=True,
516+
toolTip=self.tr("Render contents as RST "
517+
"(reStructuredText)"),
518+
data="text/rst"),
519+
makeaction("Markdown", group, checkable=True,
520+
toolTip=self.tr("Render contents as Markdown"),
521+
data="text/markdown")
522+
]
523+
for action in formatactions:
524+
action.setChecked(action.data() == self.__contentType.lower())
525+
formatmenu.addAction(action)
499526

500-
menu.addAction("text/plain")
501-
menu.addAction("text/markdown")
502-
menu.addAction("text/rst")
503-
menu.addAction("text/html")
504-
505-
for action in menu.actions():
506-
action.setCheckable(True)
507-
action.setChecked(action.text() == self.__contentType.lower())
508-
509-
@menu.triggered.connect
510527
def ontriggered(action):
511-
self.setContent(self.content(), action.text())
528+
mimetype = action.data()
529+
content = self.content()
530+
self.setContent(content, mimetype)
531+
self.editingFinished.emit()
512532

533+
menu.triggered.connect(ontriggered)
513534
menu.popup(event.screenPos())
514535
event.accept()
515536
else:

0 commit comments

Comments
 (0)