def refresh_plate_content(self): self.plate_widget.xtal_treewidget.clear() info_str_list = qt_import.QStringList() info_str_list.append(self.plate_content.plate.barcode) info_str_list.append(self.plate_content.plate.plate_type) root_item = qt_import.QTreeWidgetItem( self.plate_widget.xtal_treewidget, info_str_list) root_item.setExpanded(True) for xtal in self.plate_content.plate.xtal_list: cell_treewidget_item = None if not cell_treewidget_item: cell_treewidget_item = root_item info_str_list = qt_import.QStringList() info_str_list.append(xtal.sample) info_str_list.append(xtal.label) info_str_list.append(xtal.login) info_str_list.append(xtal.row) info_str_list.append(str(xtal.column)) if xtal.comments: info_str_list.append(str(xtal.comments)) xtal_treewidget_item = qt_import.QTreeWidgetItem( cell_treewidget_item, info_str_list) # self.plate_widget.xtal_treewidget.ensureItemVisible(xtal_treewidget_item) self.xtal_map[xtal_treewidget_item] = xtal
def shape_created(self, shape, shape_type): """ Adds information about shape in all shapes treewidget and depending on shape type also information to treewidget of all points/lines/grids """ info_str_list = ( str(self.manager_widget.shapes_treewidget.topLevelItemCount() + 1), shape.get_display_name(), str(True), str(True), str(shape.used_count), ) self.__shape_map[shape] = qt_import.QTreeWidgetItem( self.manager_widget.shapes_treewidget, info_str_list) self.toggle_buttons_enabled() # info_str_list = QStringList() info_str_list = [] info_str_list.append(str(shape.index)) if shape_type == "Point": info_str_list.append(str(shape.get_start_position())) self.manager_widget.point_treewidget.clearSelection() point_treewidget_item = qt_import.QTreeWidgetItem( self.manager_widget.point_treewidget, info_str_list) point_treewidget_item.setSelected(True) self.__point_map[shape] = point_treewidget_item elif shape_type == "Line": (start_index, end_index) = shape.get_points_index() info_str_list.append("Point %d" % start_index) info_str_list.append("Point %d" % end_index) self.manager_widget.line_treewidget.clearSelection() line_treewidget_item = qt_import.QTreeWidgetItem( self.manager_widget.line_treewidget, info_str_list) line_treewidget_item.setSelected(True) self.__line_map[shape] = line_treewidget_item elif shape_type == "Grid": self.manager_widget.grid_treewidget.clearSelection() grid_treewidget_item = qt_import.QTreeWidgetItem( self.manager_widget.grid_treewidget, info_str_list) grid_treewidget_item.setSelected(True) self.__grid_map[shape] = grid_treewidget_item
def shape_created(self, shape, shape_type): if shape_type == "Line": self._lines_widget.lines_treewidget.clearSelection() # info_str_list = QStringList() info_str_list = [] info_str_list.append(shape.get_display_name()) info_str_list.append("%d" % shape.get_points_index()[0]) info_str_list.append("%d" % shape.get_points_index()[1]) lines_treewidget_item = qt_import.QTreeWidgetItem( self._lines_widget.lines_treewidget, info_str_list) lines_treewidget_item.setSelected(True) self._lines_map[shape] = lines_treewidget_item self.lines_treewidget_selection_changed()
def add_pending_connection(self, connection_dict): """Adds pendinf connection""" parameter_list = ( "", connection_dict["senderWindow"], connection_dict["senderObject"], connection_dict["signal"], connection_dict["receiverWindow"], connection_dict["receiverObject"], connection_dict["slot"], ) new_item = qt_import.QTreeWidgetItem(self.connections_treewidget, parameter_list) new_item.setIcon(0, icons.load_icon("button_ok_small")) self.connections_treewidget.addTopLevelItem(new_item)
def add_log_line(self, record): msg = record.getMessage().replace("\n", " ").strip() info_str_list = [] info_str_list.append(record.getLevelName()) info_str_list.append(record.getDate()) info_str_list.append(record.getTime()) info_str_list.append(msg) new_item = qt_import.QTreeWidgetItem(info_str_list) self.addTopLevelItem(new_item) if self.topLevelItemCount() % 10 == 0: for col in range(4): new_item.setBackground(col, qt_import.QBrush(colors.LIGHT_2_GRAY)) if self.max_log_lines and self.max_log_lines > 0: if self.topLevelItemCount() > self.max_log_lines: self.takeTopLevelItem(0) self.scrollToBottom()
def shape_created(self, shape, shape_type): """If a grid is created then adds it to the treewidget. A binding between graphical grid and treewidget item is based on the self._grid_map :param shape: graphics object :type shape: GraphicsLib.GraphicsItem :param shape_type: type of the object (point, line, grid) :type shape_type: str """ if shape_type == "Grid": self._advanced_methods_widget.grid_treewidget.clearSelection() grid_properties = shape.get_properties() info_str_list = [] info_str_list.append(grid_properties["name"]) info_str_list.append("%d" % grid_properties["num_lines"]) info_str_list.append("%d" % grid_properties["num_images_per_line"]) if not self.dc_selected: exp_time = max( float(grid_properties["yOffset"] / 2.245), self._acq_widget.exp_time_validator.bottom() + 0.00001, ) self._acq_widget.acq_widget_layout.exp_time_ledit.setText( "%.6f" % exp_time ) grid_treewidget_item = qt_import.QTreeWidgetItem( self._advanced_methods_widget.grid_treewidget, info_str_list ) self._grid_map[shape] = grid_treewidget_item if not self.dc_selected: grid_treewidget_item.setSelected(True) self.grid_treewidget_item_selection_changed() if self._acq_widget.acq_widget_layout.max_osc_range_cbx.isChecked(): self._acq_widget.update_osc_total_range_limits( grid_properties["num_images_per_line"] ) else: self.update_grid_osc_total_range()
def __add_connection(sender_window, sender, connection): """Adds connection""" new_item = qt_import.QTreeWidgetItem(self.connections_treewidget) window_name = sender_window["name"] new_item.setText(1, window_name) if sender != sender_window: new_item.setText(2, sender["name"]) new_item.setText(4, connection["receiverWindow"]) try: receiver_window = self.configuration.windows[ connection["receiverWindow"]] except KeyError: receiver_window = {} result = False else: result = True if len(connection["receiver"]): # *-object new_item.setText(5, connection["receiver"]) result = result and __receiver_in_window( connection["receiver"], receiver_window) if result: new_item.setIcon(0, icons.load_icon("button_ok_small")) else: new_item.setIcon(0, icons.load_icon("button_cancel_small")) new_item.setText(3, connection["signal"]) new_item.setText(6, connection["slot"])
def set_items(self, checked_items): """Populates information about items to be collected""" self.sample_items = [] self.checked_items = checked_items collection_items = [] current_sample_item = None sample_treewidget_item = None collection_group_treewidget_item = None num_images = 0 file_exists = False interleave_items = 0 self.conf_dialog_layout.summary_treewidget.clear() self.conf_dialog_layout.file_treewidget.clear() self.conf_dialog_layout.interleave_cbx.setChecked(False) self.conf_dialog_layout.interleave_images_num_ledit.setText("") self.conf_dialog_layout.inverse_cbx.setChecked(False) self.conf_dialog_layout.inverse_beam_num_images_ledit.setText("") for item in checked_items: # item_type_name = "" info_str_list = [] acq_parameters = None path_template = None item_model = item.get_model() item_type_name = item_model.get_display_name() if isinstance(item, queue_item.SampleQueueItem): self.sample_items.append(item) current_sample_item = item info_str_list.append(item_model.get_name()) if item.mounted_style: info_str_list.append("Already mounted") else: info_str_list.append("Sample mounting") sample_treewidget_item = qt_import.QTreeWidgetItem( self.conf_dialog_layout.summary_treewidget, info_str_list) for col in range(13): sample_treewidget_item.setBackground( col, qt_import.QBrush(colors.TREE_ITEM_SAMPLE)) sample_treewidget_item.setExpanded(True) elif isinstance(item, queue_item.DataCollectionGroupQueueItem): info_str_list.append(item_type_name) collection_group_treewidget_item = qt_import.QTreeWidgetItem( sample_treewidget_item, info_str_list) collection_group_treewidget_item.setExpanded(True) elif isinstance(item, queue_item.SampleCentringQueueItem): info_str_list.append(item_type_name) qt_import.QTreeWidgetItem(collection_group_treewidget_item, info_str_list) elif isinstance(item, queue_item.DataCollectionQueueItem): acq_parameters = item_model.acquisitions[ 0].acquisition_parameters if not item_model.is_helical() and not item_model.is_mesh(): interleave_items += 1 elif isinstance(item, queue_item.CharacterisationQueueItem): acq_parameters = item_model.reference_image_collection.acquisitions[ 0].acquisition_parameters self.conf_dialog_layout.take_snapshots_combo.setCurrentIndex( self.conf_dialog_layout.take_snapshots_combo.count() - 1) elif isinstance(item, queue_item.XrayCenteringQueueItem): acq_parameters = item_model.mesh_dc.acquisitions[ 0].acquisition_parameters elif isinstance(item, queue_item.XrayImagingQueueItem): acq_parameters = item_model.acquisitions[ 0].acquisition_parameters path_template = item_model.get_path_template() if acq_parameters and path_template: info_str_list.append(item_type_name) info_str_list.append("") info_str_list.append(path_template.directory) # This part is also in data_path_widget. Mote to PathTemplate file_name = path_template.get_image_file_name() file_name = file_name.replace( "%" + path_template.precision + "d", int(path_template.precision) * "#", ) file_name = file_name.strip(" ") info_str_list.append(file_name) info_str_list.append("%.3f keV" % acq_parameters.energy) info_str_list.append("%.2f A" % acq_parameters.resolution) info_str_list.append("%.2f %%" % acq_parameters.transmission) info_str_list.append("%.1f" % acq_parameters.osc_start) info_str_list.append(str(acq_parameters.osc_range)) info_str_list.append(str(acq_parameters.num_images)) info_str_list.append("%s s" % str(acq_parameters.exp_time)) info_str_list.append( str(acq_parameters.num_images * acq_parameters.osc_range)) info_str_list.append( "%s s" % str(acq_parameters.num_images * acq_parameters.exp_time)) collection_treewidget_item = qt_import.QTreeWidgetItem( collection_group_treewidget_item, info_str_list) for col in range(13): collection_treewidget_item.setBackground( col, qt_import.QBrush(colors.TREE_ITEM_COLLECTION)) collection_items.append(item) file_paths = path_template.get_files_to_be_written() num_images += acq_parameters.num_images if len(file_paths) > 20: file_paths = file_paths[:20] for file_path in file_paths: if os.path.exists(file_path): (dir_name, file_name) = os.path.split(file_path) sample_name = current_sample_item.get_model( ).get_display_name() if sample_name is "": sample_name = current_sample_item.get_model( ).loc_str file_str_list = [] file_str_list.append(sample_name) file_str_list.append(dir_name) file_str_list.append(file_name) file_treewidgee_item = qt_import.QTreeWidgetItem( self.conf_dialog_layout.file_treewidget, file_str_list) if hasattr(file_treewidgee_item, "setTextcolor"): file_treewidgee_item.setTextcolor( 1, qt_import.Qt.red) file_treewidgee_item.setTextcolor( 2, qt_import.Qt.red) else: file_treewidgee_item.setForeground( 1, qt_import.QBrush(qt_import.Qt.red)) file_treewidgee_item.setForeground( 2, qt_import.QBrush(qt_import.Qt.red)) file_exists = True self.conf_dialog_layout.file_gbox.setEnabled(file_exists) self.conf_dialog_layout.interleave_cbx.setEnabled(interleave_items > 1) self.conf_dialog_layout.inverse_cbx.setEnabled(interleave_items == 1) num_samples = len(self.sample_items) num_collections = len(collection_items) for col_index in range( self.conf_dialog_layout.summary_treewidget.columnCount()): if col_index != 2: self.conf_dialog_layout.summary_treewidget.resizeColumnToContents( col_index) self.conf_dialog_layout.summary_label.setText( "Collecting " + str(num_collections) + " collection(s) on " + str(num_samples) + " sample(s) resulting in " + str(num_images) + " image(s).")
def state_changed(self, state_list): self.log_treewidget.clear() # state_list = [state_list] for state in state_list: temp_item = qt_import.QTreeWidgetItem() temp_item.setText( 0, self.get_state_by_name(state["current_state"])["desc"]) temp_item.setText(1, state["start_time"]) temp_item.setText(2, state["end_time"]) temp_item.setText(3, state["total_time"]) temp_item.setText( 4, self.get_state_by_name(state["previous_state"])["desc"]) self.log_treewidget.insertTopLevelItem(0, temp_item) for col in range(5): self.log_treewidget.resizeColumnToContents(col) new_state = state_list[-1] for col, state in enumerate(self.states_list): for row, condition in enumerate(self.cond_list): color = colors.WHITE # if row % 5: # color = colors.WHITE if not col % 5 or not row % 5: color = colors.LIGHT_2_GRAY self.cond_states_table.item(row, col).setBackground(color) self.cond_states_table.item(row, col).setText("") self.cond_states_table.item(row, col).setIcon(qt_import.QIcon()) for translation in self.trans_list: if (translation["source"] == new_state["current_state"] and translation["dest"] == state["name"]): if condition["name"] in translation["conditions_true"]: self.cond_states_table.item( row, col).setBackground(colors.LIGHT_GREEN) # self.cond_states_table.item(row, col).setText(str(index)) elif condition["name"] in translation[ "conditions_false"]: self.cond_states_table.item( row, col).setBackground(colors.LIGHT_RED) # self.cond_states_table.item(row, col).setText(str(index)) if (condition["name"] in translation["conditions_true"] or condition["name"] in translation["conditions_false"]): if condition["value"]: self.cond_states_table.item(row, col).setIcon( self.check_icon) else: self.cond_states_table.item(row, col).setIcon( self.reject_icon) if state["name"] == new_state["current_state"]: if "error" in state.get("type", []): color = colors.LIGHT_RED else: color = colors.LIGHT_GREEN self.cond_states_table.item(row, col).setBackground(color) for graph_node in self.state_graph_node_list: graph_node.setSelected( graph_node.state_dict["name"] == new_state["current_state"]) self.graph_graphics_scene.update()