示例#1
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
示例#2
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)
示例#3
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)
示例#4
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)
示例#5
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
示例#6
0
    def load(self, name):
        self.log.info("Load: %s", name)
        mod, err = self._load(name)

        plugin_base_path = os.path.join(config.base_dir, "appletree",
                                        "plugins", name)

        obj = mod.FACTORY(self.win, plugin_base_path)
        pname = obj.name
        fname = obj.friendly_name
        self.plugins.append(obj)
        self.log.info("Ready: %s: %s: %s", name, pname, fname)
        win = self.win()
        if not win:
            return

        action = Qt.QAction(fname, win)
        action.setStatusTip("Plugin " + fname)
        action.triggered.connect(obj.on_plugin_menu)
        win.menuplugins.addAction(action)
示例#7
0
 def addShortcut(self, shortcut, callback):
     action = Qt.QAction(self)
     action.setShortcut(shortcut)
     action.triggered.connect(callback)
     self.addAction(action)
示例#8
0
def MakeQAction(name, parent, callback):
    action = Qt.QAction(name, parent)
    if callback:
        action.triggered.connect(callback)
    parent.addAction(action)
    return action
示例#9
0
 def addButton(self, name, icon, callback, shortcut=None):
     button = Qt.QAction(icon, name, self.win())
     if shortcut:
         button.setShortcut(shortcut)
     button.triggered.connect(callback)
     self.addAction(button)