Example #1
0
 def getIcon(self, name):
     bfn = os.path.join(self.base_path, "icons", name)
     fn = bfn + ".svg"
     if os.path.isfile(fn):
         return Qt.QIcon(fn)
     fn = bfn + ".png"
     return Qt.QIcon(fn)
Example #2
0
def getIcon(name):
    bfn = os.path.join(config.base_dir, "icons", name)
    fn = bfn + ".svg"
    if os.path.isfile(fn):
        return Qt.QIcon(fn)
        fn = bfn + ".png"
    return Qt.QIcon(fn)
Example #3
0
    def insertImage(self, path, image=None):
        qurl = Qt.QUrl.fromLocalFile(path)
        url = qurl.toString()
        self.log.info("insertImage(): %s: %s", path, url)

        if not image:
            image = loadQImageFix(path)
            if not image:
                return

        qbaimage = Qt.QByteArray()
        qb = Qt.QBuffer(qbaimage)
        qb.open(Qt.QIODevice.WriteOnly)
        image.save(qb, 'PNG')
        del image
        qb.close()

        data = Qt.QByteArray()
        data.append(b'data:image/png;base64,')
        data.append(qbaimage.toBase64())
        qbaimage.clear()
        del qbaimage

        strdata = str(data, 'ascii')
        data.clear()
        del data

        imagef = Qt.QTextImageFormat()
        imagef.setName(strdata)

        cursor = self.editor.textCursor()
        cursor.insertImage(imagef)
        del imagef
Example #4
0
    def __init__(self, win, parent=None):
        super(QATTreeWidget, self).__init__(parent)
        self.setAcceptDrops(True)
        self.win = ref(win)

        self.menu = Qt.QMenu()
        i = 0
        for tag in TAGS_NAMES:
            i += 1
            callback = ObjectCallbackWrapperRef(self, 'on_contextmenu_tag',
                                                tag)
            Qt.QShortcut("CTRL+" + str(i), self, member=callback)
            MakeQAction(T("Tag: " + tag), self.menu, callback)

        # TODO: allow plugins to modify context menus

        self.menu.addSeparator()
        MakeQAction(T("Copy subtree"), self.menu, self.on_contextmenu_copy)

        self.menupaste = MakeQAction(T("Paste subtree"), self.menu,
                                     self.on_contextmenu_paste)
        self.menu.addSeparator()

        action = Qt.QAction(T("Remove subtree"), self.menu)
        action.triggered.connect(self.on_contextmenu_remove)
        self.menu.addAction(action)
Example #5
0
    def on_contextmenu_event(self, point):
        menu = Qt.QMenu()

        if self.model.rowCount() > 0:
            action = Qt.QAction(T("Insert row above"), menu)
            action.triggered.connect(
                ObjectCallbackWrapperRef(self, 'insertRowInPosition', 0))
            menu.addAction(action)

        action = Qt.QAction(T("Insert row below"), menu)
        action.triggered.connect(
            ObjectCallbackWrapperRef(self, 'insertRowInPosition', 1))
        menu.addAction(action)

        if self.model.columnCount() > 0:
            action = Qt.QAction(T("Insert column on the left"), menu)
            action.triggered.connect(
                ObjectCallbackWrapperRef(self, 'insertColInPosition', 0))
            menu.addAction(action)

        action = Qt.QAction(T("Insert column on the right"), menu)
        action.triggered.connect(
            ObjectCallbackWrapperRef(self, 'insertColInPosition', 1))
        menu.addAction(action)

        menu.exec_(self.editor.mapToGlobal(point))
        del menu
Example #6
0
    def __init__(self, win, project, *args):
        super(ProjectView, self).__init__(win, *args)
        self.win = ref(win)
        self.setAccessibleName(project.projectid)

        self.project = project

        self.log = logging.getLogger("at.project." + project.projectid)
        self.editors = dict()

        splitter = Qt.QSplitter()
        box = Qt.QVBoxLayout()
        tree = QATTreeWidget(self)

        tabs = Qt.QTabWidget()
        tabs.setTabsClosable(True)
        tabs.setMovable(True)
        tabs.tabCloseRequested.connect(self.on_tab_close_req)
        tabs.currentChanged.connect(self.on_tab_current_changed)

        splitter.addWidget(tree)
        splitter.addWidget(tabs)

        splitter.setStretchFactor(0, 0)
        splitter.setStretchFactor(1, 1)
        splitter.setSizePolicy(Qt.QSizePolicy.Expanding,
                               Qt.QSizePolicy.Expanding)

        tree.setColumnCount(TREE_COLUMN_COUNT)
        tree.setColumnHidden(TREE_COLUMN_UID, True)
        tree.setColumnHidden(TREE_COLUMN_TAGS, True)
        tree.setColumnWidth(TREE_COLUMN_ICON, TREE_COLUMN_ICON_WIDTH)
        tree.setRootIsDecorated(False)

        self.setLayout(box)
        self.buildToolbar()

        box.addWidget(self.toolbar)
        box.addWidget(splitter)

        tree.setHeaderHidden(True)
        tree.resizeColumnToContents(TREE_COLUMN_ICON)
        tree.setDragDropMode(Qt.QAbstractItemView.InternalMove)
        tree.setAcceptDrops(True)
        tree.setAutoScroll(True)

        root = tree.invisibleRootItem()
        tree.itemSelectionChanged.connect(self.on_tree_item_selection)
        tree.itemChanged.connect(self.on_tree_item_changed)

        self.setGeometry(50, 50, 1440, 800)

        self.tabs = tabs
        self.root = root
        self.tree = tree
        # self.tree.setSortingEnabled(True)
        # self.tree.sortByColumn(0, QtCore.Qt.Qt_)

        self.ready = True
        self.treeready = False
Example #7
0
    def getImage(self, docid, name):
        localname = resourceNameToLocal(name, ext='.png')
        path = self.localImageNamePath(docid, localname)

        self.log.info("getImage(): %s: %s: %s", docid, name, path)

        try:
            f = Qt.QFile(path)
            if not f.open(Qt.QFile.ReadOnly):
                self.log.error("getImage(): could not open file: %s", path)
                return None

            data = f.readAll()
            f.close()
            del f

            image = Qt.QPixmap()
            image.loadFromData(data)
            data.clear()
            del data
            return image
        except Exception as e:
            self.log.error("getImage(): exception: %s: %s: %s", path,
                           e.__class__.__name__, e)

        return None
Example #8
0
def getIconPixmap(name):
    bfn = os.path.join(config.base_dir, "icons", name)
    fn = bfn + ".svg"
    if os.path.isfile(fn):
        return Qt.QPixmap(fn, "SVG")

    fn = bfn + ".png"
    return Qt.QPixmap(fn, "PNG")
Example #9
0
 def insertText(self, s, cursor=None):
     if not cursor:
         cursor = self.textCursor()
     cursor = Qt.QTextCursor(cursor)
     _cformat = cursor.charFormat()
     font = _cformat.font()
     _format = Qt.QTextCharFormat()
     _format.setFont(font)
     cursor.insertText(s, _format)
Example #10
0
    def __init__(self, win, project, docid, docname):
        Qt.QWidget.__init__(self)
        self.project = project
        self.log = logging.getLogger("at.editor")
        self.win = ref(win)
        self.ignorechanges = False

        self.docid = docid
        self.docname = docname

        self.buildToolbar()

        h1 = Qt.QVBoxLayout()
        splitter = Qt.QSplitter()

        self.setLayout(h1)
        h1.addWidget(self.toolbar)
        h1.addWidget(splitter)

        self.editor = self.createEditorWidget()
        # self.loadEditor()

        self.elements = None
        self.elementsroot = None

        # elements = Qt.QTreeWidget(self)
        # # elements.setMaximumWidth(200)
        # # elements.setFixedWidth(200)
        # # elements.setMinimumWidth(100)
        # elements.setBaseSize(100, 100)
        # elements.adjustSize()
        # # elements.setSizePolicy(Qt.QSizePolicy.MinimumExpanding,Qt.QSizePolicy.MinimumExpanding)
        #
        # # elements.setFixedWidth(200)
        # elements.setHeaderHidden(True)
        # elementsroot = elements.invisibleRootItem()
        #
        # elementstype = Qt.QTreeWidgetItem(elementsroot, [T("Attachements"), "attachements"])
        # elementstype.setIcon(0, getIcon("attachments"))
        # elementstype.setExpanded(True)
        #
        # elementstype = Qt.QTreeWidgetItem(elementsroot, [T("Images"), "images"])
        # elementstype.setIcon(0, getIcon("attachments"))
        # elementstype.setExpanded(True)
        #
        # self.elements = elements
        # self.elementsroot = elementsroot

        # self._addElement("attachements", "somefile")

        splitter.addWidget(self.editor)
        # splitter.addWidget(self.elements)
        splitter.setStretchFactor(0, 2)
        # splitter.setStretchFactor(1, 0)

        # TODO: should accessibleName be used?
        self.setAccessibleName(docid)
Example #11
0
    def __init__(self, win, title, name, w, h):
        super(ImageResizeDialog, self).__init__(win)
        self.w = w
        self.h = h
        self.keepaspect = True
        self.aspect = float(w) / float(h)
        self.result = False

        self.setWindowTitle(title)
        self.vbox = Qt.QVBoxLayout(self)
        self.vbox.addWidget(Qt.QLabel(T(name)))

        self.box = Qt.QGroupBox(self)
        self.form = Qt.QFormLayout(self.box)

        buttonbox = Qt.QDialogButtonBox()
        buttonbox.setGeometry(Qt.QRect(150, 250, 341, 32))
        buttonbox.setOrientation(QtCore.Qt.Horizontal)
        buttonbox.setStandardButtons(Qt.QDialogButtonBox.Cancel | Qt.QDialogButtonBox.Ok)
        buttonbox.setWindowTitle(title)

        self.vbox.addWidget(self.box)
        self.vbox.addWidget(buttonbox)
        self.vbox.setStretch(2, 0)

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        # self.setWindowModality(QtCore.QCoreApplication)
        self.setModal(True)

        self.ww = Qt.QSpinBox()
        self.ww.setMinimum(16)
        self.ww.setMaximum(0xffff)
        self.ww.setValue(self.w)
        self.ww.valueChanged.connect(self.on_changed_width)
        self.form.addRow(T("Width"), self.ww)

        self.ww.setFocus()

        self.wh = Qt.QSpinBox()
        self.ww.setMinimum(16)
        self.wh.setMaximum(0xffff)
        self.wh.setValue(self.h)
        self.wh.valueChanged.connect(self.on_changed_height)
        self.form.addRow(T("Height"), self.wh)

        widget = Qt.QCheckBox()
        widget.setChecked(True)
        widget.stateChanged.connect(self.on_changed_aspect)
        self.form.addRow(T("Keep aspect"), widget)

        buttonbox.accepted.connect(self.on_accept)
        buttonbox.rejected.connect(self.on_reject)
        # QtCore.QMetaObject.connectSlotsByName(Dialog)
        self.adjustSize()
        self.setMinimumWidth(600)
        self.setSizePolicy(Qt.QSizePolicy.MinimumExpanding, Qt.QSizePolicy.MinimumExpanding)
Example #12
0
    def loadResourceRemote(self, url):
        # TODO: show wait/progress dialog/info
        try:
            ret = requests.get(url)
            if ret.status_code not in (200,):
                return None

            data = Qt.QByteArray(ret.content)
            image = Qt.QPixmap()
            image.loadFromData(data)
            data.clear()
            return image
        except Exception as e:
            self.log.error("Failed to retrive remote image: %s: %s", e.__class__.__name__, e)
Example #13
0
    def loadResource(self, p_int, _qurl):
        url = _qurl.toString()
        if url.startswith('data:image/'):
            return super(RTDocument, self).loadResource(p_int, _qurl)

        self.editor.log.info("loadResource(): %s", url)
        scheme = _qurl.scheme()
        image = self.editor.project.doc.getImage(self.docid, url)
        if image:
            self.editor.doc.addResource(Qt.QTextDocument.ImageResource, _qurl, image)
            return image

        if scheme:
            if scheme in ('http', 'https'):
                self.editor.log.info("Trying retrive remote image: %s", url)
                # remote image get it from network
                image = self.loadResourceRemote(url)
                if image:
                    self.editor.doc.addResource(Qt.QTextDocument.ImageResource, _qurl, image)
                return image

            if scheme == 'file':
                try:

                    filename = Qt.QDir.toNativeSeparators(_qurl.toLocalFile())
                    self.editor.log.info("Trying retrive local image: %s", filename)
                    f = Qt.QFile(filename)
                    if not f.open(Qt.QFile.ReadOnly):
                        self.log.error("loadResource(): could not open file: %s", url)
                        return self.loadResourceMissing(_qurl)

                    data = f.readAll()
                    f.close()
                    del f

                    image = Qt.QPixmap()
                    image.loadFromData(data)
                    data.clear()
                    del data
                    if image:
                        self.editor.doc.addResource(Qt.QTextDocument.ImageResource, _qurl, image)
                    return image
                except Exception as e:
                    self.log.error("Failed to load image: %s: %s", e.__class__.__name__, e)

        res = super(RTDocument, self).loadResource(p_int, _qurl)
        if res:
            return res

        return self.loadResourceMissing(_qurl)
Example #14
0
    def save(self, *args):
        docid, editor = self.getCurrentEditor()
        self.log.info("save(): %s", docid)

        if not editor:
            # TODO: notify about desync/fail?
            return None

        # first getimages, couse this method can change body settings
        images = editor.getImages()
        imageslocal = []
        body = editor.getBody()
        # save images
        for res in images:
            if res.startswith('data:image/'):
                # ignore inline encoded images
                continue
            url = Qt.QUrl()
            url.setUrl(res)
            resobj = editor.doc.resource(Qt.QTextDocument.ImageResource, url)

            localname = self.project.doc.putImage(docid, res, resobj)
            if localname:
                imageslocal.append(localname)

        self.project.doc.putDocumentBody(docid, body)
        self.project.doc.clearImagesOld(docid, imageslocal)
        editor.setModified(False)
Example #15
0
 def projectAdd(self, projectid):
     project = self.projects.open(projectid)
     if not project:
         return
     action = Qt.QAction(project.name, self)
     action.triggered.connect(ObjectCallbackWrapperRef(self, 'on_menu_project', projectid))
     self.menuprojects.addAction(action)
Example #16
0
    def addDocumentTree(self, docid, name, parent, meta={}):
        if parent:
            # TODO: find parent in tree
            parent = self.treeFindDocument(parent)
        else:
            parent = self.tree.invisibleRootItem()

        tags = meta.get('tags') or ""
        tags = [t.strip() for t in tags.split(",") if t]

        columns = [None] * TREE_COLUMN_COUNT
        columns[TREE_COLUMN_NAME] = name
        columns[TREE_COLUMN_UID] = docid

        item = Qt.QTreeWidgetItem(parent, columns)
        # item.setFirstColumnSpanned(True)
        item.setText(TREE_COLUMN_NAME, name)
        item.setText(TREE_COLUMN_UID, docid)
        item.setText(TREE_COLUMN_TAGS, "")
        item.setIcon(TREE_COLUMN_NAME, getIcon("icon-document-default"))
        item.setExpanded(True)
        item.setFlags(TREE_ITEM_FLAGS)

        self.tagDocuemntTree(treeitem=item, addtags=tags)

        self.tree.resizeColumnToContents(TREE_COLUMN_NAME)
        self.tree.resizeColumnToContents(TREE_COLUMN_ICON)
        return item
Example #17
0
    def createEditorWidget(self):
        self.editor = Qt.QPlainTextEdit(parent=self)
        # self.editor.cursorPositionChanged.connect(self.on_cursor_possition_changed)
        # self.doc = Qt.QTextDocument(self)

        self.load(draft=True)

        font = Qt.QFont("Courier")
        font.setPointSize(14)
        self.editor.setFont(font)

        # self.connect(self.editor, Qt.SIGNAL("textChanged()"), self.on_text_changed)
        self.editor.textChanged.connect(self.on_text_changed)
        # self.editor.contextMenuEventSingal.connect(self.on_contextmenu_event)

        return self.editor
Example #18
0
    def on_fontsizeselection_change(self, size):
        if self.ignorechanges:
            return

        _format = Qt.QTextCharFormat()
        _format.setFontPointSize(size)
        self.editor.mergeCurrentCharFormat(_format)
        self.editor.setFontPointSize(size)
Example #19
0
    def insertLink(self, url, cursor=None, addSpace=True):
        if not cursor:
            cursor = self.textCursor()
        cursor = Qt.QTextCursor(cursor)
        _cformat = cursor.charFormat()
        font = _cformat.font()
        _format = Qt.QTextCharFormat()
        _format.setFont(font)
        _format.setUnderlineStyle(1)
        _format.setForeground(QtCore.Qt.blue)
        _format.setAnchor(True)
        _format.setAnchorHref(url)

        cursor.insertText(url, _format)
        if addSpace:
            _format = Qt.QTextCharFormat()
            _format.setFont(font)
            cursor.insertText(" ", _format)
Example #20
0
    def __init__(self):
        super(AppleTreeMainWindow, self).__init__()
        self.setWindowIcon(getIcon('app'))
        self.log = logging.getLogger("at")
        self.projects = Projects()
        self.setWindowTitle("AppleTree (Qt " + Qt.QT_VERSION_STR + ")")

        self.menubar = Qt.QMenuBar()
        self.toolbar = Toolbar(self)

        self.menuprojects = self.menubar.addMenu("Projects")
        self.menuproject = self.menubar.addMenu("Project")
        self.menuplugins = self.menubar.addMenu("Plugins")

        self.plugins = ATPlugins(self)
        self.plugins.discovery()

        self.projects = Projects()
        self.projectsViews = dict()

        self.buildMenuProject()
        self.buildToolbar()

        self.setGeometry(50, 50, 1440, 800)
        box = Qt.QVBoxLayout()
        centralwidget = Qt.QWidget()
        centralwidget.setLayout(box)

        self.tabs = Qt.QTabWidget()
        self.tabs.setTabsClosable(True)
        self.tabs.tabCloseRequested.connect(self.on_tab_close_req)
        # tabs.currentChanged.connect(self.on_tab_current_changed)

        box.addWidget(self.toolbar)
        box.addWidget(self.tabs)

        self.setCentralWidget(centralwidget)
        self.setMenuBar(self.menubar)

        self.plugins.initialize()
        self.ready = True
        self.treeready = False

        self.load()
Example #21
0
    def buildToolbarLocal(self):
        self.fontselection = Qt.QFontComboBox(self.toolbar)
        self.fontselection.currentFontChanged.connect(self.on_fontselection_change)

        self.fontsizeselection = Qt.QSpinBox(self.toolbar)
        self.fontsizeselection.setMinimum(4)
        self.fontsizeselection.setMaximum(32)
        self.fontsizeselection.setValue(14)
        self.fontsizeselection.valueChanged.connect(self.on_fontsizeselection_change)

        self.toolbar.addWidget(self.fontselection)
        self.toolbar.addWidget(self.fontsizeselection)
        self.toolbar.addButtonObjectAction(self, "format-justify-left", getIcon('format-justify-left'))
        self.toolbar.addButtonObjectAction(self, "format-justify-center", getIcon('format-justify-center'))
        self.toolbar.addButtonObjectAction(self, "format-justify-right", getIcon('format-justify-right'))

        self.toolbar.addSeparator()
        self.toolbar.addButtonObjectAction(self, 'insert-image', getIcon('image-insert'), desc='Insert image',
                                           shortcut='CTRL+SHIFT+I')
Example #22
0
    def __init__(self, win, title, image):
        super(ImageViewDialog, self).__init__(win)
        self.setWindowTitle(title)
        vbox = Qt.QVBoxLayout(self)
        scrollarea = Qt.QScrollArea(self)
        scrollarea.setWidgetResizable(True)

        label = Qt.QLabel(self)
        label.setAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignHCenter)
        if image.__class__.__name__ == 'QImage':
            pixmap = Qt.QPixmap()
            pixmap.fromImage(image)
        else:
            pixmap = image

        label.setPixmap(pixmap)

        scrollarea.setWidget(label)
        vbox.addWidget(scrollarea)
        self.setSizePolicy(Qt.QSizePolicy.MinimumExpanding, Qt.QSizePolicy.MinimumExpanding)
Example #23
0
    def _add(self, name, icon, shortcut, callback):
        if icon.__class__.__name__ != "QIcon":
            _icon = getIcon(icon)
        else:
            _icon = icon

        a = Qt.QAction(_icon, name, self.win())
        a.triggered.connect(callback)
        if shortcut:
            a.setShortcut(shortcut)
        self.addAction(a)
Example #24
0
 def __init__(self, win, cancelcb=None, *args):
     super(ProgressDialog, self).__init__(parent=win)
     self.setModal(True)
     self.setLabelText("Please wait...")
     self.cancelcb = cancelcb
     self.setRange(0, 100)
     self.setAutoClose(False)
     self.setAutoReset(False)
     self._cancebutton = Qt.QPushButton(self)
     self._cancebutton.setText("Cancel")
     self.setCancelButton(self._cancebutton)
Example #25
0
    def on_plugin_menu(self):
        msg = Qt.QMessageBox()
        msg.setIcon(Qt.QMessageBox.Information)

        msg.setText("Plugin Test")
        msg.setInformativeText("You just clicked my plugin's menu item? ;-)")
        msg.setWindowTitle("Plugin Test")
        msg.setDetailedText("AppleTree is awsome!")
        msg.setStandardButtons(Qt.QMessageBox.Ok)
        # msg.buttonClicked.connect(msgbtn)

        msg.exec_()
Example #26
0
    def __init__(self, win, title, name):
        super(ATPreferencesDialog, self).__init__(win)

        self.fields = {}
        self.result = False

        self.setWindowTitle(title)
        self.vbox = Qt.QVBoxLayout(self)
        self.vbox.addWidget(Qt.QLabel(T(name)))

        self.box = Qt.QGroupBox(self)
        self.form = Qt.QFormLayout(self.box)

        buttonbox = Qt.QDialogButtonBox()
        buttonbox.setGeometry(Qt.QRect(150, 250, 341, 32))
        buttonbox.setOrientation(QtCore.Qt.Horizontal)
        buttonbox.setStandardButtons(Qt.QDialogButtonBox.Cancel
                                     | Qt.QDialogButtonBox.Ok)
        buttonbox.setObjectName("buttonBox")
        buttonbox.setWindowTitle(title)

        self.vbox.addWidget(self.box)
        self.vbox.addWidget(buttonbox)
        self.vbox.setStretch(2, 0)

        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        # self.setWindowModality(Qt.ApplicationModal)

        buttonbox.accepted.connect(self.on_accept)
        buttonbox.rejected.connect(self.on_reject)
        # QtCore.QMetaObject.connectSlotsByName(Dialog)
        self.adjustSize()
        self.setMinimumWidth(600)
        self.setSizePolicy(Qt.QSizePolicy.MinimumExpanding,
                           Qt.QSizePolicy.MinimumExpanding)
Example #27
0
    def _addElement(self, _type, name):
        if not _type:
            return None

        parent = self._findElement(_type) or self.elementsroot
        if not parent:
            return None

        item = Qt.QTreeWidgetItem(parent, [
            name,
            "something",
        ])
        item.setIcon(0, getIcon("attachment"))
Example #28
0
    def createEditorWidget(self):
        self.editor = Qt.QTableView(parent=self)
        self.model = Qt.QStandardItemModel(self.editor)
        self.model.itemChanged.connect(self.on_item_changed)
        self.editor.setModel(self.model)
        self.editor.setItemDelegate(Qt.QItemDelegate(self.editor))

        docbody = self.project.doc.getDocumentBodyDraft(self.docid)
        if docbody is None:
            docbody = self.project.doc.getDocumentBody(self.docid)
            draft = False
        else:
            draft = True

        self.putBody(docbody)
        self.setModified(draft)

        self.editor.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.editor.customContextMenuRequested.connect(
            self.on_contextmenu_event)

        return self.editor
Example #29
0
    def on_contextmenu_event(self, event):
        pos = event.pos()
        if not pos:
            return
        cursor = self.editor.cursorForPosition(pos)
        if not cursor:
            return

        self.cursorpos = pos
        menu = self.editor.createStandardContextMenu()

        menu.addSeparator()
        charformat = cursor.charFormat()
        if charformat.isImageFormat():
            # TODO: allow plugins to modify context menus
            action = Qt.QAction(T("View image in original size"), menu)
            action.triggered.connect(self.on_contextmenu_imageview)
            menu.addAction(action)

            action = Qt.QAction(T("Resize image"), menu)
            action.triggered.connect(self.on_contextmenu_imageresize)
            menu.addAction(action)

            action = Qt.QAction(T("Copy image"), menu)
            action.triggered.connect(self.on_contextmenu_imagecopy)
            menu.addAction(action)

        clipboard = Qt.QApplication.clipboard()
        image = clipboard.image()
        if image and not image.isNull():
            del image
            action = Qt.QAction(T("Paste image"), menu)
            action.triggered.connect(self.on_contextmenu_imagepaste)
            menu.addAction(action)

        menu.exec_(event.globalPos())
        del menu
        self.cursorpos = None
Example #30
0
    def on_toolbar_insert_image(self, *args):
        dialog = Qt.QFileDialog()
        dialog.setFileMode(Qt.QFileDialog.AnyFile)
        dialog.setNameFilters([
            "Images JPEG/PNG/TIFF (*.png *.jpg *.jpeg *.tiff)",
        ])

        if not dialog.exec_():
            return

        filenames = dialog.selectedFiles()

        for fn in filenames:
            self.insertImage(fn)