def __init__(self, parent, realtime_plot=False): qt_import.QWidget.__init__(self, parent) self.axis_x_array = [] self.axis_y_array = [] self.realtime_plot = realtime_plot self.pymca_graph = Plot(self) self.pymca_graph.showGrid() self.info_label = qt_import.QLabel("", self) self.info_label.setAlignment(qt_import.Qt.AlignRight) _main_vlayout = qt_import.QVBoxLayout(self) _main_vlayout.addWidget(self.pymca_graph) _main_vlayout.addWidget(self.info_label) _main_vlayout.setSpacing(2) _main_vlayout.setContentsMargins(2, 2, 2, 2) self.setSizePolicy(qt_import.QSizePolicy.Expanding, qt_import.QSizePolicy.Expanding) if PYMCA_EXISTS: qt_import.QObject.connect( self.pymca_graph, qt_import.SIGNAL("QtBlissGraphSignal"), self.handle_graph_signal, ) colors.set_widget_color(self, colors.WHITE)
def _folder_ledit_change(self, new_value): base_image_dir = self._base_image_dir base_proc_dir = self._base_process_dir new_sub_dir = str(new_value).strip(" ") cursor_pos = self.data_path_layout.folder_ledit.cursorPosition() if len(new_value) > 0: available_chars = ( string.ascii_lowercase + string.ascii_uppercase + string.digits + "-_/" ) if self.enable_macros: available_chars += "%" new_value = "".join(i for i in str(new_value) if i in available_chars) # new_value = new_value.replace("\\", "") new_sub_dir = str(new_value).strip(" ") self.data_path_layout.folder_ledit.setText(new_value) self.data_path_layout.folder_ledit.setCursorPosition(cursor_pos) if len(new_sub_dir) > 0: if new_sub_dir[0] == os.path.sep: new_sub_dir = new_sub_dir[1:] new_image_directory = os.path.join(base_image_dir, str(new_sub_dir)) new_proc_dir = os.path.join(base_proc_dir, str(new_sub_dir)) else: new_image_directory = base_image_dir new_proc_dir = base_proc_dir self._data_model.directory = new_image_directory self._data_model.process_directory = new_proc_dir colors.set_widget_color(self.data_path_layout.folder_ledit, colors.WHITE) self.pathTemplateChangedSignal.emit()
def command_done(self): self.executing = False colors.set_widget_color(self, self.standard_color, qt_import.QPalette.Button) if self.run_icon is not None: self.setIcon(self.run_icon) self.setEnabled(True)
def __init__(self, parent=None, name=None, fl=0): qt_import.QWidget.__init__(self, parent, qt_import.Qt.WindowFlags(fl)) if not name: self.setObjectName("RadiationDamageModelWidgetLayout") # Hardware objects ---------------------------------------------------- # Internal variables -------------------------------------------------- # Graphic elements ---------------------------------------------------- self.rad_damage_widget = qt_import.load_ui_file( "radiation_damage_model_widget_layout.ui") # Layout -------------------------------------------------------------- _main_vlayout = qt_import.QVBoxLayout(self) _main_vlayout.addWidget(self.rad_damage_widget) _main_vlayout.setSpacing(0) _main_vlayout.setContentsMargins(0, 0, 0, 0) self.setLayout(_main_vlayout) # Size policies ------------------------------------------------------- # Other --------------------------------------------------------------- self.languageChange() self.setAttribute(qt_import.Qt.WA_WState_Polished) colors.set_widget_color(self, colors.GROUP_BOX_GRAY)
def command_started(self): colors.set_widget_color(self, colors.LIGHT_YELLOW, qt_import.QPalette.Button) if self.stop_icon is not None: self.setIcon(self.stop_icon) self.executing = True self.setEnabled(True)
def detector_distance_state_changed(self, state): if state is None: return detector_distance = HWR.beamline.detector.distance color = ResolutionBrick.STATE_COLORS[state.value] unit = self.units_combobox.currentText() if state == detector_distance.STATES.FAULT: self.setEnabled(False) return if unit == "mm": if state == detector_distance.STATES.READY: self.new_value_ledit.blockSignals(True) self.new_value_ledit.setText("") self.new_value_ledit.blockSignals(False) self.new_value_ledit.setEnabled(True) else: self.new_value_ledit.setEnabled(False) if state == detector_distance.STATES.BUSY: # or \ # state == detector_distance.motor_states.MOVESTARTED: self.stop_button.setEnabled(True) else: self.stop_button.setEnabled(False) colors.set_widget_color(self.new_value_ledit, color)
def gap_value_changed(self, newGap): if newGap[0] is None: self.current_hor_pos_ledit.setText("-") # elif newGap[0] < 0: # self.current_hor_pos_ledit.setText("-") else: self.current_hor_pos_ledit.setText( "%d %sm" % (newGap[0] * 1000, uni_chr(956))) if newGap[1] is None: self.current_ver_pos_ledit.setText("-") # elif newGap[1] < 0: # self.current_ver_pos_ledit.setText("-") else: gap_str = str(newGap[1] * 1000) self.current_ver_pos_ledit.setText( "%d %sm" % (newGap[1] * 1000, uni_chr(956))) colors.set_widget_color( self.hor_pos_dspinbox.lineEdit(), SlitsBrick.CONNECTED_COLOR, qt_import.QPalette.Button, ) colors.set_widget_color( self.ver_pos_dspinbox.lineEdit(), SlitsBrick.CONNECTED_COLOR, qt_import.QPalette.Button, )
def property_changed(self, property_name, old_value, new_value): if property_name == "label": if new_value == "" and self.motor_hwobj is not None: self.label.setText("<i>" + self.motor_hwobj.username + ":</i>") else: self.label.setText(new_value) elif property_name == "mnemonic": if self.motor_hwobj is not None: self.disconnect(self.motor_hwobj, "stateChanged", self.motor_state_changed) self.disconnect( self.motor_hwobj, "valueChanged", self.predefined_position_changed, ) self.motor_hwobj = self.get_hardware_object(new_value) if self.motor_hwobj is not None: self.fill_positions() self.connect(self.motor_hwobj, "stateChanged", self.motor_state_changed) self.connect( self.motor_hwobj, "valueChanged", self.predefined_position_changed, ) #if self.motor_hwobj.is_ready(): # self.predefined_position_changed( # self.motor_hwobj.get_value() # ) if self["label"] == "": lbl = self.motor_hwobj.user_name self.label.setText("<i>" + lbl + ":</i>") colors.set_widget_color( self.positions_combo, colors.LIGHT_YELLOW, qt_import.QPalette.Button, ) self.motor_state_changed(self.motor_hwobj.get_state()) elif property_name == "showMoveButtons": if new_value: self.previous_position_button.show() self.next_position_button.show() else: self.previous_position_button.hide() self.next_position_button.hide() elif property_name == "icons": icons_list = new_value.split() try: self.previous_position_button.setIcon( icons.load_icon(icons_list[0])) self.next_position_button.setIcon( icons.load_icon(icons_list[1])) except BaseException: pass else: BaseWidget.property_changed(self, property_name, old_value, new_value)
def set_color(self, color): if not color: self.qtcolor = None self.color = None colors.set_widget_color( self.change_color_button, colors.BUTTON_ORIGINAL, qt_import.QPalette.Button, ) else: try: rgb = color.rgb() except BaseException: try: self.qtcolor = qt_import.QColor(color) except BaseException: self.qtcolor = qt_import.QColor(qt_import.Qt.green) self.color = self.qtcolor.rgb() else: self.color = self.qtcolor.rgb() else: self.qtcolor = color self.color = rgb colors.set_widget_color( self.change_color_button, self.qtcolor, qt_import.QPalette.Button ) self.parent.cellChanged.emit(self.row, self.col)
def __init__(self, *args): BaseWidget.__init__(self, *args) # Hardware objects ---------------------------------------------------- # Internal values ----------------------------------------------------- # Properties ---------------------------------------------------------- # Signals ------------------------------------------------------------ # Slots --------------------------------------------------------------- # Graphic elements ---------------------------------------------------- self.main_gbox = qt_import.QGroupBox("Aperture", self) self.aperture_diameter_combo = qt_import.QComboBox(self.main_gbox) self.aperture_diameter_combo.setMinimumWidth(100) self.aperture_position_combo = qt_import.QComboBox(self.main_gbox) self.aperture_position_combo.setMinimumWidth(100) # Layout -------------------------------------------------------------- _main_gbox_vlayout = qt_import.QVBoxLayout(self.main_gbox) _main_gbox_vlayout.addWidget(self.aperture_diameter_combo) _main_gbox_vlayout.addWidget(self.aperture_position_combo) _main_gbox_vlayout.addStretch() _main_gbox_vlayout.setSpacing(2) _main_gbox_vlayout.setContentsMargins(0, 0, 0, 0) _main_vlayout = qt_import.QVBoxLayout(self) _main_vlayout.addWidget(self.main_gbox) _main_vlayout.setSpacing(0) # _main_vlayout.addSpacing(0) _main_vlayout.setContentsMargins(2, 2, 2, 2) # Qt signal/slot connections ------------------------------------------ self.aperture_diameter_combo.activated.connect(self.change_diameter) self.aperture_position_combo.activated.connect(self.change_position) # SizePolicies -------------------------------------------------------- # Other --------------------------------------------------------------- colors.set_widget_color( self.aperture_diameter_combo, colors.LIGHT_GREEN, qt_import.QPalette.Button ) colors.set_widget_color( self.aperture_position_combo, colors.LIGHT_GREEN, qt_import.QPalette.Button ) self.aperture_diameter_combo.setMinimumWidth(100) self.aperture_position_combo.setMinimumWidth(100) self.init_aperture() self.connect( HWR.beamline.beam.aperture, "diameterIndexChanged", self.diameter_changed ) self.connect( HWR.beamline.beam.aperture, "valueChanged", self.position_changed )
def step_edited(self, step): """Paints step combobox when value is edited """ colors.set_widget_color( self.step_cbox.lineEdit(), colors.LINE_EDIT_CHANGED, qt_import.QPalette.Button, )
def user_group_changed(self, value): if self.saved_group: msg = "User group changed, press set to apply change" logging.getLogger("GUI").warning(msg) colors.set_widget_color( self.user_group_ledit, colors.LINE_EDIT_CHANGED, qt_import.QPalette.Base ) self.saved_group = False
def status_changed(self, status, status_message): if status: self.status_label.setText("<b>%s</b>" % status.title()) colors.set_widget_color( self.status_label, DETECTOR_STATES.get(status, colors.LIGHT_GRAY), ) self.setToolTip(status_message)
def centring_failed(self, method, centring_status): self.centre_button.command_failed() self.accept_button.setEnabled(True) if self.inside_data_collection: colors.set_widget_color(self.accept_button, self.standard_color) self.reject_button.setEnabled(True) colors.set_widget_color(self.reject_button, qt_import.Qt.red) else: self.reject_button.setEnabled(False)
def centring_successful(self, method, centring_status): self.centre_button.command_done() self.accept_button.setEnabled(True) self.reject_button.setEnabled(True) if self.inside_data_collection: colors.set_widget_color(self.accept_button, colors.LIGHT_GREEN) colors.set_widget_color(self.reject_button, colors.LIGHT_RED) self.setEnabled(True)
def input_field_changed(self, input_field_text): if input_field_text == "": colors.set_widget_color(self.new_value_ledit, colors.LINE_EDIT_ACTIVE, qt_import.QPalette.Base) else: colors.set_widget_color(self.new_value_ledit, colors.LINE_EDIT_CHANGED, qt_import.QPalette.Base)
def input_field_changed(self, input_field_text): if (self.new_value_validator.validate( input_field_text, 0)[0] == qt_import.QValidator.Acceptable): colors.set_widget_color(self.new_value_ledit, colors.LINE_EDIT_CHANGED, qt_import.QPalette.Base) else: colors.set_widget_color(self.new_value_ledit, colors.LINE_EDIT_ERROR, qt_import.QPalette.Base)
def __init__(self, *args): BaseWidget.__init__(self, *args) # Properties ---------------------------------------------------------- self.add_property("title", "string", "Shutter") self.add_property("hwobj_shutter", "string", "") # Signals ------------------------------------------------------------- # Slots --------------------------------------------------------------- # Hardware objects ---------------------------------------------------- self.shutter_hwobj = None # Internal values ----------------------------------------------------- # Graphic elements ---------------------------------------------------- self.main_groupbox = qt_import.QGroupBox("Shutter", self) self.main_groupbox.setAlignment(qt_import.Qt.AlignCenter) self.state_label = qt_import.QLabel("<b>unknown</b>", self.main_groupbox) self.state_label.setAlignment(qt_import.Qt.AlignCenter) self.state_label.setFixedHeight(24) colors.set_widget_color(self.state_label, colors.LIGHT_GRAY) _button_widget = qt_import.QWidget(self.main_groupbox) self.open_button = qt_import.QPushButton( icons.load_icon("ShutterOpen"), "Open", _button_widget) self.close_button = qt_import.QPushButton( icons.load_icon("ShutterClose"), "Close", _button_widget) # Layout -------------------------------------------------------------- _button_widget_hlayout = qt_import.QHBoxLayout(_button_widget) _button_widget_hlayout.addWidget(self.open_button) _button_widget_hlayout.addWidget(self.close_button) _button_widget_hlayout.setSpacing(2) _button_widget_hlayout.setContentsMargins(0, 0, 0, 0) _main_gbox_vlayout = qt_import.QVBoxLayout(self.main_groupbox) _main_gbox_vlayout.addWidget(self.state_label) _main_gbox_vlayout.addWidget(_button_widget) _main_gbox_vlayout.setSpacing(2) _main_gbox_vlayout.setContentsMargins(2, 2, 2, 2) _main_vlayout = qt_import.QVBoxLayout(self) _main_vlayout.addWidget(self.main_groupbox) _main_vlayout.setSpacing(0) _main_vlayout.setContentsMargins(0, 0, 0, 0) # SizePolicies -------------------------------------------------------- # Qt signal/slot connections ------------------------------------------ self.open_button.clicked.connect(self.open_button_clicked) self.close_button.clicked.connect(self.close_button_clicked)
def stateChanged(self, state, state_label=""): self.setEnabled(True) state = str(state) try: color = self.STATES[state][0] except KeyError: state = "unknown" color = self.STATES[state][0] if color is None: color = colors.GROUP_BOX_GRAY colors.set_widget_color(self.state_ledit, color, qt_import.QPalette.Base) # self.state_ledit.setPaletteBackgroundColor(QColor(color)) if len(state_label) > 0: self.state_ledit.setText("%s" % state_label) else: label_str = state if state == "in": prop_label = self["in"].strip() if len(prop_label.strip()): label_str = prop_label if state == "out": prop_label = self["out"].strip() if prop_label: label_str = prop_label self.state_ledit.setText("%s" % label_str) if state in self.STATES: in_enable = self.STATES[state][1] out_enable = self.STATES[state][2] else: in_enable = False out_enable = False self.set_in_button.setEnabled(in_enable) self.set_out_button.setEnabled(out_enable) if state in self.STATES: in_state = self.STATES[state][3] out_state = self.STATES[state][4] else: in_state = True out_state = False if in_state is not None: self.set_in_button.blockSignals(True) self.set_in_button.setChecked(in_state) self.set_in_button.blockSignals(False) if out_state is not None: self.set_out_button.blockSignals(True) self.set_out_button.setChecked(out_state) self.set_out_button.blockSignals(False) """
def temperature_changed(self, value, status_ok): if value is not None: unit = u"\N{DEGREE SIGN}" self.temperature_label.setText(" Temperature : %0.1f%s" % (value, unit)) if status_ok: colors.set_widget_color( self.temperature_label, STATES["OK"] ) else: colors.set_widget_color( self.temperature_label, STATES["BAD"] )
def _run_number_ledit_change(self, new_value): if str(new_value).isdigit(): self._data_model.run_number = int(new_value) self.data_path_layout.run_number_ledit.setText(str(new_value)) self.update_file_name() self.pathTemplateChangedSignal.emit() else: # self.data_path_layout.run_number_ledit.setText(str(self._data_model.run_number)) colors.set_widget_color( self.data_path_layout.folder_ledit, colors.LIGHT_YELLOW )
def set_editing(self, editing): self.editing = editing if self.editing: colors.set_widget_color( self.position_spinbox.lineEdit(), qt_import.QColor(255, 165, 0), qt_import.QPalette.Base, ) else: # restore last position from motor self.position_changed(self.motor_hwobj.get_value())
def humidity_changed(self, value, status_ok): if value is not None: self.humidity_label.setText( " Humidity : %0.1f%s" % (value, chr(37)) ) if status_ok: colors.set_widget_color( self.humidity_label, STATES["OK"] ) else: colors.set_widget_color( self.humidity_label, STATES["BAD"] )
def gap_status_changed(self, status): if status[0] == "Move": # Moving self.stop_hor_button.setEnabled(True) colors.set_widget_color( self.hor_pos_dspinbox.lineEdit(), colors.LIGHT_YELLOW, qt_import.QPalette.Base, ) else: self.stop_hor_button.setEnabled(False) colors.set_widget_color( self.hor_pos_dspinbox.lineEdit(), colors.LIGHT_GREEN, qt_import.QPalette.Base, ) if status[1] == "Move": # Moving self.stop_ver_button.setEnabled(True) colors.set_widget_color( self.ver_pos_dspinbox.lineEdit(), colors.LIGHT_YELLOW, qt_import.QPalette.Base, ) else: self.stop_ver_button.setEnabled(False) colors.set_widget_color( self.ver_pos_dspinbox.lineEdit(), colors.LIGHT_GREEN, qt_import.QPalette.Base, )
def motor_state_changed(self, state): self.positions_combo.setEnabled(self.motor_hwobj.is_ready()) if self.motor_hwobj.is_ready: colors.set_widget_color( self.positions_combo, colors.LIGHT_GREEN, qt_import.QPalette.Button, ) else: colors.set_widget_color( self.positions_combo, colors.LIGHT_GRAY, qt_import.QPalette.Button, )
def current_value_changed(self): input_field_text = self.new_value_ledit.text() if (self.new_value_validator.validate( input_field_text, 0)[0] == qt_import.QValidator.Acceptable): unit = self.units_combobox.currentText() self.new_value_ledit.setText("") if unit == chr(197): self.set_resolution(float(input_field_text)) elif unit == "mm": self.set_detector_distance(float(input_field_text)) colors.set_widget_color(self.new_value_ledit, colors.LINE_EDIT_ACTIVE, qt_import.QPalette.Base)
def metadata_value_changed(self, value): validator = self.sender().validator() if validator: if validator.validate(value, 0)[0] == qt_import.QValidator.Acceptable: HWR.beamline.ssx_setup.set_metadata_item( self.sender().objectName(), value) colors.set_widget_color(self.sender(), colors.WHITE, qt_import.QPalette.Base) else: colors.set_widget_color(self.sender(), colors.LINE_EDIT_ERROR, qt_import.QPalette.Base) else: HWR.beamline.ssx_setup.set_metadata_item( self.sender().objectName(), value)
def sample_changer_status_changed(self, status): self.status_ledit.setText(status) if status == "Loading": self.camera_live_cbx.setEnabled(False) colors.set_widget_color(self.status_ledit, colors.LIGHT_GREEN, qt_import.QPalette.Base) self.axis_camera.set_video_live(True) self.sc_camera.set_video_live(True) else: self.camera_live_cbx.setEnabled(True) colors.set_widget_color(self.status_ledit, colors.WHITE, qt_import.QPalette.Base) if not self.camera_live_cbx.isChecked(): self.axis_camera.set_video_live(False) self.sc_camera.set_video_live(False)
def input_field_changed(self, input_field_text): """UI update function triggered by field value changes""" if self.update_function is not None: self.update_function(self.parent()) if ( self.validator.validate(input_field_text, 0)[0] == qt_import.QValidator.Acceptable ): colors.set_widget_color( self, colors.LINE_EDIT_CHANGED, qt_import.QPalette.Base ) else: colors.set_widget_color( self, colors.LINE_EDIT_ERROR, qt_import.QPalette.Base )
def current_value_changed(self): input_field_text = self.new_value_ledit.text() if (self.new_value_validator.validate( input_field_text, 0)[0] == qt_import.QValidator.Acceptable): if self.units_combobox.currentIndex() == 0: BaseWidget.set_status_info("status", "Setting energy...", "running") HWR.beamline.energy.set_value(float(input_field_text)) else: HWR.beamline.energy.set_wavelength(float(input_field_text)) self.new_value_ledit.setText("") colors.set_widget_color(self.new_value_ledit, colors.LINE_EDIT_ACTIVE, qt_import.QPalette.Base)