Exemple #1
0
    def term(self):
        names = self.setups.keys()
        names.sort()

        for n in names:
            m = self.get_submenu(n.split())
            m.leaf = self.setups[n]

        children = piw.term(0)

        for c in self.children:
            children.add_arg(-1,c.term())

        k = self.children2.keys()
        k.sort()

        for c in k:
            children.add_arg(-1,self.children2[c].term())

        l = self.leaf

        if l:
            t = piw.term('n',7)
            t.set_arg(0,piw.term(piw.makestring(self.label,0)))
            t.set_arg(1,children)
            t.set_arg(2,piw.term(piw.makestring(l[0],0)))
            t.set_arg(3,piw.term(piw.makestring(l[1],0)))
            t.set_arg(4,piw.term(piw.makestring(l[2],0)))
            t.set_arg(5,piw.term(piw.makebool(l[3],0)))
            t.set_arg(6,piw.term(piw.makebool(l[4],0)))
        else:
            t = piw.term('n',2)
            t.set_arg(0,piw.term(piw.makestring(self.label,0)))
            t.set_arg(1,children)

        return t
Exemple #2
0
def find_user_setups_flat():
    rd = resource.user_resource_dir(resource.setup_dir)

    t = piw.term("tree",0)
    t.add_arg(-1,piw.term(piw.makestring('user setups',0)))

    for (sp,sd,sn) in os.walk(rd):
        for s in filter(filter_valid_setup,sn):
            t3 = piw.term('leaf',0)
            s3 = split_setup(s)
            # unencode url encoded illegal chars to display them properly
            name = piw.term(piw.makestring(urllib.unquote(s3[0]),0)) if s3[0] else piw.term()
            slot = piw.term(piw.makestring(s3[1],0))
            t3.add_arg(-1,name)
            t3.add_arg(-1,slot)
            t3.add_arg(-1,piw.term(piw.makestring(os.path.join(rd,s),0)))
            t3.add_arg(-1,piw.term(piw.makebool(False,0)))
            t3.add_arg(-1,piw.term(piw.makebool(True,0)))
            t.add_arg(-1,t3)

    return t
Exemple #3
0
    def load_state(self, state, delegate, phase):
        if state.arity() == 0 or phase != 1:
            return

        children = [state.arg(n) for n in range(1, state.arity())]

        if children and children[0].type() == 1:
            d = children[0].value()
            self.load_value(delegate, d)
            children = children[1:]

        children = [(c.arg(0).value().as_long(), c) for c in children
                    if c.type() == 3 and (c.pred() == 'n' or c.pred() == 'p')]

        if self.__creator is not None:
            childlist = [c[0] for c in children]
            self.populate(childlist)

        r = None

        while children:
            (i, c) = children.pop(0)

            if c.pred() == 'p':
                continue

            n = self.get_internal(i)
            if n is not None:
                if hasattr(n, 'load_state'):
                    n.load_state(c, delegate, phase)
                continue
            else:
                if r is None:
                    r = piw.term('n', 0)
                    r.append_arg(state.arg(0))
                r.append_arg(c)

        if r:
            delegate.set_residual(self, r)