예제 #1
0
def load_remote_device(instr_server_client, dname):

    info = instr_server_client.get_instr_info(dname)

    driver_class = get_class_from_str(info['class'])

    class Remote_Device_Instance(Remote_Device):
        def __init__(self):
            self.client, self.dname, self.info = instr_server_client, dname, info

    for feat_name, feat in driver_class._lantz_features.items():
        if isinstance(feat, DictFeat):

            def get_remote_dictfeat(_feat_name):
                class Remote_DictFeat():
                    # This is not ideal, but it will do for now
                    # Ideally I would have a _self reference here instead of the more static instr_server_client and dname
                    def __getitem__(self, key):
                        return instr_server_client.get_dictfeat(
                            dname, _feat_name, key)

                    def __setitem__(self, key, val):
                        return instr_server_client.set_dictfeat(
                            dname, _feat_name, key, val)

                return Remote_DictFeat

            setattr(Remote_Device_Instance, feat_name,
                    get_remote_dictfeat(feat_name)())
        elif isinstance(feat, Feat):

            def get_fun(_feat_name):
                def f_(_self):
                    return _self.client.get_feat(_self.dname, _feat_name)

                return f_

            def set_fun(_feat_name):
                def f_(_self, val):
                    return _self.client.set_feat(_self.dname, _feat_name, val)

                return f_

            setattr(Remote_Device_Instance, feat_name,
                    property(get_fun(feat_name), set_fun(feat_name)))

    for action_name, action in driver_class._lantz_actions.items():

        def execute(_action_name):
            def f_(_self, *args, **kwargs):
                return _self.client.run_action(_self.dname, _action_name,
                                               *args, **kwargs)

            return f_

        setattr(Remote_Device_Instance, action_name, execute(action_name))

    return Remote_Device_Instance()
예제 #2
0
 def add_instr(self, dname, dclass, *args, **kwargs):
     c = get_class_from_str(dclass)
     self.instr[dname] = c(*args, **kwargs)
     self.instr_info[dname] = {
         'class': dclass,
         'args': args,
         'kwargs': kwargs
     }
     self.initialize_instr(dname)
     return "Instrument added!"
예제 #3
0
    def add_instr(self, dname, dclass, *args, **kwargs):
        ans = super().add_instr(dname, dclass, *args, **kwargs)
        self.db[dname].drop()

        c = get_class_from_str(dclass)

        doc_list = list()
        for feat_name, feat in c._lantz_features.items():
            params = feat.modifiers[MISSING][MISSING]
            values = list(
                params['values']) if not params['values'] is None else None
            if 'keys' in params and not params['keys'] is None:
                keys = list(params['keys'])
                keys.sort()
            else:
                keys = None
            limits = params['limits']
            if not limits is None:
                if len(limits) == 1:
                    limits = [0, limits[0]]
                elif len(limits) == 3:
                    limits = [limits[0], limits[1]]
                    # step = limits[2] #Not used right now

            doc_list.append({
                'name':
                feat_name,
                'type':
                'dictfeat' if isinstance(feat, DictFeat) else 'feat',
                'readonly':
                dict(self.instr[dname].feats.items())[feat_name].feat.fset is
                None,
                'units':
                params['units'],
                'limits':
                limits,
                'values':
                values,
                'keys':
                keys,
                'value': [None] *
                len(params['keys']) if isinstance(feat, DictFeat) else None,
            })
        for action_name, action in c._lantz_actions.items():
            doc_list.append({
                'name': action_name,
                'type': 'action',
            })

        self.db[dname].insert_many(doc_list)
        return ans
예제 #4
0
파일: views.py 프로젝트: aidanj5/nspyre
    def __init__(self, spyrelet_class):
        if type(spyrelet_class) is str:
            spyrelet_class = get_class_from_str(spyrelet_class)

        self.views = {
            x: getattr(spyrelet_class, x)
            for x in dir(spyrelet_class)
            if type(getattr(spyrelet_class, x)) is View
        }
        formatters = [
            getattr(spyrelet_class, x) for x in dir(spyrelet_class)
            if type(getattr(spyrelet_class, x)) is Formatter
        ]

        # Associate format_init and format_update functions
        for f in formatters:
            for view_name in f.view_list:
                if view_name in self.views:
                    self.views[view_name].add_formatter(f)
예제 #5
0
    def update_instr(self, dname):
        try:
            self.tree.setSortingEnabled(False)

            dclass = self.manager.get(dname)['class']
            c = get_class_from_str(dclass)

            self.manager.get(dname)['zmq'].get_none_feat(dname)

            instr_item = QtWidgets.QTreeWidgetItem(self.tree, [dname, ''])
            feats = self.manager.get(dname)['mongo'].find({}, {'_id': False})

            self.feat_items[dname] = dict()
            for feat in feats:
                if feat['type'] == 'dictfeat':
                    feat_item = DictFeatTreeWidgetItem(
                        feat, self.tree,
                        self.manager.get(dname)['dev'])
                    instr_item.addChild(feat_item.item)
                elif feat['type'] == 'feat':
                    feat_item = FeatTreeWidgetItem(
                        feat, self.tree,
                        self.manager.get(dname)['dev'])
                    instr_item.addChild(feat_item.item)
                    self.tree.setItemWidget(feat_item.item, 1, feat_item.w)
                elif feat['type'] == 'action':
                    feat_item = ActionTreeWidgetItem(
                        feat, self.tree,
                        self.manager.get(dname)['dev'])
                    instr_item.addChild(feat_item.item)
                    self.tree.setItemWidget(feat_item.item, 1, feat_item.w)
                self.feat_items[dname][feat['name']] = feat_item
                self.tree.setItemWidget(feat_item.item, 0,
                                        QtWidgets.QLabel(feat['name']))

            self.tree.setSortingEnabled(True)
            self.tree.sortByColumn(0, QtCore.Qt.AscendingOrder)
        except:
            print("Could not load {}".format(dname))
            self.remove_instr(dname)