def update_gui(self): # Updates all of the widgets with their settings from the config self.update_hkl_options() blockers = [QSignalBlocker(x) for x in self.all_widgets] # noqa: F841 def setter(w): if isinstance(w, QComboBox): return lambda x: w.setCurrentIndex(w.findData(x)) # Assume it is a spin box of some kind return w.setValue config = HexrdConfig().indexing_config def set_val(w, path): cur = config for x in path: if x not in cur: # If it's not in the config, skip over it return cur = cur[x] setter(w)(cur) for w, path in self.widget_paths.items(): w = getattr(self.ui, w) set_val(w, path) # Update the method name method = config['find_orientations']['seed_search']['method'] self.method_name = next(iter(method)) self.update_method_tab() # Also set the color map minimum to the threshold value... self.threshold = config['find_orientations']['threshold']
def update_gui(self): if self.overlay is None: return blockers = [QSignalBlocker(w) for w in self.widgets] # noqa: F841 self.tth_width_gui = self.tth_width_config self.update_enable_states()
def update_extra_params(self): # First, make a copy of the old params object. We will remove all # extra params currently in place. old_params = copy.deepcopy(self.params) for key in list(self.params.keys()): if key not in self.default_params: del self.params[key] # Temporarily set the background method to chebyshev # so that the spline lineplot won't pop up blocker = QSignalBlocker(self.ui.background_method) # noqa: F841 previous = self.background_method self.background_method = 'chebyshev' try: # Next, create the WPPF object and allow it to add whatever params # it wants to. Then we will add them to the new params. wppf_object = self.create_wppf_object(add_params=True) finally: # Restore the old background method self.background_method = previous for key, obj in wppf_object.params.param_dict.items(): if key in self.params: # Already present. Continue continue if all(key in x for x in [old_params, self.default_params]): # Copy over the previous info for the key # Only copy over default params, no extra params self.params[key] = old_params[key] continue # Otherwise, copy it straight from the WPPF object. self.params[key] = [obj.value, obj.lb, obj.ub, obj.vary]
def update_table(self): block_list = [ self.ui.table, self.ui.table.selectionModel() ] blockers = [QSignalBlocker(x) for x in block_list] # noqa: F841 prev_selected = self.selected_row overlays = HexrdConfig().overlays self.clear_table() self.ui.table.setRowCount(len(overlays)) for i, overlay in enumerate(overlays): w = self.create_materials_combo(overlay['material']) self.ui.table.setCellWidget(i, COLUMNS['material'], w) w = self.create_type_combo(overlay['type']) self.ui.table.setCellWidget(i, COLUMNS['type'], w) w = self.create_visibility_checkbox(overlay['visible']) self.ui.table.setCellWidget(i, COLUMNS['visible'], w) if prev_selected is not None: select_row = (prev_selected if prev_selected < len(overlays) else len(overlays) - 1) self.select_row(select_row) self.ui.table.resizeColumnsToContents() # Just in case the selection actually changed... self.selection_changed()
def update_selectors(self): tensor_type = self.tensor_type.capitalize() # Build combo boxes in code to assign columns in grains data items = [ ('Completeness', 1), ('Goodness of Fit', 2), (f'Equivalent {tensor_type}', EQUIVALENT_IND), (f'Hydrostatic {tensor_type}', HYDROSTATIC_IND), (f'XX {tensor_type}', 15), (f'YY {tensor_type}', 16), (f'ZZ {tensor_type}', 17), (f'YZ {tensor_type}', 18), (f'XZ {tensor_type}', 19), (f'XY {tensor_type}', 20) ] prev_ind = self.ui.plot_color_option.currentIndex() blocker = QSignalBlocker(self.ui.plot_color_option) # noqa: F841 self.ui.plot_color_option.clear() for item in items: self.ui.plot_color_option.addItem(*item) del blocker if hasattr(self, '_first_selector_update'): self.ui.plot_color_option.setCurrentIndex(prev_ind) else: self._first_selector_update = True index = self.ui.plot_color_option.findData(EQUIVALENT_IND) self.ui.plot_color_option.setCurrentIndex(index)
def update_gui_from_config(self): block_list = [ self.material_editor_widget, self.ui.materials_combo, self.ui.show_overlays, self.ui.min_d_spacing, self.ui.max_tth, self.ui.limit_active ] blockers = [QSignalBlocker(x) for x in block_list] combo = self.ui.materials_combo current_items = [combo.itemText(x) for x in range(combo.count())] materials_keys = list(HexrdConfig().materials.keys()) # If the materials in the config have changed, re-build the list if current_items != materials_keys: self.ui.materials_combo.clear() self.ui.materials_combo.addItems(materials_keys) self.material_editor_widget.material = HexrdConfig().active_material self.ui.materials_combo.setCurrentIndex( materials_keys.index(HexrdConfig().active_material_name)) self.ui.show_overlays.setChecked(HexrdConfig().show_overlays) self.ui.limit_active.setChecked(HexrdConfig().limit_active_rings) # Unblock the signal blockers before proceeding del blockers self.update_material_limits() self.update_table() self.update_enable_states()
def update_gui(self): if self.overlay is None: return blockers = [QSignalBlocker(w) for w in self.widgets] # noqa: F841 options = self.overlay.get('options', {}) if 'min_energy' in options: self.ui.min_energy.setValue(options['min_energy']) if 'max_energy' in options: self.ui.max_energy.setValue(options['max_energy']) if 'crystal_params' in options: self.crystal_params = options['crystal_params'] else: self.crystal_params = DEFAULT_CRYSTAL_PARAMS.copy() if options.get('tth_width') is not None: self.ui.tth_width.setValue(np.degrees(options['tth_width'])) if options.get('eta_width') is not None: self.ui.eta_width.setValue(np.degrees(options['eta_width'])) widths = ['tth_width', 'eta_width'] enable_widths = all(options.get(x) is not None for x in widths) self.ui.enable_widths.setChecked(enable_widths) self.update_enable_states()
def update_table(self): prev_selected = self.selected_row self.clear_table() if not self.sites: return block_list = [ self.ui.table, self.ui.table.selectionModel() ] blockers = [QSignalBlocker(x) for x in block_list] # noqa: F841 self.ui.table.setRowCount(len(self.sites)) for i, site in enumerate(self.sites): w = self.create_table_widget(site['name']) self.ui.table.setItem(i, 0, w) if prev_selected is not None: select_row = (prev_selected if prev_selected < len(self.sites) else len(self.sites) - 1) self.select_row(select_row) # Just in case the selection actually changed... self.selection_changed()
def update_gui_from_config(self): blocked = [QSignalBlocker(x) for x in self.all_widgets()] # noqa: F841 self.ui.raw_threshold_comparison.setCurrentIndex( HexrdConfig().threshold_comparison) self.ui.raw_threshold_value.setValue(HexrdConfig().threshold_value) self.ui.raw_threshold_mask.setChecked( HexrdConfig().threshold_mask_status) self.ui.cartesian_pixel_size.setValue( HexrdConfig().cartesian_pixel_size) self.ui.cartesian_virtual_plane_distance.setValue( HexrdConfig().cartesian_virtual_plane_distance) self.ui.cartesian_plane_normal_rotate_x.setValue( HexrdConfig().cartesian_plane_normal_rotate_x) self.ui.cartesian_plane_normal_rotate_y.setValue( HexrdConfig().cartesian_plane_normal_rotate_y) self.ui.polar_pixel_size_tth.setValue( HexrdConfig().polar_pixel_size_tth) self.ui.polar_pixel_size_eta.setValue( HexrdConfig().polar_pixel_size_eta) self.ui.polar_res_tth_min.setValue(HexrdConfig().polar_res_tth_min) self.ui.polar_res_tth_max.setValue(HexrdConfig().polar_res_tth_max) self.ui.polar_res_eta_min.setValue(HexrdConfig().polar_res_eta_min) self.ui.polar_res_eta_max.setValue(HexrdConfig().polar_res_eta_max) self.ui.polar_snip1d_algorithm.setCurrentIndex( HexrdConfig().polar_snip1d_algorithm) self.ui.polar_apply_snip1d.setChecked(HexrdConfig().polar_apply_snip1d) self.ui.polar_snip1d_width.setValue(HexrdConfig().polar_snip1d_width) self.ui.polar_snip1d_numiter.setValue( HexrdConfig().polar_snip1d_numiter)
def update_duplicate(self, w): ind = int(w.objectName().replace('stretch_matrix_', '')) dup_ind = self.stretch_matrix_duplicates.get(ind) if dup_ind is not None: dup = getattr(self.ui, f'stretch_matrix_{dup_ind}') blocker = QSignalBlocker(dup) # noqa: F841 dup.setValue(w.value())
def update_table(self): prev_selected = self.selected_row block_list = [self.ui.table, self.ui.table.selectionModel()] blockers = [QSignalBlocker(x) for x in block_list] # noqa: F841 atoms = self.site['atoms'] self.clear_table() self.ui.table.setRowCount(len(atoms)) for i, atom in enumerate(atoms): w = self.create_symbol_label(atom['symbol']) self.ui.table.setItem(i, COLUMNS['symbol'], w) w = self.create_occupancy_spinbox(atom['occupancy']) self.ui.table.setCellWidget(i, COLUMNS['occupancy'], w) w = self.create_thermal_factor_spinbox(self.thermal_factor(atom)) self.ui.table.setCellWidget(i, COLUMNS['thermal_factor'], w) self.update_occupancy_validity() if prev_selected is not None: select_row = (prev_selected if prev_selected < self.num_rows else self.num_rows - 1) self.select_row(select_row) # Just in case the selection actually changed... self.selection_changed()
def update_gui_from_config(self, config): blocked = [QSignalBlocker(x) for x in self.all_widgets()] self.ui.npdiv.setValue(config.get('npdiv')) self.ui.refit_pixel_scale.setValue(config.get('refit')[0]) self.ui.refit_ome_step_scale.setValue(config.get('refit')[1]) self.ui.threshold.setValue(config.get('threshold')) tth_max = config.get('tth_max') if isinstance(tth_max, bool): enabled = tth_max instrument = tth_max value = 0.0 else: enabled = True instrument = False value = tth_max self.ui.tth_max_enable.setChecked(enabled) self.ui.tth_max_instrument.setEnabled(enabled) self.ui.tth_max_instrument.setChecked(instrument) self.ui.tth_max_specify.setEnabled(enabled) self.ui.tth_max_specify.setChecked(not instrument) self.ui.tth_max_value.setEnabled(enabled and (not instrument)) self.ui.tth_max_value.setValue(value) tolerances = config.get('tolerance') self.tolerances_model.update_from_config(tolerances)
def load_settings(self): settings = HexrdConfig().config['calibration'].get('wppf') if not settings: return blockers = [QSignalBlocker(w) for w in self.all_widgets] # noqa: F841 for k, v in settings.items(): setattr(self, k, v)
def update_gui(self): widgets = self.site_settings_widgets blockers = [QSignalBlocker(w) for w in widgets] # noqa: F841 self.ui.total_occupancy.setValue(self.total_occupancy) for i, w in enumerate(self.fractional_coords_widgets): w.setValue(self.fractional_coords[i]) self.update_table()
def selected_rows(self, rows): selection_model = self.ui.table.selectionModel() blocker = QSignalBlocker(selection_model) # noqa: F841 selection_model.clear() command = QItemSelectionModel.Select | QItemSelectionModel.Rows for i in rows: model_index = selection_model.model().index(i, 0) selection_model.select(model_index, command)
def update_hkl_options(self): # This won't trigger a re-draw. Can change in the future if needed. hkl_indices = self.data.iHKLList all_hkls = self.data.planeData.getHKLs(asStr=True) hkls = [all_hkls[i] for i in hkl_indices] blocker = QSignalBlocker(self.ui.active_hkl) # noqa: F841 self.ui.active_hkl.clear() self.ui.active_hkl.addItems(hkls)
def update_image(self, cv_img: np.ndarray): """ Slot that gets called when a new image is available from the camera handles the signal :attr:`camera.AbstractCamera.new_image_available` :param cv_img: the image array from the camera :type cv_img: np.ndarray, numpy 2D array .. seealso:: :py:meth:`camera_preview.CameraPreview.update_image`, :attr:`camera.AbstractCamera.new_image_available` """ # block image signal to prevent overloading blocker = QSignalBlocker(self.cam) if self.cam.is_running: # evaluate droplet if checkbox checked eval = self.ui.evalChk.isChecked() or self._oneshot_eval self._oneshot_eval = False # display current fps self.ui.frameInfoLbl.setText('Running | FPS: ' + str(self.cam.get_framerate())) # save image frame if recording if self.ui.record_chk.isChecked(): self.recorder.write_frame( cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB)) elif self._oneshot_eval: # enable evaluate for one frame (eg snapshots) eval = True self._oneshot_eval = False else: eval = False # if ROI size changed, cause update of internal variables for new image dimensions if self.cam._image_size_invalid: self.ui.camera_prev.invalidate_imagesize() self.cam._image_size_invalid = False # update preview image self.ui.camera_prev.update_image(cv_img, eval) # display droplet parameters self.ui.drpltDataLbl.setText(str(self.ui.camera_prev._droplet)) # unblock signals from cam blocker.unblock()
def orientation(self, v): # This automatically converts to Euler angle conventions if HexrdConfig().euler_angle_convention is not None: v = copy.deepcopy(v) convention = HexrdConfig().euler_angle_convention self.convert_angle_convention(v, None, convention) for i, w in enumerate(self.orientation_widgets): blocker = QSignalBlocker(w) # noqa: F841 w.setValue(v[i])
def update_gui(self, orientation, position): """Called by parent widget.""" self._orientation = orientation self._position = position data = self._orientation if self.mode == WidgetMode.ORIENTATION \ else self._position for i, w in enumerate(self.spinbox_widgets): blocker = QSignalBlocker(w) # noqa: F841 w.setValue(data[i]) self.update_ranges()
def update_misc_gui(self): blocked = [QSignalBlocker(w) for w in self.misc_widgets] # noqa: F841 material = self.material density = getattr(material.unitcell, 'density', 0) volume = getattr(material, 'vol', 0) volume_per_atom = getattr(material, 'vol_per_atom', 0) self.ui.density.setValue(density) self.ui.volume.setValue(volume) self.ui.volume_per_atom.setValue(volume_per_atom)
def update_ranges(self): data = self._orientation if self.mode == WidgetMode.ORIENTATION \ else self._position range_value = self.ui.slider_range.value() * \ self.CONF_VAL_TO_SLIDER_VAL delta = range_value / 2.0 sliders = self.slider_widgets for i, slider in enumerate(sliders): val = data[i] blocker = QSignalBlocker(slider) # noqa: F841 slider.setRange(val - delta, val + delta) slider.setValue(val)
def block_signals(*objects): """Block signals of objects via a with block: with block_signals(object): ... """ blocked = [QSignalBlocker(o) for o in objects] try: yield finally: blocked.clear()
def update_valid_methods(self): valid_methods = list(self.all_methods) if getattr(self.indexing_runner, 'grains_table', None) is None: valid_methods.remove('indexing') widget = self.ui.method blocker = QSignalBlocker(widget) # noqa: F841 widget.clear() widget.addItems([x.capitalize() for x in valid_methods]) # In case the current widget changed... self.update_method_tab()
def update_gui(self): blockers = [QSignalBlocker(x) for x in self.widgets] # noqa: F841 indexing_config = HexrdConfig().indexing_config maps_config = indexing_config['find_orientations']['orientation_maps'] file_name = maps_config['file'] if maps_config['file'] else '' self.ui.file_name.setText(file_name) self.ui.threshold.setValue(maps_config['threshold']) self.ui.bin_frames.setValue(maps_config['bin_frames']) self.update_method_tab()
def update_gui(self): # Updates all of the widgets with their settings from the config self.update_hkl_options() blockers = [QSignalBlocker(x) for x in self.all_widgets] # noqa: F841 def setter(w): if isinstance(w, QComboBox): return lambda x: w.setCurrentIndex(w.findData(x)) # Assume it is a spin box of some kind return w.setValue config = self.config def set_val(w, path): cur = config for x in path: if x not in cur: # If it's not in the config, skip over it return cur = cur[x] setter(w)(cur) for w, path in self.widget_paths.items(): w = getattr(self.ui, w) set_val(w, path) find_orientations = config['find_orientations'] if find_orientations['use_quaternion_grid']: self.quaternion_method_name = 'grid_search' else: self.quaternion_method_name = 'seed_search' self.quaternion_grid_file = find_orientations.get('_quat_file', '') # Update the method name method = find_orientations['seed_search']['method'] self.seed_search_method_name = next(iter(method)) # Also set the color map minimum to the threshold value... self.threshold = find_orientations['threshold'] self.filter_maps = find_orientations['orientation_maps']['filter_maps'] key = '_write_scored_orientations' self.write_scored_orientations = find_orientations.get(key, False) self.working_dir = config.get('working_dir', HexrdConfig().working_dir)
def on_eta_max_changed(self, max_value): """Sync min when max is changed.""" min_value = HexrdConfig().polar_res_eta_min update_min = False if max_value < min_value: min_value = max_value update_min = True elif max_value - min_value > 360.0: min_value = max_value - 360.0 update_min = True if update_min: blocked = QSignalBlocker(self.ui.polar_res_eta_min) # noqa: F841 self.ui.polar_res_eta_min.setValue(min_value) HexrdConfig().set_polar_res_eta_min(min_value, rerender=False) HexrdConfig().polar_res_eta_max = max_value
def on_eta_min_changed(self, min_value): """Sync max when min is changed.""" max_value = HexrdConfig().polar_res_eta_max update_max = False if min_value > max_value: max_value = min_value update_max = True elif max_value - min_value > 360.0: max_value = min_value + 360.0 update_max = True if update_max: blocked = QSignalBlocker(self.ui.polar_res_eta_max) # noqa: F841 self.ui.polar_res_eta_max.setValue(max_value) HexrdConfig().set_polar_res_eta_max(max_value, rerender=False) HexrdConfig().polar_res_eta_min = min_value
def update_table_selections(self): # This updates the table selections based on the exclusions material = HexrdConfig().active_material selection_model = self.ui.table.selectionModel() blocker = QSignalBlocker(selection_model) # noqa: F841 selection_model.clear() plane_data = material.planeData for i, exclude in enumerate(plane_data.exclusions): if exclude: continue # Add the row to the selections model_index = selection_model.model().index(i, 0) command = QItemSelectionModel.Select | QItemSelectionModel.Rows selection_model.select(model_index, command)
def setup_selectors(self): # Build combo boxes in code to assign columns in grains data blocker = QSignalBlocker(self.ui.plot_color_option) # noqa: F841 self.ui.plot_color_option.clear() self.ui.plot_color_option.addItem('Completeness', 1) self.ui.plot_color_option.addItem('Goodness of Fit', 2) self.ui.plot_color_option.addItem('Equivalent Strain', -1) self.ui.plot_color_option.addItem('XX Strain', 15) self.ui.plot_color_option.addItem('YY Strain', 16) self.ui.plot_color_option.addItem('ZZ Strain', 17) self.ui.plot_color_option.addItem('YZ Strain', 18) self.ui.plot_color_option.addItem('XZ Strain', 19) self.ui.plot_color_option.addItem('XY Strain', 20) index = self.ui.plot_color_option.findData(-1) self.ui.plot_color_option.setCurrentIndex(index)
def update_gui(self): if self.overlay is None: return blockers = [QSignalBlocker(w) for w in self.widgets] # noqa: F841 self.tth_width_gui = self.tth_width_config self.offset_gui = self.offset_config if 'refinements' in self.overlay: self.refinements = self.overlay['refinements'] else: self.refinements = DEFAULT_POWDER_REFINEMENTS self.update_enable_states() self.update_refinement_options()