def commit_settings(self, param): if param.name() in iter_children(self.settings.child(('settings_client')), []): grabber_socket = \ [client['socket'] for client in self.connected_clients if client['type'] == self.client_type][0] grabber_socket.send_string('set_info') path = get_param_path(param)[2:] # get the path of this param as a list starting at parent 'infos' grabber_socket.send_list(path) # send value data = ioxml.parameter_to_xml_string(param) grabber_socket.send_string(data)
def update_settings(self, settings_parameter_dict): """ Update the settings tree from settings_parameter_dict. Finally do a commit to activate changes. ========================== ============= ===================================================== **Parameters** **Type** **Description** *settings_parameter_dict* dictionnnary a dictionnary listing path and associated parameter ========================== ============= ===================================================== See Also -------- send_param_status, commit_settings """ # settings_parameter_dict=edict(path=path,param=param) try: path = settings_parameter_dict['path'] param = settings_parameter_dict['param'] change = settings_parameter_dict['change'] try: self.settings.sigTreeStateChanged.disconnect( self.send_param_status) except Exception: pass if change == 'value': self.settings.child(*path[1:]).setValue( param.value()) # blocks signal back to main UI elif change == 'childAdded': child = Parameter.create(name='tmp') child.restoreState(param) self.settings.child(*path[1:]).addChild( child) # blocks signal back to main UI param = child elif change == 'parent': children = get_param_from_name(self.settings, param.name()) if children is not None: path = get_param_path(children) self.settings.child(*path[1:-1]).removeChild(children) self.settings.sigTreeStateChanged.connect(self.send_param_status) self.commit_settings(param) except Exception as e: self.emit_status(ThreadCommand("Update_Status", [str(e), 'log']))
def commit_settings(self, param): if param.name() in putils.iter_children( self.settings.child(('settings_client')), []): actuator_socket = [ client['socket'] for client in self.connected_clients if client['type'] == 'ACTUATOR' ][0] actuator_socket.send_string('set_info') path = putils.get_param_path(param)[2:] # get the path of this param as a list starting at parent 'infos' actuator_socket.send_list(path) # send value data = ioxml.parameter_to_xml_string(param) actuator_socket.send_string(data)
def test_get_param_path(): item1 = mock.Mock() item1.name.return_value = 'first' item1.parent.return_value = None item2 = mock.Mock() item2.name.return_value = 'second' item2.parent.return_value = item1 item3 = mock.Mock() item3.name.return_value = 'third' item3.parent.return_value = item2 item4 = mock.Mock() item4.name.return_value = 'fourth' item4.parent.return_value = item3 path = utils.get_param_path(item4) assert path == ['first', 'second', 'third', 'fourth']
def update_settings( self, settings_parameter_dict ): # settings_parameter_dict=edict(path=path,param=param) """ Receive the settings_parameter signal from the param_tree_changed method and make hardware updates of mmodified values. ========================== =========== ========================================================================================================== **Arguments** **Type** **Description** *settings_parameter_dict* dictionnary Dictionnary with the path of the parameter in hardware structure as key and the parameter name as element ========================== =========== ========================================================================================================== See Also -------- send_param_status, commit_settings """ path = settings_parameter_dict['path'] param = settings_parameter_dict['param'] change = settings_parameter_dict['change'] try: self.settings.sigTreeStateChanged.disconnect( self.send_param_status) except Exception: pass if change == 'value': self.settings.child(*path[1:]).setValue( param.value()) # blocks signal back to main UI elif change == 'childAdded': child = Parameter.create(name='tmp') child.restoreState(param) self.settings.child(*path[1:]).addChild( child) # blocks signal back to main UI param = child elif change == 'parent': children = putils.get_param_from_name(self.settings, param.name()) if children is not None: path = putils.get_param_path(children) self.settings.child(*path[1:-1]).removeChild(children) self.settings.sigTreeStateChanged.connect(self.send_param_status) self.commit_common_settings(param) self.commit_settings(param)
def roi_tree_changed(self, param, changes): for param, change, data in changes: path = self.settings.childPath(param) if path is not None: childName = '.'.join(path) else: childName = param.name() if change == 'childAdded': # new roi to create par = data[0] newindex = int(par.name()[-2:]) if par.child(('type')).value() == '1D': roi_type = '' pos = self.viewer_widget.plotItem.vb.viewRange()[0] newroi = LinearROI(index=newindex, pos=pos) newroi.setZValue(-10) newroi.setBrush(par.child(('Color')).value()) newroi.setOpacity(0.2) elif par.child(('type')).value() == '2D': roi_type = par.child(('roi_type')).value() xrange = self.viewer_widget.plotItem.vb.viewRange()[0] yrange = self.viewer_widget.plotItem.vb.viewRange()[1] width = np.max(((xrange[1] - xrange[0]) / 10, 2)) height = np.max(((yrange[1] - yrange[0]) / 10, 2)) pos = [ int(np.mean(xrange) - width / 2), int(np.mean(yrange) - width / 2) ] if roi_type == 'RectROI': newroi = RectROI(index=newindex, pos=pos, size=[width, height]) else: newroi = EllipseROI(index=newindex, pos=pos, size=[width, height]) newroi.setPen(par.child(('Color')).value()) newroi.sigRegionChanged.connect( lambda: self.ROI_changed.emit()) newroi.sigRegionChangeFinished.connect( lambda: self.ROI_changed_finished.emit()) newroi.index_signal[int].connect(self.update_roi_tree) try: self.settings.sigTreeStateChanged.disconnect() except Exception: pass self.settings.sigTreeStateChanged.connect( self.roi_tree_changed) self.viewer_widget.plotItem.addItem(newroi) self._set_roi_from_index(newindex, newroi) self.new_ROI_signal.emit(newindex, roi_type) self.update_roi_tree(newindex) elif change == 'value': if param.name() in putils.iter_children( self.settings.child(('ROIs')), []): parent_name = putils.get_param_path(param)[ putils.get_param_path(param).index('ROIs') + 1] self.update_roi(parent_name, param) self.roi_value_changed.emit(parent_name, (param, param.value())) elif change == 'parent': if 'ROI' in param.name(): roi = self._ROIs.pop(param.name()) self.viewer_widget.plotItem.removeItem(roi) self.remove_ROI_signal.emit(param.name()) self.ROI_changed_finished.emit()