From ef62ee4d8273a3142bdcdc02df6aff1e111089d7 Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Tue, 8 Nov 2016 12:50:55 +0100 Subject: [PATCH] canvas/annotations: Change context menu --- Orange/canvas/canvas/items/annotationitem.py | 45 ++++++++++++++------ 1 file changed, 33 insertions(+), 12 deletions(-) diff --git a/Orange/canvas/canvas/items/annotationitem.py b/Orange/canvas/canvas/items/annotationitem.py index 9bef333cfff..c4ff6d2b783 100644 --- a/Orange/canvas/canvas/items/annotationitem.py +++ b/Orange/canvas/canvas/items/annotationitem.py @@ -8,7 +8,7 @@ from AnyQt.QtWidgets import ( QGraphicsItem, QGraphicsPathItem, QGraphicsWidget, QGraphicsTextItem, - QGraphicsDropShadowEffect, QMenu + QGraphicsDropShadowEffect, QMenu, QAction, QActionGroup ) from AnyQt.QtGui import ( QPainterPath, QPainterPathStroker, QPolygonF, QColor, QPen @@ -496,20 +496,41 @@ def contextMenuEvent(self, event): if event.modifiers() & Qt.AltModifier: menu = QMenu(event.widget()) menu.setAttribute(Qt.WA_DeleteOnClose) + formatmenu = menu.addMenu("Render as") + group = QActionGroup(self, exclusive=True) + + def makeaction(text, parent, data=None, **kwargs): + action = QAction(text, parent, **kwargs) + if data is not None: + action.setData(data) + return action + + formatactions = [ + makeaction("Plain Text", group, checkable=True, + toolTip=self.tr("Render contents as plain text"), + data="text/plain"), + makeaction("HTML", group, checkable=True, + toolTip=self.tr("Render contents as HTML"), + data="text/html"), + makeaction("RST", group, checkable=True, + toolTip=self.tr("Render contents as RST " + "(reStructuredText)"), + data="text/rst"), + makeaction("Markdown", group, checkable=True, + toolTip=self.tr("Render contents as Markdown"), + data="text/markdown") + ] + for action in formatactions: + action.setChecked(action.data() == self.__contentType.lower()) + formatmenu.addAction(action) - menu.addAction("text/plain") - menu.addAction("text/markdown") - menu.addAction("text/rst") - menu.addAction("text/html") - - for action in menu.actions(): - action.setCheckable(True) - action.setChecked(action.text() == self.__contentType.lower()) - - @menu.triggered.connect def ontriggered(action): - self.setContent(self.content(), action.text()) + mimetype = action.data() + content = self.content() + self.setContent(content, mimetype) + self.editingFinished.emit() + menu.triggered.connect(ontriggered) menu.popup(event.screenPos()) event.accept() else: