Example #1
0
    def button_menu(self, event, bm, but, up=False):
        """button_menu - handle a button being right-clicked

        :Parameters:
        - `event`: QPushButton event
        - `bm`: Bookmark associated with button
        - `but`: button widget
        """

        menu = QtWidgets.QMenu()

        actions = [
            ("Link bookmark to this node", self.update_bookmark),
            ("Re-name bookmark", self.rename_bookmark),
            ("Edit bookmark in tree", self.edit_bookmark),
            ("Delete bookmark", self.delete_bookmark),
            ("Add this node as child bookmark", self.add_child_bookmark),
        ]
        for action in actions:
            # pylint: disable=cell-var-from-loop
            act = QtWidgets.QAction(action[0], menu)
            act.triggered.connect(lambda checked, bm=bm, f=action[1]: f(bm))
            menu.addAction(act)

        def follow(checked, bm=bm, manager=self):
            manager.current = bm.v
            manager.second = True
            manager.upwards = False
            manager.show_list(manager.get_list(), up=False)

        act = QtWidgets.QAction("Show child bookmarks", menu)
        act.triggered.connect(follow)
        menu.addAction(act)

        menu.exec_(but.mapToGlobal(event.pos()))
Example #2
0
 def makeButtons(self):
     ib_w = self.c.frame.iconBar.w
     if not ib_w: return  # EKR: can be None when unit testing.
     icon_l = ib_w.style().standardIcon(QtWidgets.QStyle.SP_ArrowLeft)
     icon_r = ib_w.style().standardIcon(QtWidgets.QStyle.SP_ArrowRight)
     act_l = QtWidgets.QAction(icon_l, 'prev', ib_w)
     act_r = QtWidgets.QAction(icon_r, 'next', ib_w)
     # act_l.connect(act_l, QtCore.SIGNAL("triggered()"), self.clickPrev)
     # act_r.connect(act_r, QtCore.SIGNAL("triggered()"), self.clickNext)
     act_l.triggered.connect(self.clickPrev)
     act_r.triggered.connect(self.clickNext)
     self.c.frame.iconBar.add(qaction=act_l, command=self.clickPrev)
     self.c.frame.iconBar.add(qaction=act_r, command=self.clickNext)
Example #3
0
    def misc_menu(self):
        """build menu on Action button"""

        # info needed to separate edit and view widgets in self.widget_classes
        name_test_current = [
            ("Editor", lambda x: x.lep_type == 'EDITOR',
             self.edit_widget.__class__),
            ("Viewer", lambda x: x.lep_type != 'EDITOR',
             self.view_widget.__class__),
        ]

        menu = QtWidgets.QMenu()
        for name, is_one, current in name_test_current:
            # list Editor widgets, then Viewer widgets
            for widget_class in [i for i in self.widget_classes if is_one(i)]:

                def cb(checked, widget_class=widget_class):
                    self.set_widget(widget_class=widget_class)

                act = QtWidgets.QAction(
                    "%s: %s" % (name, widget_class.lep_name), self)
                act.setCheckable(True)
                act.setChecked(widget_class == current)
                act.triggered.connect(cb)
                menu.addAction(act)
        menu.exec_(self.mapToGlobal(self.control_menu_button.pos()))
Example #4
0
    def makeButtons(self):

        c = self.c
        w = c.frame.iconBar.w
        if not w: return # EKR: can be None when unit testing.

        icon_l = w.style().standardIcon(QtWidgets.QStyle.SP_ArrowLeft)
        icon_r = w.style().standardIcon(QtWidgets.QStyle.SP_ArrowRight)

        act_l = QtWidgets.QAction(icon_l,'prev',w)
        act_r = QtWidgets.QAction(icon_r,'next',w)

        # 2011/04/02: Use the new commands.
        act_l.triggered.connect(lambda checked: c.goToPrevHistory())
        act_r.triggered.connect(lambda checked: c.goToNextHistory())

        # 2011/04/02: Don't execute the command twice.
        self.c.frame.iconBar.add(qaction = act_l) #, command = self.clickPrev)
        self.c.frame.iconBar.add(qaction = act_r) #, command = self.clickNext)
Example #5
0
    def mode_menu(self):
        """build menu on Action button"""
        menu = QtWidgets.QMenu()

        for mode in 'edit', 'view', 'split':
            act = QtWidgets.QAction(mode.title(), self)
            def cb(checked, self=self, mode=mode):
                self.set_mode(mode)
            act.triggered.connect(cb)
            act.setCheckable(True)
            act.setChecked(mode == self.mode)
            menu.addAction(act)
        menu.exec_(self.mapToGlobal(self.btn_mode.pos()))
Example #6
0
    def context_menu(self, event):
        """context_menu
        """

        menu = QtWidgets.QMenu()
        bm = self.c._bookmarks

        actions = [
            ("Edit bookmarks in tree", self.edit_bookmark),
            ("Add bookmark folder",
             lambda e: cmd_bookmark_organizer(event={'c': bm.v.context})),
        ]
        for action in actions:
            # pylint: disable=cell-var-from-loop
            # pylint: disable=undefined-variable
            # weird: bm clearly *is* defined.
            act = QtWidgets.QAction(action[0], menu)
            act.triggered.connect(lambda checked, bm=bm, f=action[1]: f(bm))
            menu.addAction(act)

        menu.exec_(self.w.mapToGlobal(event.pos()))
Example #7
0
    def popup(self, c, p, menu):
        """make popup menu entry for tree context menu"""
        # pylint: disable=function-redefined
        # several callbacks have the same name.
        if c != self.c:
            return  # wrong commander
        for cb, name in reversed(self.recent_moves):
            a = QtWidgets.QAction(name, menu)
            a.triggered.connect(
                lambda checked, cb=cb, name=name: self.do_wrap(cb, name))
            menu.insertAction(menu.actions()[0], a)
        pathmenu = menu.addMenu("Move")
        # copy / cut to other outline
        cut = None
        for txt, cut in ("Copy to...", False), ("Move to...", True):
            sub = pathmenu.addMenu(txt)
            # global targets
            for target in g.app.db['_quickmove']['global_targets']:
                a = sub.addAction(target['name'])

                def cb(c2=target['unl'], cut=cut):
                    self.to_other(c2, cut=cut)

                def wrap(checked,
                         cb=cb,
                         name=txt.strip('.') + ' ' + target['name']):
                    self.do_wrap(cb, name)

                a.triggered.connect(wrap)
            # top of open outlines
            for c2 in g.app.commanders():
                a = sub.addAction("Top of " +
                                  g.os_path_basename(c2.fileName()))

                def cb(c2=c2, cut=cut):
                    self.to_other(c2, cut=cut)

                def wrap(checked,
                         cb=cb,
                         name=txt.strip('.') + ' top of ' +
                         g.os_path_basename(c2.fileName())):
                    self.do_wrap(cb, name)

                a.triggered.connect(wrap)
        # bookmark to other outline
        sub = pathmenu.addMenu("Bookmark to...")
        # global targets
        for target in g.app.db['_quickmove']['global_targets']:
            a = sub.addAction(target['name'])

            def cb(c2=target['unl'], cut=cut):
                self.bookmark_other(c2)

            def wrap(checked, cb=cb, name="Bookmark to " + target['name']):
                self.do_wrap(cb, name)

            a.triggered.connect(wrap)
        # top of open outlines
        for c2 in g.app.commanders():
            a = sub.addAction(g.os_path_basename(c2.fileName()))

            def cb(c2=c2):
                self.bookmark_other(c2)

            def wrap(checked,
                     cb=cb,
                     name="Bookmark to top of " +
                     g.os_path_basename(c2.fileName())):
                self.do_wrap(cb, name)

            a.triggered.connect(wrap)
        # actions within this outline
        need_submenu = 'Move', 'Copy', 'Clone', 'Bookmark', 'Link'
        current_kind = None
        current_submenu = None
        for name, dummy, command in self.local_imps:
            kind = name.split()[0]
            if kind in need_submenu:
                if current_kind != kind:
                    current_submenu = pathmenu.addMenu(kind)
                    current_kind = kind
            else:
                current_submenu = pathmenu
            a = current_submenu.addAction(name)
            a.triggered.connect(lambda checked, command=command: command())
        # add new global target, etc.
        a = pathmenu.addAction("Add node as target")
        a.triggered.connect(lambda checked, p=p: self.add_target(p))
        a = pathmenu.addAction("Show targets")
        a.triggered.connect(lambda checked, p=p: self.show_targets())
        a = pathmenu.addAction("Read targets")
        a.triggered.connect(lambda checked, p=p: self.read_targets())
Example #8
0
    def addButton(self, which, type_="move", v=None, parent=None):
        '''Add a button that creates a target for future moves.'''
        c = self.c
        p = c.p
        if v is None:
            v = p.v
        sc = scriptingController(c)
        mb = quickMoveButton(self, v, which, type_=type_)
        txt = self.txts[type_]

        if parent:  # find parent button
            for i in self.buttons:
                if i[0].target.gnx == parent:
                    parent = i[1]
                    break
            else:
                g.es('Move to button parent not found, placing at top level')
                parent = None

        header = v.anyAtFileNodeName() or v.h  # drop @auto etc.

        text = txt + ":" + header if txt else header
        # createButton truncates text.

        if parent and g.app.gui.guiName().startswith("qt"):
            pb = parent.button
            rc = QtWidgets.QAction(text, pb)
            rc.triggered.connect(mb.moveCurrentNodeToTarget)
            pb.insertAction(pb.actions()[0], rc)  # insert at top
            b = None
            mb.has_parent = True
            # New code.
            t = c.config.getString('mod-scripting-subtext') or ''
            t2 = pb.text()
            if not t.endswith(t):
                pb.setText(t2 + t)
        else:
            b = sc.createIconButton(
                args=None,
                text=text,
                command=mb.moveCurrentNodeToTarget,
                statusLine='%s current node to %s child of %s' %
                (type_.title(), which, v.h),
                kind="quick-move")
            if g.app.gui.guiName() == "qt":

                def cb_goto_target(checked, c=c, v=v):
                    p = c.vnode2position(v)
                    c.selectPosition(p)
                    c.redraw()

                def cb_set_parent(checked, c=c, v=v, first=which, type_=type_):
                    c.quickMove.set_parent(v, first, type_)

                def cb_permanent(checked, c=c, v=v, type_=type_, first=which):
                    c.quickMove.permanentButton(v=v, type_=type_, first=first)

                # def cb_clear(event=None, c=c, v=v):
                #     c.quickMove.clearButton(v)

                for cb, txt in [
                    (cb_goto_target, 'Goto target'),
                    (cb_permanent, 'Make permanent'),
                        # (cb_clear, 'Clear permanent'),
                    (cb_set_parent, 'Set parent'),
                ]:
                    but = b.button
                    rc = QtWidgets.QAction(txt, but)
                    rc.triggered.connect(cb)
                    but.insertAction(but.actions()[-1], rc)
                    # insert rc before Remove Button

        self.buttons.append((mb, b))