Ejemplo n.º 1
0
    def __init__(self, parent, pos, name):
        """ Creates a context menu for the given QPoint (in widget coordinates).
        """
        super(ImageContextMenu, self).__init__(parent)

        self.addAction("Copy Image", lambda: copy_image(parent, name))
        self.addAction("Save Image As...", lambda: save_image(parent, name))
        self.addSeparator()

        svg = parent.name_to_svg_map.get(name, None)
        if svg is not None:
            self.addSeparator()
            self.addAction("Copy SVG", lambda: svg_to_clipboard(svg))
            self.addAction("Save SVG As...", lambda: save_svg(svg, parent))
Ejemplo n.º 2
0
    def _context_menu_make(self, pos):
        """ Reimplemented to return a custom context menu for images.
        """
        format = self._control.cursorForPosition(pos).charFormat()
        name = format.stringProperty(QtGui.QTextFormat.ImageName)
        if name:
            menu = QtWidgets.QMenu(self)

            menu.addAction('Copy Image', lambda: self._copy_image(name))
            menu.addAction('Save Image As...', lambda: self._save_image(name))
            menu.addSeparator()

            svg = self._name_to_svg_map.get(name, None)
            if svg is not None:
                menu.addSeparator()
                menu.addAction('Copy SVG', lambda: svg_to_clipboard(svg))
                menu.addAction('Save SVG As...',
                               lambda: save_svg(svg, self._control))
        else:
            menu = super()._context_menu_make(pos)
        return menu
Ejemplo n.º 3
0
    def _context_menu_make(self, pos):
        """ Reimplemented to return a custom context menu for images.
        """
        format = self._control.cursorForPosition(pos).charFormat()
        name = format.stringProperty(QtGui.QTextFormat.ImageName)
        if name:
            menu = QtGui.QMenu()

            menu.addAction('Copy Image', lambda: self._copy_image(name))
            menu.addAction('Save Image As...', lambda: self._save_image(name))
            menu.addSeparator()

            svg = self._name_to_svg_map.get(name, None)
            if svg is not None:
                menu.addSeparator()
                menu.addAction('Copy SVG', lambda: svg_to_clipboard(svg))
                menu.addAction('Save SVG As...',
                               lambda: save_svg(svg, self._control))
        else:
            menu = super(RichJupyterWidget, self)._context_menu_make(pos)
        return menu