class ResultImageView(ImageView): """ :type _settings PartSettings: """ def __init__(self, settings: PartSettings, channel_property: ChannelProperty, name: str): super().__init__(settings, channel_property, name) self._channel_control_top = True self.only_border = QCheckBox("") self.image_state.only_borders = False self.only_border.setChecked(self.image_state.only_borders) self.only_border.stateChanged.connect(self.image_state.set_borders) self.opacity = QDoubleSpinBox() self.opacity.setRange(0, 1) self.opacity.setValue(self.image_state.opacity) self.opacity.setSingleStep(0.1) self.opacity.valueChanged.connect(self.image_state.set_opacity) self.opacity.setMinimumWidth(500) self.label1 = QLabel("Borders:") self.label2 = QLabel("Opacity:") self.btn_layout.insertWidget(3, self.label1) self.btn_layout.insertWidget(4, self.only_border) self.btn_layout.insertWidget(5, self.label2) self.btn_layout.insertWidget(6, self.opacity) self.label1.setVisible(False) self.label2.setVisible(False) self.opacity.setVisible(False) self.only_border.setVisible(False) def any_segmentation(self): for image_info in self.image_info.values(): if image_info.segmentation is not None: return True return False @Slot() @Slot(SegmentationInfo) def set_segmentation(self, segmentation_info: Optional[SegmentationInfo] = None, image: Optional[Image] = None) -> None: super().set_segmentation(segmentation_info, image) show = self.any_segmentation() self.label1.setVisible(show) self.label2.setVisible(show) self.opacity.setVisible(show) self.only_border.setVisible(show) def resizeEvent(self, event: QResizeEvent): if event.size().width() > 700 and not self._channel_control_top: w = self.btn_layout2.takeAt(0).widget() self.btn_layout.takeAt(2) # noinspection PyArgumentList self.btn_layout.insertWidget(2, w) self._channel_control_top = True elif event.size().width() <= 700 and self._channel_control_top: w = self.btn_layout.takeAt(2).widget() self.btn_layout.insertStretch(2, 1) # noinspection PyArgumentList self.btn_layout2.insertWidget(0, w) self._channel_control_top = False
class HighlightWindow(PyDialog): """ +-----------+ | Highlight | +--------------------------+ | Nodes ______ | | Elements ______ | | | | Highlight Close | +--------------------------+ """ def __init__(self, data, win_parent=None): """ Saves the data members from data and performs type checks """ PyDialog.__init__(self, data, win_parent) gui = win_parent if gui is None: # pragma: no cover self.highlight_color_float = [0., 0., 0.] self.highlight_color_int = [0, 0, 0] self._highlight_opacity = 0.9 else: self.highlight_color_float = gui.settings.highlight_color self.highlight_color_int = [int(val) for val in self.highlight_color_float] #self.highlight_color_int = gui.settings.highlight_color_int self._highlight_opacity = gui.settings.highlight_opacity self._updated_highlight = False self.actors = [] self._default_font_size = data['font_size'] self.model_name = data['model_name'] assert len(self.model_name) > 0, self.model_name #self._default_annotation_size = data['annotation_size'] # int #self.default_magnify = data['magnify'] if 'nodes_pound' in data: # testing nodes_pound = data['nodes_pound'] elements_pound = data['elements_pound'] nodes = np.arange(1, nodes_pound+1) elements = np.arange(1, elements_pound+1) else: # gui nodes = gui.get_node_ids(model_name=self.model_name) elements = gui.get_element_ids(model_name=self.model_name) nodes_pound = nodes.max() elements_pound = elements.max() self.nodes = nodes self.elements = elements self._nodes_pound = nodes_pound self._elements_pound = elements_pound self.setWindowTitle('Highlight') self.create_widgets() self.create_layout() self.set_connections() self.on_font(self._default_font_size) #self.show() def create_widgets(self): """creates the display window""" # Text Size model_name = self.model_name self.nodes_label = QLabel("Nodes:") self.nodes_edit = QNodeEdit(self, model_name, pick_style='area', tab_to_next=False) self.elements_label = QLabel("Elements:") self.elements_edit = QElementEdit(self, model_name, pick_style='area', tab_to_next=False) #----------------------------------------------------------------------- # Highlight Color self.highlight_opacity_label = QLabel("Highlight Opacity:") self.highlight_opacity_edit = QDoubleSpinBox(self) self.highlight_opacity_edit.setValue(self._highlight_opacity) self.highlight_opacity_edit.setRange(0.1, 1.0) self.highlight_opacity_edit.setDecimals(1) self.highlight_opacity_edit.setSingleStep(0.1) self.highlight_opacity_button = QPushButton("Default") # Text Color self.highlight_color_label = QLabel("Highlight Color:") self.highlight_color_edit = QPushButtonColor(self.highlight_color_int) #----------------------------------------------------------------------- # closing self.show_button = QPushButton("Show") self.clear_button = QPushButton("Clear") self.close_button = QPushButton("Close") def create_layout(self): """displays the menu objects""" grid = QGridLayout() irow = 0 grid.addWidget(self.nodes_label, irow, 0) grid.addWidget(self.nodes_edit, irow, 1) irow += 1 grid.addWidget(self.elements_label, irow, 0) grid.addWidget(self.elements_edit, irow, 1) irow += 1 grid.addWidget(self.highlight_color_label, irow, 0) grid.addWidget(self.highlight_color_edit, irow, 1) self.highlight_color_label.setVisible(False) self.highlight_color_edit.setVisible(False) irow += 1 grid.addWidget(self.highlight_opacity_label, irow, 0) grid.addWidget(self.highlight_opacity_edit, irow, 1) self.highlight_opacity_label.setVisible(False) self.highlight_opacity_edit.setVisible(False) irow += 1 #self.create_legend_widgets() #grid2 = self.create_legend_layout() ok_cancel_box = QHBoxLayout() ok_cancel_box.addWidget(self.show_button) ok_cancel_box.addWidget(self.clear_button) ok_cancel_box.addWidget(self.close_button) vbox = QVBoxLayout() vbox.addLayout(grid) #vbox.addStretch() #vbox.addLayout(grid2) vbox.addStretch() vbox.addLayout(ok_cancel_box) self.setLayout(vbox) def set_connections(self): """creates the actions for the menu""" self.highlight_color_edit.clicked.connect(self.on_highlight_color) self.highlight_opacity_edit.valueChanged.connect(self.on_highlight_opacity) self.nodes_edit.textChanged.connect(self.on_validate) self.elements_edit.textChanged.connect(self.on_validate) self.show_button.clicked.connect(self.on_show) self.clear_button.clicked.connect(self.on_remove_actors) self.close_button.clicked.connect(self.on_close) # closeEvent def on_font(self, value=None): """update the font for the current window""" if value is None: value = self.font_size_edit.value() font = QtGui.QFont() font.setPointSize(value) self.setFont(font) def on_highlight_color(self): """ Choose a highlight color TODO: not implemented """ title = "Choose a highlight color" rgb_color_ints = self.highlight_color_int color_edit = self.highlight_color_edit func_name = 'set_highlight_color' passed, rgb_color_ints, rgb_color_floats = self._background_color( title, color_edit, rgb_color_ints, func_name) if passed: self.highlight_color_int = rgb_color_ints self.highlight_color_float = rgb_color_floats def on_highlight_opacity(self, value=None): """ update the highlight opacity TODO: not implemented """ if value is None: value = self.highlight_opacity_edit.value() self._highlight_opacity = value if self.win_parent is not None: self.win_parent.settings.set_highlight_opacity(value) def _background_color(self, title, color_edit, rgb_color_ints, func_name): """helper method for ``on_background_color`` and ``on_background_color2``""" passed, rgb_color_ints, rgb_color_floats = self.on_color( color_edit, rgb_color_ints, title) if passed: if self.win_parent is not None: settings = self.win_parent.settings func_background_color = getattr(settings, func_name) func_background_color(rgb_color_floats) return passed, rgb_color_ints, rgb_color_floats def on_color(self, color_edit, rgb_color_ints, title): """pops a color dialog""" col = QColorDialog.getColor(QtGui.QColor(*rgb_color_ints), self, title) if not col.isValid(): return False, rgb_color_ints, None color_float = col.getRgbF()[:3] # floats color_int = [int(colori * 255) for colori in color_float] assert isinstance(color_float[0], float), color_float assert isinstance(color_int[0], int), color_int color_edit.setStyleSheet( "QPushButton {" "background-color: rgb(%s, %s, %s);" % tuple(color_int) + #"border:1px solid rgb(255, 170, 255); " "}") return True, color_int, color_float #--------------------------------------------------------------------------- def on_validate(self): """makes sure that all attributes are valid before doing any actions""" unused_nodes, flag1 = check_patran_syntax(self.nodes_edit, pound=self._nodes_pound) unused_elements, flag2 = check_patran_syntax(self.elements_edit, pound=self._elements_pound) if all([flag1, flag2]): self.out_data['clicked_ok'] = True return True return False def on_show(self): """show the highlight""" passed = self.on_validate() self.parent().mouse_actions.get_grid_selected(self.model_name) if passed and self.win_parent is not None: nodes, unused_flag1 = check_patran_syntax(self.nodes_edit, pound=self._nodes_pound) elements, unused_flag2 = check_patran_syntax( self.elements_edit, pound=self._elements_pound) if len(nodes) == 0 and len(elements) == 0: return False nodes_filtered = np.intersect1d(self.nodes, nodes) elements_filtered = np.intersect1d(self.elements, elements) nnodes = len(nodes_filtered) nelements = len(elements_filtered) if nnodes == 0 and nelements == 0: return False self.on_remove_actors() gui = self.parent() mouse_actions = gui.mouse_actions grid = mouse_actions.get_grid_selected(self.model_name) actors = create_highlighted_actors( gui, grid, all_nodes=self.nodes, nodes=nodes_filtered, all_elements=self.elements, elements=elements_filtered) if actors: add_actors_to_gui(gui, actors, render=True) self.actors = actors return passed def on_remove_actors(self): """removes multiple vtk actors""" gui = self.parent() if gui is not None: remove_actors_from_gui(gui, self.actors, render=True) self.actors = [] def on_close(self): """close the window""" self.on_remove_actors() self.out_data['close'] = True self.close()
class EditGeometryProperties(PyDialog): force = True def __init__(self, data, win_parent=None): """ +------------------+ | Edit Actor Props | +------------------+------+ | Name1 | | Name2 | | Name3 | | Name4 | | | | Active_Name main | | Color box | | Line_Width 2 | | Point_Size 2 | | Bar_Scale 2 | | Opacity 0.5 | | Show/Hide | | | | Apply OK Cancel | +-------------------------+ """ PyDialog.__init__(self, data, win_parent) self.set_font_size(data['font_size']) del self.out_data['font_size'] self.setWindowTitle('Edit Geometry Properties') self.allow_update = True #default #self.win_parent = win_parent #self.out_data = data self.keys = sorted(data.keys()) self.keys = data.keys() keys = self.keys #nrows = len(keys) self.active_key = 'main' items = list(keys) header_labels = ['Groups'] table_model = Model(items, header_labels, self) view = SingleChoiceQTableView(self) #Call your custom QTableView here view.setModel(table_model) #if qt_version == 4: #view.horizontalHeader().setSectionResizeMode(QHeaderView.Stretch) self.table = view #self.opacity_edit.valueChanged.connect(self.on_opacity) #mListWidget, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(itemClicked(QListWidgetItem*))); #self.table.itemClicked.connect(self.table.mouseDoubleClickEvent) actor_obj = data[self.active_key] name = actor_obj.name line_width = actor_obj.line_width point_size = actor_obj.point_size bar_scale = actor_obj.bar_scale opacity = actor_obj.opacity color = actor_obj.color show = actor_obj.is_visible self.representation = actor_obj.representation # table header = self.table.horizontalHeader() header.setStretchLastSection(True) self._default_is_apply = False self.name = QLabel("Name:") self.name_edit = QLineEdit(str(name)) self.name_edit.setDisabled(True) self.color = QLabel("Color:") self.color_edit = QPushButton() #self.color_edit.setFlat(True) color = self.out_data[self.active_key].color qcolor = QtGui.QColor() qcolor.setRgb(*color) #print('color =%s' % str(color)) palette = QtGui.QPalette(self.color_edit.palette()) # make a copy of the palette #palette.setColor(QtGui.QPalette.Active, QtGui.QPalette.Base, \ #qcolor) palette.setColor(QtGui.QPalette.Background, QtGui.QColor('blue')) # ButtonText self.color_edit.setPalette(palette) self.color_edit.setStyleSheet("QPushButton {" "background-color: rgb(%s, %s, %s);" % tuple(color) + #"border:1px solid rgb(255, 170, 255); " "}") self.use_slider = True self.is_opacity_edit_active = False self.is_opacity_edit_slider_active = False self.is_line_width_edit_active = False self.is_line_width_edit_slider_active = False self.is_point_size_edit_active = False self.is_point_size_edit_slider_active = False self.is_bar_scale_edit_active = False self.is_bar_scale_edit_slider_active = False self.opacity = QLabel("Opacity:") self.opacity_edit = QDoubleSpinBox(self) self.opacity_edit.setRange(0.1, 1.0) self.opacity_edit.setDecimals(1) self.opacity_edit.setSingleStep(0.1) self.opacity_edit.setValue(opacity) if self.use_slider: self.opacity_slider_edit = QSlider(QtCore.Qt.Horizontal) self.opacity_slider_edit.setRange(1, 10) self.opacity_slider_edit.setValue(opacity * 10) self.opacity_slider_edit.setTickInterval(1) self.opacity_slider_edit.setTickPosition(QSlider.TicksBelow) self.line_width = QLabel("Line Width:") self.line_width_edit = QSpinBox(self) self.line_width_edit.setRange(1, MAX_LINE_WIDTH) self.line_width_edit.setSingleStep(1) self.line_width_edit.setValue(line_width) if self.use_slider: self.line_width_slider_edit = QSlider(QtCore.Qt.Horizontal) self.line_width_slider_edit.setRange(1, MAX_LINE_WIDTH) self.line_width_slider_edit.setValue(line_width) self.line_width_slider_edit.setTickInterval(1) self.line_width_slider_edit.setTickPosition(QSlider.TicksBelow) if self.representation in ['point', 'surface']: self.line_width.setEnabled(False) self.line_width_edit.setEnabled(False) self.line_width_slider_edit.setEnabled(False) self.point_size = QLabel("Point Size:") self.point_size_edit = QSpinBox(self) self.point_size_edit.setRange(1, MAX_POINT_SIZE) self.point_size_edit.setSingleStep(1) self.point_size_edit.setValue(point_size) self.point_size.setVisible(False) self.point_size_edit.setVisible(False) if self.use_slider: self.point_size_slider_edit = QSlider(QtCore.Qt.Horizontal) self.point_size_slider_edit.setRange(1, MAX_POINT_SIZE) self.point_size_slider_edit.setValue(point_size) self.point_size_slider_edit.setTickInterval(1) self.point_size_slider_edit.setTickPosition(QSlider.TicksBelow) self.point_size_slider_edit.setVisible(False) if self.representation in ['wire', 'surface']: self.point_size.setEnabled(False) self.point_size_edit.setEnabled(False) if self.use_slider: self.point_size_slider_edit.setEnabled(False) self.bar_scale = QLabel("Bar Scale:") self.bar_scale_edit = QDoubleSpinBox(self) #self.bar_scale_edit.setRange(0.01, 1.0) # was 0.1 #self.bar_scale_edit.setRange(0.05, 5.0) self.bar_scale_edit.setDecimals(1) #self.bar_scale_edit.setSingleStep(bar_scale / 10.) self.bar_scale_edit.setSingleStep(0.1) self.bar_scale_edit.setValue(bar_scale) #if self.use_slider: #self.bar_scale_slider_edit = QSlider(QtCore.Qt.Horizontal) #self.bar_scale_slider_edit.setRange(1, 100) # 1/0.05 = 100/5.0 #self.bar_scale_slider_edit.setValue(opacity * 0.05) #self.bar_scale_slider_edit.setTickInterval(10) #self.bar_scale_slider_edit.setTickPosition(QSlider.TicksBelow) if self.representation != 'bar': self.bar_scale.setEnabled(False) self.bar_scale_edit.setEnabled(False) self.bar_scale.setVisible(False) self.bar_scale_edit.setVisible(False) #self.bar_scale_slider_edit.setVisible(False) #self.bar_scale_slider_edit.setEnabled(False) # show/hide self.checkbox_show = QCheckBox("Show") self.checkbox_hide = QCheckBox("Hide") self.checkbox_show.setChecked(show) self.checkbox_hide.setChecked(not show) if name == 'main': self.color.setEnabled(False) self.color_edit.setEnabled(False) self.point_size.setEnabled(False) self.point_size_edit.setEnabled(False) if self.use_slider: self.point_size_slider_edit.setEnabled(False) self.cancel_button = QPushButton("Close") self.create_layout() self.set_connections() def on_delete(self, irow): """deletes an actor based on the row number""" if irow == 0: # main return nkeys = len(self.keys) if nkeys in [0, 1]: return name = self.keys[irow] nrows = nkeys - 1 self.keys.pop(irow) header_labels = ['Groups'] table_model = Model(self.keys, header_labels, self) self.table.setModel(table_model) if len(self.keys) == 0: self.update() self.set_as_null() return if irow == nrows: irow -= 1 new_name = self.keys[irow] self.update_active_name(new_name) if self.is_gui: self.win_parent.delete_actor(name) def set_as_null(self): """sets the null case""" self.name.setVisible(False) self.name_edit.setVisible(False) self.color.setVisible(False) self.color_edit.setVisible(False) self.line_width.setVisible(False) self.line_width_edit.setVisible(False) self.point_size.setVisible(False) self.point_size_edit.setVisible(False) self.bar_scale.setVisible(False) self.bar_scale_edit.setVisible(False) self.opacity.setVisible(False) self.opacity_edit.setVisible(False) self.opacity_slider_edit.setVisible(False) self.point_size_slider_edit.setVisible(False) self.line_width_slider_edit.setVisible(False) self.checkbox_show.setVisible(False) self.checkbox_hide.setVisible(False) def on_update_geometry_properties_window(self, data): """Not Implemented""" return #new_keys = sorted(data.keys()) #if self.active_key in new_keys: #i = new_keys.index(self.active_key) #else: #i = 0 #self.table.update_data(new_keys) #self.out_data = data #self.update_active_key(i) def update_active_key(self, index): """ Parameters ---------- index : PyQt4.QtCore.QModelIndex the index of the list Internal Parameters ------------------- name : str the name of obj obj : CoordProperties, AltGeometry the storage object for things like line_width, point_size, etc. """ name = str(index.data()) #print('name = %r' % name) #i = self.keys.index(self.active_key) self.update_active_name(name) def update_active_name(self, name): self.active_key = name self.name_edit.setText(name) obj = self.out_data[name] if isinstance(obj, CoordProperties): opacity = 1.0 representation = 'coord' is_visible = obj.is_visible elif isinstance(obj, AltGeometry): line_width = obj.line_width point_size = obj.point_size bar_scale = obj.bar_scale opacity = obj.opacity representation = obj.representation is_visible = obj.is_visible self.color_edit.setStyleSheet("QPushButton {" "background-color: rgb(%s, %s, %s);" % tuple(obj.color) + #"border:1px solid rgb(255, 170, 255); " "}") self.allow_update = False self.force = False self.line_width_edit.setValue(line_width) self.point_size_edit.setValue(point_size) self.bar_scale_edit.setValue(bar_scale) self.force = True self.allow_update = True else: raise NotImplementedError(obj) #allowed_representations = [ #'main', 'surface', 'coord', 'toggle', 'wire', 'point', 'bar'] if self.representation != representation: self.representation = representation #if representation not in allowed_representations: #msg = 'name=%r; representation=%r is invalid\nrepresentations=%r' % ( #name, representation, allowed_representations) if self.representation == 'coord': self.color.setVisible(False) self.color_edit.setVisible(False) self.line_width.setVisible(False) self.line_width_edit.setVisible(False) self.point_size.setVisible(False) self.point_size_edit.setVisible(False) self.bar_scale.setVisible(False) self.bar_scale_edit.setVisible(False) self.opacity.setVisible(False) self.opacity_edit.setVisible(False) if self.use_slider: self.opacity_slider_edit.setVisible(False) self.point_size_slider_edit.setVisible(False) self.line_width_slider_edit.setVisible(False) #self.bar_scale_slider_edit.setVisible(False) else: self.color.setVisible(True) self.color_edit.setVisible(True) self.line_width.setVisible(True) self.line_width_edit.setVisible(True) self.point_size.setVisible(True) self.point_size_edit.setVisible(True) self.bar_scale.setVisible(True) #self.bar_scale_edit.setVisible(True) self.opacity.setVisible(True) self.opacity_edit.setVisible(True) if self.use_slider: self.opacity_slider_edit.setVisible(True) self.line_width_slider_edit.setVisible(True) self.point_size_slider_edit.setVisible(True) #self.bar_scale_slider_edit.setVisible(True) if name == 'main': self.color.setEnabled(False) self.color_edit.setEnabled(False) self.point_size.setEnabled(False) self.point_size_edit.setEnabled(False) self.line_width.setEnabled(True) self.line_width_edit.setEnabled(True) self.bar_scale.setEnabled(False) self.bar_scale_edit.setEnabled(False) show_points = False show_line_width = True show_bar_scale = False if self.use_slider: self.line_width_slider_edit.setEnabled(True) #self.bar_scale_slider_edit.setVisible(False) else: self.color.setEnabled(True) self.color_edit.setEnabled(True) show_points = False if self.representation in ['point', 'wire+point']: show_points = True show_line_width = False if self.representation in ['wire', 'wire+point', 'bar', 'toggle']: show_line_width = True if representation == 'bar': show_bar_scale = True else: show_bar_scale = False #self.bar_scale_button.setVisible(show_bar_scale) #self.bar_scale_edit.setSingleStep(bar_scale / 10.) #if self.use_slider: #self.bar_scale_slider_edit.setEnabled(False) self.point_size.setEnabled(show_points) self.point_size_edit.setEnabled(show_points) self.point_size.setVisible(show_points) self.point_size_edit.setVisible(show_points) self.line_width.setEnabled(show_line_width) self.line_width_edit.setEnabled(show_line_width) self.bar_scale.setEnabled(show_bar_scale) self.bar_scale_edit.setEnabled(show_bar_scale) self.bar_scale.setVisible(show_bar_scale) self.bar_scale_edit.setVisible(show_bar_scale) if self.use_slider: self.point_size_slider_edit.setEnabled(show_points) self.point_size_slider_edit.setVisible(show_points) self.line_width_slider_edit.setEnabled(show_line_width) #if self.representation in ['wire', 'surface']: self.opacity_edit.setValue(opacity) #if self.use_slider: #self.opacity_slider_edit.setValue(opacity*10) self.checkbox_show.setChecked(is_visible) self.checkbox_hide.setChecked(not is_visible) passed = self.on_validate() #self.on_apply(force=True) # TODO: was turned on...do I want this??? #self.allow_update = True def create_layout(self): ok_cancel_box = QHBoxLayout() ok_cancel_box.addWidget(self.cancel_button) grid = QGridLayout() irow = 0 grid.addWidget(self.name, irow, 0) grid.addWidget(self.name_edit, irow, 1) irow += 1 grid.addWidget(self.color, irow, 0) grid.addWidget(self.color_edit, irow, 1) irow += 1 grid.addWidget(self.opacity, irow, 0) if self.use_slider: grid.addWidget(self.opacity_edit, irow, 2) grid.addWidget(self.opacity_slider_edit, irow, 1) else: grid.addWidget(self.opacity_edit, irow, 1) irow += 1 grid.addWidget(self.line_width, irow, 0) if self.use_slider: grid.addWidget(self.line_width_edit, irow, 2) grid.addWidget(self.line_width_slider_edit, irow, 1) else: grid.addWidget(self.line_width_edit, irow, 1) irow += 1 grid.addWidget(self.point_size, irow, 0) if self.use_slider: grid.addWidget(self.point_size_edit, irow, 2) grid.addWidget(self.point_size_slider_edit, irow, 1) else: grid.addWidget(self.point_size_edit, irow, 1) irow += 1 grid.addWidget(self.bar_scale, irow, 0) if self.use_slider and 0: grid.addWidget(self.bar_scale_edit, irow, 2) grid.addWidget(self.bar_scale_slider_edit, irow, 1) else: grid.addWidget(self.bar_scale_edit, irow, 1) irow += 1 checkboxs = QButtonGroup(self) checkboxs.addButton(self.checkbox_show) checkboxs.addButton(self.checkbox_hide) vbox = QVBoxLayout() vbox.addWidget(self.table, stretch=1) vbox.addLayout(grid) vbox1 = QVBoxLayout() vbox1.addWidget(self.checkbox_show) vbox1.addWidget(self.checkbox_hide) vbox.addLayout(vbox1) vbox.addStretch() #vbox.addWidget(self.check_apply) vbox.addLayout(ok_cancel_box) self.setLayout(vbox) def set_connections(self): self.opacity_edit.valueChanged.connect(self.on_opacity) self.line_width_edit.valueChanged.connect(self.on_line_width) self.point_size_edit.valueChanged.connect(self.on_point_size) self.bar_scale_edit.valueChanged.connect(self.on_bar_scale) if self.use_slider: self.opacity_slider_edit.valueChanged.connect(self.on_opacity_slider) self.line_width_slider_edit.valueChanged.connect(self.on_line_width_slider) self.point_size_slider_edit.valueChanged.connect(self.on_point_size_slider) #self.bar_scale_slider_edit.valueChanged.connect(self.on_bar_scale_slider) # self.connect(self.opacity_edit, QtCore.SIGNAL('clicked()'), self.on_opacity) # self.connect(self.line_width, QtCore.SIGNAL('clicked()'), self.on_line_width) # self.connect(self.point_size, QtCore.SIGNAL('clicked()'), self.on_point_size) if qt_version == 4: self.connect(self, QtCore.SIGNAL('triggered()'), self.closeEvent) self.color_edit.clicked.connect(self.on_color) self.checkbox_show.clicked.connect(self.on_show) self.checkbox_hide.clicked.connect(self.on_hide) self.cancel_button.clicked.connect(self.on_cancel) # closeEvent def keyPressEvent(self, event): if event.key() == QtCore.Qt.Key_Escape: self.close() def closeEvent(self, event): self.on_cancel() def on_color(self): """called when the user clicks on the color box""" name = self.active_key obj = self.out_data[name] rgb_color_ints = obj.color msg = name col = QColorDialog.getColor(QtGui.QColor(*rgb_color_ints), self, "Choose a %s color" % msg) if col.isValid(): color_float = col.getRgbF()[:3] obj.color = color_float color_int = [int(colori * 255) for colori in color_float] self.color_edit.setStyleSheet("QPushButton {" "background-color: rgb(%s, %s, %s);" % tuple(color_int) + #"border:1px solid rgb(255, 170, 255); " "}") self.on_apply(force=self.force) #print(self.allow_update) def on_show(self): """shows the actor""" name = self.active_key is_checked = self.checkbox_show.isChecked() self.out_data[name].is_visible = is_checked self.on_apply(force=self.force) def on_hide(self): """hides the actor""" name = self.active_key is_checked = self.checkbox_hide.isChecked() self.out_data[name].is_visible = not is_checked self.on_apply(force=self.force) def on_line_width(self): """increases/decreases the wireframe (for solid bodies) or the bar thickness""" self.is_line_width_edit_active = True name = self.active_key line_width = self.line_width_edit.value() self.out_data[name].line_width = line_width if not self.is_line_width_edit_slider_active: if self.use_slider: self.line_width_slider_edit.setValue(line_width) self.is_line_width_edit_active = False self.on_apply(force=self.force) self.is_line_width_edit_active = False def on_line_width_slider(self): """increases/decreases the wireframe (for solid bodies) or the bar thickness""" self.is_line_width_edit_slider_active = True #name = self.active_key line_width = self.line_width_slider_edit.value() if not self.is_line_width_edit_active: self.line_width_edit.setValue(line_width) self.is_line_width_edit_slider_active = False def on_point_size(self): """increases/decreases the point size""" self.is_point_size_edit_active = True name = self.active_key point_size = self.point_size_edit.value() self.out_data[name].point_size = point_size if not self.is_point_size_edit_slider_active: if self.use_slider: self.point_size_slider_edit.setValue(point_size) self.is_point_size_edit_active = False self.on_apply(force=self.force) self.is_point_size_edit_active = False def on_point_size_slider(self): """increases/decreases the point size""" self.is_point_size_edit_slider_active = True #name = self.active_key point_size = self.point_size_slider_edit.value() if not self.is_point_size_edit_active: self.point_size_edit.setValue(point_size) self.is_point_size_edit_slider_active = False def on_bar_scale(self): """ Vectors start at some xyz coordinate and can increase in length. Increases/decreases the length scale factor. """ self.is_bar_scale_edit_active = True name = self.active_key float_bar_scale = self.bar_scale_edit.value() self.out_data[name].bar_scale = float_bar_scale if not self.is_bar_scale_edit_slider_active: #int_bar_scale = int(round(float_bar_scale * 20, 0)) #if self.use_slider: #self.bar_scale_slider_edit.setValue(int_bar_scale) self.is_bar_scale_edit_active = False self.on_apply(force=self.force) self.is_bar_scale_edit_active = False def on_bar_scale_slider(self): """ Vectors start at some xyz coordinate and can increase in length. Increases/decreases the length scale factor. """ self.is_bar_scale_edit_slider_active = True #name = self.active_key int_bar_scale = self.bar_scale_slider_edit.value() if not self.is_bar_scale_edit_active: float_bar_scale = int_bar_scale / 20. self.bar_scale_edit.setValue(float_bar_scale) self.is_bar_scale_edit_slider_active = False def on_opacity(self): """ opacity = 1.0 (solid/opaque) opacity = 0.0 (invisible) """ self.is_opacity_edit_active = True name = self.active_key float_opacity = self.opacity_edit.value() self.out_data[name].opacity = float_opacity if not self.is_opacity_edit_slider_active: int_opacity = int(round(float_opacity * 10, 0)) if self.use_slider: self.opacity_slider_edit.setValue(int_opacity) self.is_opacity_edit_active = False self.on_apply(force=self.force) self.is_opacity_edit_active = False def on_opacity_slider(self): """ opacity = 1.0 (solid/opaque) opacity = 0.0 (invisible) """ self.is_opacity_edit_slider_active = True #name = self.active_key int_opacity = self.opacity_slider_edit.value() if not self.is_opacity_edit_active: float_opacity = int_opacity / 10. self.opacity_edit.setValue(float_opacity) self.is_opacity_edit_slider_active = False def on_validate(self): self.out_data['clicked_ok'] = True self.out_data['clicked_cancel'] = False old_obj = self.out_data[self.active_key] old_obj.line_width = self.line_width_edit.value() old_obj.point_size = self.point_size_edit.value() old_obj.bar_scale = self.bar_scale_edit.value() old_obj.opacity = self.opacity_edit.value() #old_obj.color = self.color_edit old_obj.is_visible = self.checkbox_show.isChecked() return True #name_value, flag0 = self.check_name(self.name_edit) #ox_value, flag1 = self.check_float(self.transparency_edit) #if flag0 and flag1: #self.out_data['clicked_ok'] = True #return True #return False @property def is_gui(self): return hasattr(self.win_parent, 'on_update_geometry_properties') def on_apply(self, force=False): passed = self.on_validate() #print("passed=%s force=%s allow=%s" % (passed, force, self.allow_update)) if (passed or force) and self.allow_update and self.is_gui: #print('obj = %s' % self.out_data[self.active_key]) self.win_parent.on_update_geometry_properties(self.out_data, name=self.active_key) return passed def on_cancel(self): passed = self.on_apply(force=True) if passed: self.close()
class ResultImageView(ImageView): """ :type _settings PartSettings: """ def __init__(self, settings: PartSettings, channel_property: ChannelProperty, name: str): super().__init__(settings, channel_property, name) self._channel_control_top = True self.only_border = QCheckBox("") self.image_state.only_borders = False self.only_border.setChecked(self.image_state.only_borders) self.only_border.stateChanged.connect(self.image_state.set_borders) self.opacity = QDoubleSpinBox() self.opacity.setRange(0, 1) self.opacity.setValue(self.image_state.opacity) self.opacity.setSingleStep(0.1) self.opacity.valueChanged.connect(self.image_state.set_opacity) self.opacity.setMinimumWidth(500) self.channel_control_index = self.btn_layout.indexOf( self.channel_control) self.label1 = QLabel("Borders:") self.label2 = QLabel("Opacity:") self.roi_alternative_select = QComboBox() self.roi_alternative_select.currentTextChanged.connect( self.image_state.set_roi_presented) self.btn_layout.insertWidget(self.channel_control_index + 1, self.label1) self.btn_layout.insertWidget(self.channel_control_index + 2, self.only_border) self.btn_layout.insertWidget(self.channel_control_index + 3, self.label2) self.btn_layout.insertWidget(self.channel_control_index + 4, self.opacity) self.btn_layout.insertWidget(self.channel_control_index + 1, self.roi_alternative_select) self.label1.setVisible(False) self.label2.setVisible(False) self.opacity.setVisible(False) self.only_border.setVisible(False) self.roi_alternative_select.setVisible(False) def any_roi(self): for image_info in self.image_info.values(): if image_info.roi is not None: return True return False def available_alternatives(self): available_alternatives = set() for image_info in self.image_info.values(): if image_info.roi_info.alternative: available_alternatives.update( image_info.roi_info.alternative.keys()) return available_alternatives @Slot() @Slot(ROIInfo) def set_roi(self, roi_info: Optional[ROIInfo] = None, image: Optional[Image] = None) -> None: super().set_roi(roi_info, image) show = self.any_roi() self.label1.setVisible(show) self.label2.setVisible(show) self.opacity.setVisible(show) self.only_border.setVisible(show) self.update_alternatives() def update_alternatives(self): alternatives = self.available_alternatives() self.roi_alternative_select.setVisible(bool(alternatives)) text = self.roi_alternative_select.currentText() block = self.roi_alternative_select.signalsBlocked() self.roi_alternative_select.blockSignals(True) self.roi_alternative_select.clear() self.roi_alternative_select.addItems(["ROI"] + list(alternatives)) self.roi_alternative_select.setCurrentText(text) self.roi_alternative_select.blockSignals(block) def resizeEvent(self, event: QResizeEvent): if event.size().width() > 700 and not self._channel_control_top: w = self.btn_layout2.takeAt(0).widget() self.btn_layout.takeAt(self.channel_control_index) # noinspection PyArgumentList self.btn_layout.insertWidget(self.channel_control_index, w) select = self.btn_layout2.takeAt( self.btn_layout2.indexOf( self.roi_alternative_select)).widget() self.btn_layout.insertWidget(self.channel_control_index + 1, select) self._channel_control_top = True elif event.size().width() <= 700 and self._channel_control_top: w = self.btn_layout.takeAt(self.channel_control_index).widget() self.btn_layout.insertStretch(self.channel_control_index, 1) # noinspection PyArgumentList self.btn_layout2.insertWidget(0, w) select = self.btn_layout.takeAt( self.btn_layout.indexOf(self.roi_alternative_select)).widget() self.btn_layout2.insertWidget(1, select) self._channel_control_top = False
class ResultImageView(ImageView): """ :type _settings PartSettings: """ def __init__(self, settings: PartSettings, channel_property: ChannelProperty, name: str): super().__init__(settings, channel_property, name) self._channel_control_top = True self.only_border = QCheckBox("") self._set_border_from_settings() self.only_border.stateChanged.connect(self._set_border) self.opacity = QDoubleSpinBox() self.opacity.setRange(0, 1) self.opacity.setSingleStep(0.1) self._set_opacity_from_settings() self.opacity.valueChanged.connect(self._set_opacity) self.opacity.setMinimumWidth(500) self.channel_control_index = self.btn_layout.indexOf(self.channel_control) self.label1 = QLabel("Borders:") self.label2 = QLabel("Opacity:") self.roi_alternative_select = QComboBox() self.roi_alternative_select.currentTextChanged.connect(self._set_roi_alternative_version) self.stretch = None self.btn_layout.insertWidget(self.channel_control_index + 1, self.label1) self.btn_layout.insertWidget(self.channel_control_index + 2, self.only_border) self.btn_layout.insertWidget(self.channel_control_index + 3, self.label2) self.btn_layout.insertWidget(self.channel_control_index + 4, self.opacity) self.btn_layout.insertWidget(self.channel_control_index + 1, self.roi_alternative_select) self.channel_control_index = self.btn_layout.indexOf(self.channel_control) self.label1.setVisible(False) self.label2.setVisible(False) self.opacity.setVisible(False) self.only_border.setVisible(False) self.roi_alternative_select.setVisible(False) self.settings.connect_to_profile(f"{self.name}.image_state.only_border", self._set_border_from_settings) self.settings.connect_to_profile(f"{self.name}.image_state.opacity", self._set_opacity_from_settings) def _set_border(self, value: bool): self.settings.set_in_profile(f"{self.name}.image_state.only_border", value) def _set_opacity(self, value: float): self.settings.set_in_profile(f"{self.name}.image_state.opacity", value) def _set_border_from_settings(self): self.only_border.setChecked(self.settings.get_from_profile(f"{self.name}.image_state.only_border", False)) def _set_opacity_from_settings(self): self.opacity.setValue(self.settings.get_from_profile(f"{self.name}.image_state.opacity", 1)) def _set_roi_alternative_version(self, name: str): self.roi_alternative_selection = name self.update_roi_border() def any_roi(self): return any(image_info.roi is not None for image_info in self.image_info.values()) def available_alternatives(self): available_alternatives = set() for image_info in self.image_info.values(): if image_info.roi_info.alternative: available_alternatives.update(image_info.roi_info.alternative.keys()) return available_alternatives @Slot() @Slot(ROIInfo) def set_roi(self, roi_info: Optional[ROIInfo] = None, image: Optional[Image] = None) -> None: super().set_roi(roi_info, image) show = self.any_roi() self.label1.setVisible(show) self.label2.setVisible(show) self.opacity.setVisible(show) self.only_border.setVisible(show) self.update_alternatives() def update_alternatives(self): alternatives = self.available_alternatives() self.roi_alternative_select.setVisible(bool(alternatives)) text = self.roi_alternative_select.currentText() block = self.roi_alternative_select.signalsBlocked() self.roi_alternative_select.blockSignals(True) self.roi_alternative_select.clear() values = ["ROI"] + list(alternatives) self.roi_alternative_select.addItems(values) try: self.roi_alternative_select.setCurrentIndex(values.index(text)) except ValueError: pass self.roi_alternative_select.blockSignals(block) def resizeEvent(self, event: QResizeEvent): if event.size().width() > 800 and not self._channel_control_top: w = self.btn_layout2.takeAt(0).widget() channel_control_index = self.btn_layout.indexOf(self.search_roi_btn) + 1 self.btn_layout.takeAt(channel_control_index) # noinspection PyArgumentList self.btn_layout.insertWidget(channel_control_index, w) select = self.btn_layout2.takeAt(self.btn_layout2.indexOf(self.roi_alternative_select)).widget() self.btn_layout.insertWidget(channel_control_index + 1, select) self._channel_control_top = True elif event.size().width() <= 800 and self._channel_control_top: channel_control_index = self.btn_layout.indexOf(self.channel_control) w = self.btn_layout.takeAt(channel_control_index).widget() self.btn_layout.insertStretch(channel_control_index, 1) # noinspection PyArgumentList self.btn_layout2.insertWidget(0, w) select = self.btn_layout.takeAt(self.btn_layout.indexOf(self.roi_alternative_select)).widget() self.btn_layout2.insertWidget(1, select) self._channel_control_top = False
class ItemPropertyDialog(QDialog): def __init__(self, jsonitem: JsonItem, parent=None): super().__init__(parent) assert jsonitem is not None self.item = jsonitem # name self.nameLabel = QLabel(self.tr("name:")) self.nameLineEdit = QLineEdit(self.item.name or "") self.nameLabel.setBuddy(self.nameLineEdit) # unit self.unitLabel = QLabel(self.tr("unit:")) self.unitLineEdit = QLineEdit(self.item.unit or "") self.unitLabel.setBuddy(self.unitLineEdit) # type self.typeLabel = QLabel(self.tr("type:")) self.typeComboBox = QComboBox() self.typeComboBox.addItems([k for k, t in VALUETYPES]) self.typeComboBox.setCurrentIndex( self.typeComboBox.findText(self.item.type)) self.typeComboBox.currentIndexChanged.connect(self.data_changed) self.typeLabel.setBuddy(self.typeComboBox) # decimals self.decimalsLabel = QLabel(self.tr("decimals:")) self.decimalsSpinBox = QSpinBox() self.decimalsSpinBox.setRange(0, 10) self.decimalsSpinBox.setValue(self.item.decimals or 0) self.decimalsLabel.setBuddy(self.decimalsSpinBox) self.decimalsSpinBox.valueChanged.connect(self.data_changed) self.last_decimals = self.decimalsSpinBox.value() # min self.minLabel = QLabel(self.tr("minimum:")) self.minSpinBox =QDoubleSpinBox() self.minSpinBox.setRange(-sys.maxsize, sys.maxsize) self.minLabel.setBuddy(self.minSpinBox) self.minSpinBox.setValue(self.item.min or 0.0) # max self.maxLabel = QLabel(self.tr("maximum:")) self.maxSpinBox = QDoubleSpinBox() self.maxSpinBox.setRange(-sys.maxsize, sys.maxsize) self.maxSpinBox.setValue(self.item.max or 100.0) # numerator self.scalefactorLabel = QLabel(self.tr("scalefactor:")) self.scalefactorSpinBox = NoZerosDoubleSpinBox() self.scalefactorSpinBox.setRange(-sys.maxsize, sys.maxsize) self.scalefactorSpinBox.setButtonSymbols(QSpinBox.NoButtons) self.scalefactorSpinBox.setDecimals(10) self.scalefactorSpinBox.setValue(self.item.scalefactor or 1) self.scalefactorLabel.setBuddy(self.scalefactorSpinBox) # readonly self.readonlyCheckBox = QCheckBox(self.tr("readonly")) self.readonlyCheckBox.setChecked(Qt.Checked if self.item.readonly else Qt.Unchecked) self.readonlyCheckBox.stateChanged.connect(self.data_changed) # buttons self.buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, Qt.Horizontal ) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) # layout layout = QGridLayout() layout.addWidget(self.nameLabel, 0, 0) layout.addWidget(self.nameLineEdit, 0, 1) layout.addWidget(self.unitLabel, 1, 0) layout.addWidget(self.unitLineEdit, 1, 1) layout.addWidget(self.typeLabel, 2, 0) layout.addWidget(self.typeComboBox, 2, 1) layout.addWidget(self.decimalsLabel, 3, 0) layout.addWidget(self.decimalsSpinBox, 3, 1) layout.addWidget(self.minLabel, 4, 0) layout.addWidget(self.minSpinBox, 4, 1) layout.addWidget(self.maxLabel, 5, 0) layout.addWidget(self.maxSpinBox, 5, 1) layout.addWidget(self.scalefactorLabel, 6, 0) layout.addWidget(self.scalefactorSpinBox, 6, 1) layout.addWidget(self.readonlyCheckBox, 7, 0, 1, 2) layout.addWidget(self.buttons, 8, 0, 1, 2) self.setLayout(layout) # misc self.setWindowTitle("Edit JsonItem '%s'" % self.item.key) self.data_changed() def accept(self): self.item.name = self.nameLineEdit.text() self.item.unit = self.unitLineEdit.text() self.item.decimals = self.decimalsSpinBox.value() self.item.min = self.minSpinBox.value() self.item.max = self.maxSpinBox.value() self.item.scalefactor = self.scalefactorSpinBox.value() self.item.readonly = self.readonlyCheckBox.checkState() == Qt.Checked self.item.type = self.typeComboBox.currentText() return super().accept() def data_changed(self): type_numeric = self.typeComboBox.currentText() not in ('bool', 'str') type_int = self.typeComboBox.currentText() == 'int' readonly = self.readonlyCheckBox.checkState() == Qt.Checked # not used properties invisible self.decimalsSpinBox.setVisible(type_numeric) self.decimalsLabel.setVisible(type_numeric) self.scalefactorSpinBox.setVisible(type_numeric) self.scalefactorLabel.setVisible(type_numeric) self.minSpinBox.setVisible(type_numeric and not readonly) self.minLabel.setVisible(type_numeric and not readonly) self.maxSpinBox.setVisible(type_numeric and not readonly) self.maxLabel.setVisible(type_numeric and not readonly) self.unitLineEdit.setVisible(type_numeric) self.unitLabel.setVisible(type_numeric) # no decimals for int self.minSpinBox.setDecimals(self.decimalsSpinBox.value()) self.maxSpinBox.setDecimals(self.decimalsSpinBox.value()) if type_int: delta = self.decimalsSpinBox.value() - self.last_decimals self.scalefactorSpinBox.setValue( self.scalefactorSpinBox.value() / 10**delta ) self.last_decimals = self.decimalsSpinBox.value()