コード例 #1
0
 def __init__(self, c):
     self.c = c
     #@+at
     #     c.k.registerCommand('upload',shortcut=None,func=self.upload)
     #     script = "c.k.simulateCommand('upload')"
     #     g.app.gui.makeScriptButton(c,script=script,buttonText='Upload')
     #@@c
     ib_w = self.c.frame.iconBar.w
     action = QtGui.QAction('Upload', ib_w)
     self.c.frame.iconBar.add(qaction=action, command=self.upload)
コード例 #2
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 = QtGui.QAction(name, menu)
         a.connect(a, QtCore.SIGNAL("triggered()"), 
                   lambda cb=cb, name=name: self.do_wrap(cb, name))
         menu.insertAction(menu.actions()[0], a)
     pathmenu = menu.addMenu("Move")
     # copy / cut to other outline
     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(cb=cb, name=txt.strip('.')+' '+target['name']):
                 self.do_wrap(cb, name)
             a.connect(a, QtCore.SIGNAL("triggered()"), 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(cb=cb, name=txt.strip('.')+' top of '+g.os_path_basename(c2.fileName())):
                 self.do_wrap(cb, name)
             a.connect(a, QtCore.SIGNAL("triggered()"), 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(cb=cb, name="Bookmark to "+target['name']):
             self.do_wrap(cb, name)
         a.connect(a, QtCore.SIGNAL("triggered()"), 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(cb=cb, name="Bookmark to top of "+g.os_path_basename(c2.fileName())):
             self.do_wrap(cb, name)
         a.connect(a, QtCore.SIGNAL("triggered()"), 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.connect(a, QtCore.SIGNAL("triggered()"), command)
     # add new global target, etc.
     a = pathmenu.addAction("Add node as target")
     a.connect(a, QtCore.SIGNAL("triggered()"), 
          lambda p=p: self.add_target(p))
     a = pathmenu.addAction("Show targets")
     a.connect(a, QtCore.SIGNAL("triggered()"), 
          lambda p=p: self.show_targets())
     a = pathmenu.addAction("Read targets")
     a.connect(a, QtCore.SIGNAL("triggered()"), 
          lambda p=p: self.read_targets())
コード例 #3
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() == "qt":
            pb = parent.button
            rc = QtGui.QAction(text, pb)
            rc.connect(rc, QtCore.SIGNAL("triggered()"), mb.moveCurrentNodeToTarget)
            pb.insertAction(pb.actions()[0], rc)  # insert at top
            b = None
            mb.has_parent = True
            t = QtCore.QString(c.config.getString('mod_scripting_subtext') or '')
            if not unicode(pb.text()).endswith(unicode(t)):
                pb.setText(pb.text()+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(event=None, c=c, v=v):
                    p = c.vnode2position(v)
                    c.selectPosition(p)
                    c.redraw()

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

                def cb_permanent(event=None, 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 = QtGui.QAction(txt, but)
                    rc.connect(rc, QtCore.SIGNAL("triggered()"), cb)
                    but.insertAction(but.actions()[-1], rc)
                        # insert rc before Remove Button

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