def _setup_ui(self): hbox = QtGui.QHBoxLayout(self) self.setLayout(hbox) form_vbox = self.vbox = QtGui.QVBoxLayout(self) hbox2 = QtGui.QVBoxLayout(self) self.device_and_state = DevnameAndState(self) hbox2.addWidget(self.device_and_state) self.magnet_type_label = QtGui.QLabel("Magnet type:") hbox2.addWidget(self.magnet_type_label) form_vbox.addLayout(hbox2) # attributes self.form = MAXForm(withButtons=False) form_vbox.addWidget(self.form, stretch=1) self.status_area = StatusArea(self) form_vbox.addWidget(self.status_area) hbox.addLayout(form_vbox) # value bar self.valuebar = MAXValueBar(self) slider_vbox = QtGui.QVBoxLayout(self) slider_vbox.setContentsMargins(10, 10, 10, 10) hbox.addLayout(slider_vbox) self.current_label = TaurusLabel() self.current_label.setAlignment(QtCore.Qt.AlignCenter) slider_vbox.addWidget(self.valuebar, 1) slider_vbox.addWidget(self.current_label)
def _setup_ui(self): vbox = QtGui.QVBoxLayout(self) self.setLayout(vbox) grid = QtGui.QGridLayout() self.form = MAXForm(withButtons=False) grid.addWidget(self.form, 0, 0, 2, 1) # rescale taurus form methode self.form.scrollArea.sizeHint = self.scaleSize self.status_label = StatusArea() grid.addWidget(self.status_label, 0, 1, 1, 1) commandbox = QtGui.QVBoxLayout(self) self.start_button = TaurusCommandButton(command="StartCycle") self.start_button.setUseParentModel(True) self.stop_button = TaurusCommandButton(command="StopCycle") self.stop_button.setUseParentModel(True) commandbox.addWidget(self.start_button) commandbox.addWidget(self.stop_button) grid.addLayout(commandbox, 1, 1, 1, 1) vbox.addLayout(grid) self.trend = TaurusTrend() vbox.addWidget(self.trend, stretch=1) self.trend_trigger.connect(self.set_trend_paused) self.cyclingState = None
def _setup_ui(self): hbox = QtGui.QHBoxLayout(self) self.setLayout(hbox) form_vbox = QtGui.QVBoxLayout(self) # devicename label hbox2 = QtGui.QVBoxLayout(self) self.device_and_state = DevnameAndState(self) hbox2.addWidget(self.device_and_state, stretch=2) # commands commandbox = QtGui.QHBoxLayout(self) self.start_button = TaurusCommandButton(command="Start") self.start_button.setUseParentModel(True) self.stop_button = TaurusCommandButton(command="Stop") self.stop_button.setUseParentModel(True) self.init_button = TaurusCommandButton(command="Init") self.init_button.setUseParentModel(True) self.on_button = TaurusCommandButton(command="On") self.on_button.setUseParentModel(True) self.off_button = TaurusCommandButton(command="Off") self.off_button.setUseParentModel(True) self.enable_trigger_button = TaurusCommandButton(command="EnableTrigger") self.enable_trigger_button.setUseParentModel(True) self.disable_trigger_button = TaurusCommandButton(command="DisableTrigger") self.disable_trigger_button.setUseParentModel(True) self.reset_button = TaurusCommandButton(command="Reset") self.reset_button.setUseParentModel(True) commandbox.addWidget(self.start_button) commandbox.addWidget(self.stop_button) commandbox.addWidget(self.init_button) commandbox.addWidget(self.on_button) commandbox.addWidget(self.off_button) commandbox.addWidget(self.enable_trigger_button) commandbox.addWidget(self.disable_trigger_button) commandbox.addWidget(self.reset_button) hbox2.addLayout(commandbox, stretch=1) form_vbox.addLayout(hbox2) # attributes self.form = MAXForm(withButtons=False) form_vbox.addLayout(commandbox) form_vbox.addWidget(self.form, stretch=1) self.status_area = StatusArea() form_vbox.addWidget(self.status_area) hbox.addLayout(form_vbox) # value bar self.valuebar = MAXValueBar(self) slider_vbox = QtGui.QVBoxLayout(self) slider_vbox.setContentsMargins(10, 10, 10, 10) hbox.addLayout(slider_vbox) self.current_label = TaurusLabel() self.current_label.setAlignment(QtCore.Qt.AlignCenter) slider_vbox.addWidget(self.valuebar, 1) slider_vbox.addWidget(self.current_label)
def _setup_ui(self): vbox = QtGui.QVBoxLayout(self) self.setLayout(vbox) label = QtGui.QLabel("All magnets in the circuit") label.setAlignment(QtCore.Qt.AlignCenter) vbox.addWidget(label) self.table = DeviceRowsTable() vbox.addWidget(self.table)
def _setup_ui(self): hbox = QtGui.QHBoxLayout(self) self.setLayout(hbox) self.button = QtGui.QPushButton() # self.button.setText() self.button.setCheckable(True) hbox.addWidget(self.button) self.button.clicked.connect(self.onClick) self.state_trigger.connect(self.change_state)
def _setup_ui(self): hbox = QtGui.QHBoxLayout(self) self.setLayout(hbox) self.table = QtGui.QTableWidget(parent=self) hbox.addWidget(self.table) self.trigger.connect(self.update_item) self.table.itemClicked.connect(self.on_item_clicked) self._items = {} self.attributes = {}
def _setup_ui(self): hbox = QtGui.QHBoxLayout(self) self.setLayout(hbox) self.table = QtGui.QTableWidget() self.table.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) hbox.addWidget(self.table) self.trigger.connect(self.updateColumn) self.attributes = [] self._columns = [] self._values = {} self._config = {}
def _setup_ui(self): # layout hbox = QtGui.QHBoxLayout(self) self.setLayout(hbox) # tabs tabs = self.tabs = TaurusLazyQTabWidget() hbox.addWidget(tabs) # magnet self.circuit_widget = MagnetCircuitPanel() self.circuit_tab = tabs.addTab(self.circuit_widget, "Circuit") # ps self.ps_widget = PowerSupplyPanel() self.ps_tab = tabs.addTab(self.ps_widget, "Power supply") # magnet self.magnets_widget = MagnetListPanel() self.magnets_tab = tabs.addTab(self.magnets_widget, "Magnets") # field self.field_widget = FieldPanel() self.field_tab = tabs.addTab(self.field_widget, "Field") # switchboard self.switchboard_widget = SwitchBoardPanel() tab = tabs.addTab(self.switchboard_widget, "Switchboard") self.switchboard_tab = tab # make the PS tab default for now... tabs.setCurrentIndex(self.ps_tab) self.resize(700, 400)
def update_item(self, row, column): item = self.table.item(row, column) value, config = item.value, item.config # Set text if (config and config.format_spec != "Not specified") and \ (config.format_spec != "!s"): data_format = "%" + config.format_spec item.setText(data_format % value.rvalue) else: item.setText(str(value.rvalue)) # Set flags and state if item.writable_boolean: item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsUserCheckable) state = QtCore.Qt.Checked if value.wvalue else QtCore.Qt.Unchecked item.setCheckState(state) else: item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) # Set background color if config.type == 5: # DevState if value.rvalue in self.STATE_COLORS: item.setBackgroundColor(QtGui.QColor(*self.STATE_COLORS[value.rvalue]))
def _setup_ui(self): # layout hbox = QtGui.QHBoxLayout(self) self.setLayout(hbox) # tabs tabs = self.tabs = TaurusLazyQTabWidget() hbox.addWidget(tabs) # circuit panel self.circuit_widget = MagnetCircuitPanel() self.circuit_tab = tabs.addTab(self.circuit_widget, "Circuit") # ps panel self.ps_widget = PowerSupplyPanel() self.ps_tab = tabs.addTab(self.ps_widget, "Power supply") # magnet panel self.magnets_widget = MagnetListPanel() self.magnets_tab = tabs.addTab(self.magnets_widget, "Magnets") # cycle panel self.cycle_widget = CyclePanel() self.cycle_tab = tabs.addTab(self.cycle_widget, "Cycle") # field panel self.field_widget = FieldPanel() self.field_tab = tabs.addTab(self.field_widget, "Field") # make the PS tab default for now... tabs.setCurrentIndex(self.ps_tab) self.resize(700, 450)
def _setup_ui(self): hbox = QtGui.QVBoxLayout(self) self.setLayout(hbox) self.status_label = QtGui.QLabel("(No status has been read.)") self.status_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) self.status_label.setWordWrap(True) self.status_label.setAlignment(QtCore.Qt.AlignTop) status_scroll_area = QtGui.QScrollArea() status_scroll_area.setMaximumSize(QtCore.QSize(100000, 100)) status_scroll_area.setWidgetResizable(True) status_scroll_area.setWidget(self.status_label) hbox.addWidget(status_scroll_area) self.status = None self.statusTrigger.connect(self.updateStatus)
def _setup_ui(self): vbox = QtGui.QHBoxLayout(self) self.valuebar = ValueBarWidget() vbox.addWidget(self.valuebar) self.setLayout(vbox) self.value_trigger.connect(self.valuebar.setValue) self.conf_trigger.connect(self.updateConfig) self.setFocusPolicy(QtCore.Qt.WheelFocus)
def _setup_ui(self): vbox = QtGui.QVBoxLayout(self) self.setLayout(vbox) hbox = QtGui.QHBoxLayout(self) label = QtGui.QLabel("Magnetic field components", parent=self) label.setAlignment(QtCore.Qt.AlignCenter) hbox.addWidget(label) # the dropdown to select which magnet's fields to show self.magnet_combobox = QtGui.QComboBox(parent=self) self.magnet_combobox.currentIndexChanged.connect(self._magnet_selected) hbox.addWidget(self.magnet_combobox) vbox.addLayout(hbox) # the actual field table for the chosen magnet self.table = AttributeColumnsTable(parent=self) vbox.addWidget(self.table)
def _setup_ui(self, url, section=None): hbox = QtGui.QHBoxLayout(self) hbox.setContentsMargins(0, 0, 0, 0) hbox.layout().setContentsMargins(0, 0, 0, 0) hbox.addWidget(self._create_view(url, section)) self.setLayout(hbox) self.js.leftclicked.connect(self.on_click) self.js.rightclicked.connect(self.on_rightclick)
def _draw_scale(self, w, h, fh, fw, qp): ticks = self._get_ticks() if all(t is not None for t in ticks): n = len(ticks) - 1 qp.setPen(QtGui.QColor(0, 0, 0)) qp.drawLine(Point(w, self.pad), Point(w, h + self.pad)) for i, tick in enumerate(ticks): qp.drawLine(Point(w, h - i * h / n + self.pad), Point(w + 5, h - i * h / n + self.pad)) qp.drawText( Point(w + self.pad, h - i * h / n + self.pad + fw / 2), TICK_FORMAT % tick)
def updateColumn(self, column): if not self._values: return # when does this happen? data = self._values[column] for row, value in enumerate(data.value): if not isnan(value): cfg = self._config.get(column) if cfg and cfg.format != "Not specified": item = QtGui.QTableWidgetItem(cfg.format % value) else: item = QtGui.QTableWidgetItem(str(value)) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) else: item = QtGui.QTableWidgetItem("NaN") item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) item.setBackgroundColor(QtGui.QColor(220, 220, 220)) item.setTextAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) self.table.setItem(row, column, item)
def hack_circuitpanel(widget, ps_model): """ add trigger buttons from PS to the circuit panel (BinpPowerSupplyPanel case) """ circuit = widget.circuit_widget h_box = QtGui.QHBoxLayout(circuit) circuit.enable_trigger_button = TaurusCommandButton( command="EnableTrigger") circuit.disable_trigger_button = TaurusCommandButton( command="DisableTrigger") circuit.enable_trigger_button.setModel(ps_model) circuit.disable_trigger_button.setModel(ps_model) h_box.addWidget(circuit.enable_trigger_button) h_box.addWidget(circuit.disable_trigger_button) circuit.vbox.insertLayout(1, h_box)
def __init__(self, *args): TaurusWidget.__init__(self, *args) self.setLayout(QtGui.QHBoxLayout()) self.layout().setMargin(0) led = YAGLed(self) led.setUseParentModel(True) led.setModel('/State') led.getFormatedToolTip = self.getFormatedToolTip led.setSizePolicy(Qt.QSizePolicy.Fixed, Qt.QSizePolicy.Fixed) self.layout().addWidget(led) self.layout().addStretch()
def __init__(self, *args): TaurusWidget.__init__(self, *args) self.setLayout(QtGui.QHBoxLayout()) self.layout().setMargin(0) self.layout().setSpacing(0) self.led = TaurusLed(self) self.led.setUseParentModel(True) self.led.setModel('/State') self.led.getFormatedToolTip = self.getFormatedToolTip self.led.setSizePolicy(Qt.QSizePolicy.Fixed, Qt.QSizePolicy.Fixed) self.label = ExpandingLabel() self.label.setUseParentModel(True) self.layout().addWidget(self.led) self.layout().addWidget(self.label)
def __init__(self, *args): TaurusWidget.__init__(self, *args) self.setLayout(QtGui.QHBoxLayout()) self.layout().setMargin(0) self.moveInButton = TaurusCommandButton(self) self.moveInButton.setUseParentModel(True) self.moveInButton.setCommand('MoveIn') self.moveInButton.setCustomText('Move In') self.moveOutButton = TaurusCommandButton(self) self.moveOutButton.setUseParentModel(True) self.moveOutButton.setCommand('MoveOut') self.moveOutButton.setCustomText('Move Out') self.layout().addWidget(self.moveInButton) self.layout().addWidget(self.moveOutButton)
def setModel(self, devices, attributes=[]): if not devices: for dev, attrs in self.attributes.items(): for att in attrs: att and att.removeListener( self._items[dev][att.name].event_received) else: try: # TaurusWidget.setModel(self, attrs[0].rsplit("/", 1)[0]) attrnames = [a[0] if isinstance(a, tuple) else a for a in attributes] self.attributes = dict((dev, [Attribute("%s/%s" % (dev, a)) for a in attrnames]) for dev in devices) self.table.setColumnCount(len(attributes) + 1) colnames = [a[1] if isinstance(a, tuple) else a for a in attributes] labels = ["Device"] + colnames self.table.setHorizontalHeaderLabels(labels) header = self.table.horizontalHeader() header.setResizeMode(QtGui.QHeaderView.Stretch) # Check if there are any columns at all self.table.setRowCount(len(devices)) for r, (dev, attrs) in enumerate(self.attributes.items()): item = QtGui.QTableWidgetItem(dev) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.table.setItem(r, 0, item) for c, att in enumerate(attrs, 1): # JFF: this is a workaround for a behavior in Taurus. Just # adding a new listener to each attribute does not work, the # previous ones get removed for some reason. item = TableItem(self.trigger) self.table.setItem(r, c, item) att.addListener(item.event_received) except PyTango.DevFailed: pass
def _setup_ui(self): grid = QtGui.QGridLayout(self) self.setLayout(grid) grid.addWidget(QtGui.QLabel("Device:"), 0, 0) self.devicename_label = QtGui.QLabel("<devicename>") self.devicename_label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) grid.addWidget(self.devicename_label, 0, 1) grid.addWidget(QtGui.QLabel("State:"), 1, 0) hbox = QtGui.QHBoxLayout(self) # self.state_led = TaurusLed() # hbox.addWidget(self.state_led) self.state_label = TaurusLabel() policy = QtGui.QSizePolicy() self.state_label.setBgRole("state") policy.setHorizontalPolicy(QtGui.QSizePolicy.Expanding) self.state_label.setSizePolicy(policy) hbox.addWidget(self.state_label) # hbox.insertStretch(2, 1) grid.addLayout(hbox, 1, 1, alignment=QtCore.Qt.AlignLeft) grid.setColumnStretch(1, 1)
def draw_widget(self, qp): # TODO: clean up and complete the error handling; e.g. no limits, # non-valid qualities, etc. font = QtGui.QFont('Serif', 7, QtGui.QFont.Light) qp.setFont(font) metrics = qp.fontMetrics() ticks = self._get_ticks() fw = [metrics.width(TICK_FORMAT % s) for s in ticks if s is not None] if not fw: return # no ticks, should draw something anyway..? fw = max(fw) if len(fw) > 0 else 0 fh = metrics.height() size = self.size() w = size.width() - (self.pad + fw) h = size.height() - 2 * self.pad # draw things in the value scale with self._scale(qp): # frame qp.setPen(QtCore.Qt.transparent) qp.setBrush(QtGui.QColor(255, 255, 255)) qp.drawRect( Rect(0, self.min_value, w, self.max_value - self.min_value)) # warning if self.warn_high is not None: qp.setBrush(QtGui.QColor(255, 200, 150)) qp.drawRect( Rect(0, self.warn_high, w, self.max_value - self.warn_high)) if self.warn_low is not None: qp.setBrush(QtGui.QColor(255, 200, 150)) qp.drawRect( Rect(0, self.min_value, w, abs(self.min_value - self.warn_low))) # alarm if self.alarm_high is not None: qp.setBrush(QtGui.QColor(255, 170, 170)) qp.drawRect( Rect(0, self.alarm_high, w, self.max_value - self.alarm_high)) if self.alarm_low is not None: qp.setBrush(QtGui.QColor(255, 170, 170)) qp.drawRect( Rect(0, self.min_value, w, abs(self.min_value - self.alarm_low))) # value bar qp.setPen(QtGui.QColor(0, 200, 0)) qp.setBrush(QtGui.QColor(0, 200, 0)) qp.drawRect(Rect(10, 0, w - 2 * self.pad, self.value)) # write value line qp.setPen(QtGui.QColor(255, 0, 0)) if self.write_value: qp.drawLine(Point(0, self.write_value), Point(w, self.write_value)) # zero line qp.setPen(QtGui.QColor(0, 0, 0)) if self.min_value <= 0 <= self.max_value: qp.drawLine(0, 0, w + 5, 0) self._draw_scale(w, h, fw, fh, qp)
def paintEvent(self, e): qp = QtGui.QPainter() qp.begin(self) self.draw_widget(qp) qp.end()