def test_find_dict_in_list_from_key_val(self): dict_tmp_1 = {1: 'abc', 2: 'def'} dict_tmp_2 = {1: 'def', 2: 'abc'} dict_tmp_3 = {'abc': 1, 'def': 2} dicts = [dict_tmp_1, dict_tmp_2, dict_tmp_3] assert utils.find_dict_in_list_from_key_val(dicts, 1, 'abc') == dict_tmp_1 assert utils.find_dict_in_list_from_key_val( dicts, 1, 'abc', True) == tuple([dict_tmp_1, 0]) assert utils.find_dict_in_list_from_key_val(dicts, 'def', 1) is None assert utils.find_dict_in_list_from_key_val(dicts, 'def', 1, True) == tuple([None, -1])
def set_setting_tree(self, index=0): """ Set the move settings parameters tree, clearing the current tree and setting the 'move_settings' node. See Also -------- update_status """ self.stage_name = self.ui.Stage_type_combo.currentText() self.settings.child('main_settings', 'move_type').setValue(self.stage_name) try: for child in self.settings.child(('move_settings')).children(): child.remove() parent_module = utils.find_dict_in_list_from_key_val( DAQ_Move_Stage_type, 'name', self.stage_name) class_ = getattr( getattr(parent_module['module'], 'daq_move_' + self.stage_name), 'DAQ_Move_' + self.stage_name) params = getattr(class_, 'params') move_params = Parameter.create(name='move_settings', type='group', children=params) self.settings.child( ('move_settings')).addChildren(move_params.children()) except Exception as e: self.logger.exception(str(e))
def get_set_model_params(self, model_name): self.settings.child('models', 'model_params').clearChildren() models = get_models() if len(models) > 0: model_class = find_dict_in_list_from_key_val(models, 'name', model_name)['class'] params = getattr(model_class, 'params') self.settings.child('models', 'model_params').addChildren(params)
def set_actuator(self, actuator_id): act = utils.find_dict_in_list_from_key_val(self.actuators, 'id', actuator_id) reply = None if act is not None: ret = self._write_command([0x43, act['command']]) reply = self._read_reply(self.message_len_without_data) self.get_status()
def set_diag(self, diag_id, value): diag = utils.find_dict_in_list_from_key_val(self.diagnostics, 'id', diag_id) reply = None if diag is not None: if not diag['readonly']: assert len(value) == diag['reply'] ret = self._write_command([0x54, diag['write_command']], data=value) commands, data = self._read_reply( self.message_len_without_data + diag['reply']) assert len(data) == diag['reply'] diag['value'] = data return reply
def addNew(self, typ): """ Add a child. =============== =========== **Parameters** **Type** *typ* string =============== =========== """ name_prefix = 'move' child_indexes = [int(par.name()[len(name_prefix) + 1:]) for par in self.children()] if child_indexes == []: newindex = 0 else: newindex = max(child_indexes) + 1 params = daq_move_params iterative_show_pb(params) parent_module = utils.find_dict_in_list_from_key_val(DAQ_Move_Stage_type, 'name', typ) class_ = getattr(getattr(parent_module['module'], 'daq_move_' + typ), 'DAQ_Move_' + typ) params_hardware = getattr(class_, 'params') iterative_show_pb(params_hardware) for main_child in params: if main_child['name'] == 'move_settings': main_child['children'] = params_hardware elif main_child['name'] == 'main_settings': for child in main_child['children']: if child['name'] == 'move_type': child['value'] = typ if child['name'] == 'controller_ID': child['value'] = random.randint(0, 9999) child = {'title': 'Actuator {:02.0f}'.format(newindex), 'name': f'{name_prefix}{newindex:02.0f}', 'type': 'group', 'removable': True, 'children': [ {'title': 'Name:', 'name': 'name', 'type': 'str', 'value': 'Move {:02.0f}'.format(newindex)}, {'title': 'Init?:', 'name': 'init', 'type': 'bool', 'value': True}, {'title': 'Settings:', 'name': 'params', 'type': 'group', 'children': params }], 'removable': True, 'renamable': False} self.addChild(child)
def ini_stage(self, params_state=None, controller=None): """ Init a stage updating the hardware and sending an hardware move_done signal. =============== =================================== ========================================================================================================================== **Parameters** **Type** **Description** *params_state* ordered dictionnary list The parameter state of the hardware class composed by a list representing the tree to keep a temporary save of the tree *controller* one or many instance of DAQ_Move The controller id of the hardware *stage* instance of DAQ_Move Defining axes and motors =============== =================================== ========================================================================================================================== See Also -------- DAQ_utils.ThreadCommand, DAQ_Move """ status = edict(initialized=False, info="") try: parent_module = utils.find_dict_in_list_from_key_val( DAQ_Move_Stage_type, 'name', self.stage_name) class_ = getattr( getattr(parent_module['module'], 'daq_move_' + self.stage_name), 'DAQ_Move_' + self.stage_name) self.hardware = class_(self, params_state) status.update(self.hardware.ini_stage( controller)) # return edict(info="", controller=, stage=) self.hardware.Move_Done_signal.connect(self.Move_Done) # status.initialized=True return status except Exception as e: self.logger.exception(str(e)) return status
def get_diag_from_id(self, diag_id): diag = utils.find_dict_in_list_from_key_val(self.diagnostics, 'id', diag_id) return self.get_diag(diag)
def get_diag_from_name(self, name): diag = utils.find_dict_in_list_from_key_val(self.diagnostics, 'name', name) return self.get_diag(diag)
def get_shutter(self): return bool( utils.find_dict_in_list_from_key_val(self.status, 'id', 20)['value'])
def set_model(self): model_name = self.settings.child('models', 'model_class').value() self.model_class = find_dict_in_list_from_key_val(self.models, 'name', model_name)['class'](self) self.set_setpoints_buttons() self.model_class.ini_model() self.settings.child('main_settings', 'epsilon').setValue(self.model_class.epsilon)
def addNew(self, typ): """ Add a child. =============== =========== ================ **Parameters** **Type** **Description* *typ* string the viewer name =============== =========== ================ """ try: name_prefix = 'det' child_indexes = [int(par.name()[len(name_prefix) + 1:]) for par in self.children()] if child_indexes == []: newindex = 0 else: newindex = max(child_indexes) + 1 params = daq_viewer_params iterative_show_pb(params) for main_child in params: if main_child['name'] == 'main_settings': for child in main_child['children']: if child['name'] == 'DAQ_type': child['value'] = typ[0:5] if child['name'] == 'detector_type': child['value'] = typ[6:] if child['name'] == 'controller_status': child['visible'] = True if child['name'] == 'controller_ID': child['value'] = random.randint(0, 9999) if '0D' in typ: parent_module = utils.find_dict_in_list_from_key_val(DAQ_0DViewer_Det_types, 'name', typ[6:]) class_ = getattr(getattr(parent_module['module'], 'daq_0Dviewer_' + typ[6:]), 'DAQ_0DViewer_' + typ[6:]) elif '1D' in typ: parent_module = utils.find_dict_in_list_from_key_val(DAQ_1DViewer_Det_types, 'name', typ[6:]) class_ = getattr(getattr(parent_module['module'], 'daq_1Dviewer_' + typ[6:]), 'DAQ_1DViewer_' + typ[6:]) elif '2D' in typ: parent_module = utils.find_dict_in_list_from_key_val(DAQ_2DViewer_Det_types, 'name', typ[6:]) class_ = getattr(getattr(parent_module['module'], 'daq_2Dviewer_' + typ[6:]), 'DAQ_2DViewer_' + typ[6:]) elif 'ND' in typ: parent_module = utils.find_dict_in_list_from_key_val(DAQ_NDViewer_Det_types, 'name', typ[6:]) class_ = getattr(getattr(parent_module['module'], 'daq_NDviewer_' + typ[6:]), 'DAQ_NDViewer_' + typ[6:]) for main_child in params: if main_child['name'] == 'main_settings': for child in main_child['children']: if child['name'] == 'axes': child['visible'] = True params_hardware = getattr(class_, 'params') iterative_show_pb(params_hardware) for main_child in params: if main_child['name'] == 'detector_settings': while len(main_child['children']) != 1: for child in main_child['children']: if child['name'] != 'ROIselect': main_child['children'].remove(child) main_child['children'].extend(params_hardware) child = {'title': 'Det {:02.0f}'.format(newindex), 'name': f'{name_prefix}{newindex:02.0f}', 'type': 'group', 'children': [ {'title': 'Name:', 'name': 'name', 'type': 'str', 'value': 'Det {:02.0f}'.format(newindex)}, {'title': 'Init?:', 'name': 'init', 'type': 'bool', 'value': True}, {'title': 'Settings:', 'name': 'params', 'type': 'group', 'children': params}, ], 'removable': True, 'renamable': False} self.addChild(child) except Exception as e: print(str(e))