def set_mounted_style(self, state, clear_background=False): self.mounted_style = state if state: self.setIcon(0, PIN_ICON) self.setBackground(0, QtImport.QBrush(Colors.PLUM)) self.setBackground(1, QtImport.QBrush(Colors.PLUM)) self.setSelected(True) bold_fond = self.font(1) bold_fond.setBold(True) self.setFont(1, bold_fond) if self.parent(): self.parent().setExpanded(True) else: self.setIcon(0, QtImport.QIcon()) if clear_background: self.set_background_color(0) else: queue_entry = self.get_queue_entry() if queue_entry: queue_entry._set_background_color() self.setSelected(False) self.setFontBold(False) self.setText(1, "")
def __init__(self): """ Defines grid view """ QtImport.QGraphicsItem.__init__(self) self.index = None self.rect = QtImport.QRectF(0, 0, 0, 0) self.setPos(10, 10) self.custom_pen = QtImport.QPen(QtImport.Qt.SolidLine) self.custom_pen.setWidth(1) self.custom_pen.setColor(QtImport.Qt.lightGray) self.custom_brush = QtImport.QBrush(QtImport.Qt.SolidPattern) brush_color = QtImport.Qt.white self.custom_brush.setColor(brush_color) self.results = None self.debug_hit_limit = 1e9 self.num_comp_x = None self.num_comp_y = None self.num_holes_x = None self.num_holes_y = None self.offset_hole = 2 self.offset_comp = 10 self.size_hole = None self.size_comp_x = None self.size_comp_y = None self.size_chip_x = None self.size_chip_y = None self.images_per_crystal = 1
def __init__(self, parent, index, state_dict): QtImport.QGraphicsItem.__init__(self) self.setFlags(QtImport.QGraphicsItem.ItemIsSelectable) # QtImport.QGraphicsItem.ItemIsMovable) self.setAcceptDrops(True) self.parent = parent self.rect = QtImport.QRectF(0, 0, 0, 0) self.setPos(state_dict["coord"][0], state_dict["coord"][1]) self.index = index self.state_dict = state_dict self.custom_brush = QtImport.QBrush(QtImport.Qt.SolidPattern)
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 = QtImport.QTreeWidgetItem(info_str_list) self.addTopLevelItem(new_item) if self.topLevelItemCount() % 10 == 0: for col in range(4): new_item.setBackground(col, QtImport.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 paintEvent(self, e): painter = QtImport.QPainter(self) brush = QtImport.QBrush() brush.setColor(self._background_color) brush.setStyle(QtImport.Qt.SolidPattern) rect = QtImport.QRect(0, 0, painter.device().width(), painter.device().height()) painter.fillRect(rect, brush) # Get current state. parent = self.parent() vmin, vmax = parent.minimum(), parent.maximum() value = parent.value() # Define our canvas. d_height = painter.device().height() - (self._padding * 2) d_width = painter.device().width() - (self._padding * 2) # Draw the bars. step_size = d_height / self.n_steps bar_height = step_size * self._bar_solid_percent bar_spacer = step_size * (1 - self._bar_solid_percent) / 2 # Calculate the y-stop position, from the value in range. pc = (value - vmin) / (vmax - vmin) n_steps_to_draw = int(pc * self.n_steps) for n in range(n_steps_to_draw): brush.setColor(QtImport.QColor(self.steps[n])) rect = QtImport.QRect( self._padding, self._padding + d_height - ((1 + n) * step_size) + bar_spacer, d_width, bar_height) painter.fillRect(rect, brush) painter.end()
class QueueItem(QtImport.QTreeWidgetItem): """ Use this class to create a new type of item for the collect tree/queue. """ normal_brush = QtImport.QBrush(QtImport.Qt.black) highlighted_brush = QtImport.QBrush(QtImport.QColor(128, 128, 128)) normal_pen = QtImport.QPen(QtImport.Qt.black) highlighted_pen = QtImport.QPen(QtImport.QColor(128, 128, 128)) bg_brush = QtImport.QBrush(QtImport.QColor(0, 128, 0)) bg_normal_brush = QtImport.QBrush(QtImport.Qt.white) def __init__(self, *args, **kwargs): QtImport.QTreeWidgetItem.__init__(self, args[0]) self.deletable = kwargs.pop("deletable", False) self.pen = QueueItem.normal_pen self.brush = QueueItem.normal_brush self.bg_brush = QueueItem.bg_normal_brush self.previous_bg_brush = QueueItem.bg_normal_brush self._queue_entry = None self._data_model = None self._checkable = True self._previous_check_state = False self._font_is_bold = False self._star = False self._base_tool_tip = "" self.setText(1, "") def listView(self): # remove this return self.treeWidget() def setOn(self, state): """ Backward compatability, because QueueManager and other hwobj are using this method to change state """ if self._checkable: if state: check_state = QtImport.Qt.Checked else: check_state = QtImport.Qt.Unchecked self.setCheckState(0, check_state) else: self.setCheckState(0, QtImport.Qt.Unchecked) def setCheckState(self, column, check_state): """ sets check state for item and all children and parent if they exist """ self._previous_check_state = self.checkState(0) if isinstance(self, DataCollectionGroupQueueItem): self._checkable = False if self.childCount() == 0: self._checkable = True else: for index in range(self.childCount()): if self.child(index)._checkable: self._checkable = True break self.parent().setCheckState(column, check_state) if not self._checkable: check_state = QtImport.Qt.Unchecked QtImport.QTreeWidgetItem.setCheckState(self, column, check_state) if self._queue_entry: self._queue_entry.set_enabled(check_state > 0) if self._data_model: self._data_model.set_enabled(check_state > 0) def set_hidden(self, hidden): self.setHidden(hidden) for index in range(self.childCount()): self.child(index).setHidden(hidden) if self._queue_entry: self._queue_entry.set_enabled(not hidden) if self._data_model: self._data_model.set_enabled(not hidden) def update_check_state(self, new_state): """ in qt3 method was called stateChanged. """ if new_state != self._previous_check_state: self.setCheckState(0, self.checkState(0)) if isinstance(self, DataCollectionGroupQueueItem): for index in range(self.childCount()): self.child(index).setCheckState(0, self.checkState(0)) def move_item(self, after): self.parent().takeChild(self.parent().indexOfChild(self)) after.parent().insertChild(after.parent().indexOfChild(after) + 1, self) container_qe = self.get_queue_entry().get_container() after_qe = after.get_queue_entry() container_qe.swap(after_qe, self.get_queue_entry()) def setHighlighted(self, enable): """ Controls highlighting of the list item. :param enable: Highlighted True, or not highlighted False. :type enable: bool """ if enable: self.pen = QueueItem.highlighted_pen self.brush = QueueItem.highlighted_brush else: self.pen = QueueItem.normal_pen self.brush = QueueItem.normal_brush if self.treeWidget(): self.treeWidget().updateGeometry() def set_background_color(self, color_index): self.previous_bg_brush = self.background(0) color = Colors.QUEUE_ENTRY_COLORS[color_index] self.bg_brush = QtImport.QBrush(color) self.setBackground(0, self.bg_brush) self.setBackground(1, self.bg_brush) def restoreBackgroundColor(self): self.bg_brush = self.previous_bg_brush self.setBackground(0, self.bg_brush) self.setBackground(1, self.bg_brush) def setFontBold(self, state): self._font_is_bold = state def reset_style(self): self.set_background_color(0) self.setFontBold(False) self.setHighlighted(False) def lastItem(self): """ :returns: The last item of this child. :rtype: QueueItem """ if self.childCount() > 0: return self.child(self.childCount()) def set_checkable(self, state): self._checkable = state def set_queue_entry(self, queue_entry): self._queue_entry = queue_entry def get_previous_check_state(self): return self._previous_check_state def get_queue_entry(self): return self._queue_entry def get_model(self): return self._data_model def update_display_name(self): self.setText(0, self._data_model.get_display_name()) def update_tool_tip(self): pass def set_star(self, state): self._star = state def has_star(self): return self._star == True def get_all_grand_children(self): grand_children_list = [] for child_index in range(self.childCount()): for grand_child_index in range( self.child(child_index).childCount()): grand_children_list.append( self.child(child_index).child(grand_child_index)) return grand_children_list def set_strike_out(self, state): font = self.font(0) font.setStrikeOut(state) self.setFont(0, font)
def set_background_color(self, color_index): self.previous_bg_brush = self.background(0) color = Colors.QUEUE_ENTRY_COLORS[color_index] self.bg_brush = QtImport.QBrush(color) self.setBackground(0, self.bg_brush) self.setBackground(1, self.bg_brush)
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 = QtImport.QTreeWidgetItem( self.conf_dialog_layout.summary_treewidget, info_str_list) for col in range(13): sample_treewidget_item.setBackground( col, QtImport.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 = QtImport.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) QtImport.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.reference_image_collection.acquisitions[ 0].acquisition_parameters elif isinstance(item, queue_item.XrayImagingQueueItem): acq_parameters = item_model.acquisition.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 = QtImport.QTreeWidgetItem( collection_group_treewidget_item, info_str_list) for col in range(13): collection_treewidget_item.setBackground( col, QtImport.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 = QtImport.QTreeWidgetItem( self.conf_dialog_layout.file_treewidget, file_str_list) file_treewidgee_item.setTextColor(1, QtImport.Qt.red) file_treewidgee_item.setTextColor(2, QtImport.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).")