Beispiel #1
0
    def __init__(self, callback=None, *args, **kwargs):
        if callback is not None:
            self._callback = util.WeakMethod(callback)
        else:
            self._callback = None

        super(ConfigObjProj, self).__init__(*args, **kwargs)
Beispiel #2
0
    def __init__(self, parent=None, ignoreChildren=False, **opts):
        self.sigValueChanged = util.Signal()
        self.sigLimitsChanged = util.Signal()
        self.sigOptionsChanged = util.Signal()
        self.sigChildAdded = util.Signal()
        self.sigChildRemoved = util.Signal()

        self.previousValue = None
        self.parent = parent
        self.invalid = False
        self.opts = {"visible": True}
        self.opts.update(opts)

        if 'name' not in self.opts or not isinstance(self.opts['name'],
                                                     basestring):
            raise Exception("Parameter must have a name.")

        name = self.opts["name"]
        if 'type' not in self.opts or not isinstance(
                self.opts['type'], basestring
        ) or self.opts['type'] not in Parameter.supportedTypes:
            raise Exception("Parameter \"%s\" must have a valid string type." %
                            name)

        # for opt in opts:
        #     if opt not in Parameter.suppertedAttributes:
        #         raise Exception("Parameter \"%s\" has unknown attribute type: %s." % (name, opt))

        if self.opts['type'] != 'group':
            if (('set' in self.opts) or
                ('get' in self.opts)) and ('value' in self.opts):
                raise Exception(
                    "Use set/get or value, not both simultaneously in parameter \"%s\". If an action is needed, use the action option."
                    % name)

            if not ('set' in self.opts or 'get' in self.opts
                    or 'value' in self.opts or 'action' in self.opts
                    or 'linked' in self.opts):
                raise Exception(
                    "Useless parameter \"%s\" because no set/get/value/action/linked option is defined."
                    % name)

            if 'set' in self.opts and (not ('get' in self.opts)):
                raise Exception(
                    "Option set and get should be used together in parameter \"%s\"."
                    % name)

            if 'get' in self.opts and (not 'set' in self.opts) and (
                    'readonly'
                    in self.opts) and self.opts['readonly'] == False:
                raise Exception(
                    "Parameters \"%s\" has get and no set. Should be marked as readonly."
                    % name)

            if self.opts.get("type", None) == "list":
                self.opts['limits'] = opts['values']

            if 'set' in self.opts:
                self.sigValueChanged.connect(self.opts['set'])
                self.opts['set'] = None

            if 'get' in self.opts:
                self.opts['get'] = util.WeakMethod(self.opts['get'])

            if 'action' in self.opts:
                self.opts['action'] = util.WeakMethod(self.opts['action'])

            if "default" not in self.opts:
                self.opts["default"] = self.getValue()
                self.setValue(self.opts["default"], init=True)
        else:
            if 'addLoadSave' in self.opts and self.opts["addLoadSave"]:
                self.opts["addLoadSave"] = (self.load, self.save)

        self.childs = []
        self.ignoredChildren = self.opts.pop("children", [])
        if Parameter.usePyQtGraph and self.opts["type"] != "menu":
            self.setupPyQtGraphParameter()
        self.keys = {}
        if ignoreChildren is False:
            self.addChildren(self.ignoredChildren)
            self.ignoredChildren = []