示例#1
0
    def add_visibility_func(self, block):
        groupname = block.BLOCKNAME.rstrip("1234567890")
        tags = ["widget:toggle"]
        if groupname != block.BLOCKNAME:
            self.make_group(groupname)
            tags += ["group:%s" % groupname]
        attr = Attribute(VEnum("Hide,Show"), "Does this appear in flowgraph",
                         tags=tags)
        self.add_attribute(block.BLOCKNAME, attr)
        setattr(self, block.BLOCKNAME, "Hide")
        set_name = "_set_%s_visible" % block.BLOCKNAME

        def set_func(device, **args):
            block._set_visible(args[block.BLOCKNAME])

        method = ClientMethod(set_name, set_name, set_func)
        arg = dict(type=attr.typ, descriptor=attr.descriptor)
        method.in_arguments = OrderedDict([(attr.name, arg)])
        setattr(self, set_name, method)
        self.add_method(method)
        attr.tags.append("method:{}".format(set_name))

        def update_attr(value, changes):
            attr.update(value)

        block.add_listener(update_attr, "attributes.VISIBLE.value")
示例#2
0
    def make_method(self, mname, mdata):
        def f(self, *args, **kwargs):
            return self.do_call(mname, *args, **kwargs)

        valid_states = mdata.get("validStates", None)
        if valid_states:
            valid_states = [DState.__members__[s] for s in valid_states]
        m = ClientMethod(mname, mdata.get("descriptor", mname), f, valid_states)
        m.in_arguments = mdata.get("arguments", {})
        return m
示例#3
0
    def make_setter(self, attr):
        param = attr.name
        set_name = "_set_{}".format(param)
        isbool = type(attr.typ) == VBool

        def set_func(device, **args):
            value = args[param]
            setattr(device, param, value)
            if isbool:
                value = int(args[param])
            device.comms.set_field(
                self.block + self.i, param.replace(":", "."), value)

        method = ClientMethod(set_name, set_name, set_func)
        arg = dict(type=attr.typ, descriptor=attr.descriptor)
        method.in_arguments = OrderedDict([(param, arg)])
        setattr(self, set_name, method)
        self.add_method(method)
        attr.tags.append("method:{}".format(set_name))