def __init__(self, model, parent=None): QWidget.__init__(self, parent) uic.loadUi("MotorWidget.ui", self) self.connect(self.configButton, SIGNAL("clicked()"), self.openConfig) self.connect(self.goButton, SIGNAL("clicked()"), self.go) self.connect(self.moveNegButton, SIGNAL("clicked()"), self.moveNeg) self.connect(self.movePosButton, SIGNAL("clicked()"), self.movePos) self.connect(self.disableButton, SIGNAL("toggled(bool)"), self.disable) self.stateLabel.setModel("%s/state" % model) self.positionLCD.setModel("%s/position" % model) self.motor = DeviceProxy(str(model)) try: self.nameLabel.setText(self.motor.alias()) except Exception: match = re.search(r"((?:[^/]+/){2}[^/]+)$", model) if not match: self.nameLabel.setText(model) else: self.nameLabel.setText(match.group(1)) pos = AttributeProxy("%s/position" % model) try: self.unitLabel.setText(pos.get_config().unit) except Exception: self.unitLabel.setText("") self.absMotionEdit.setText(str(self.motor.position))
def loadUi(obj, filename=None, path=None, with_ui=None): """ Loads a QtDesigner .ui file into the given widget. If no filename is given, it tries to load from a file name which is the widget class name plus the extension ".ui" (example: if your widget class is called MyWidget it tries to find a MyWidget.ui). If path is not given it uses the directory where the python file which defines the widget is located plus a *ui* directory (example: if your widget is defined in a file /home/homer/workspace/taurusgui/my_widget.py then it uses the path /home/homer/workspace/taurusgui/ui) :param filename: the QtDesigner .ui file name [default: None, meaning calculate file name with the algorithm explained before] :type filename: str :param path: directory where the QtDesigner .ui file is located [default: None, meaning calculate path with algorithm explained before] :type path: str :param with_ui: if True, the objects defined in the ui file will be accessible as submembers of an ui member of the widget. If False, such objects will directly be members of the widget. :type with_ui: bool """ if path is None: obj_file = sys.modules[obj.__module__].__file__ path = os.path.join(os.path.dirname(obj_file), 'ui') if filename is None: filename = obj.__class__.__name__ + os.path.extsep + 'ui' full_name = os.path.join(path, filename) if with_ui is not None: ui_obj = __UI() setattr(obj, with_ui, ui_obj) previous_members = set(dir(obj)) uic.loadUi(full_name, baseinstance=obj) post_members = set(dir(obj)) new_members = post_members.difference(previous_members) for member_name in new_members: member = getattr(obj, member_name) setattr(ui_obj, member_name, member) delattr(obj, member_name) else: uic.loadUi(full_name, baseinstance=obj)
def init(self): l = Qt.QVBoxLayout() self.setLayout(l) panel = self._mainPanel = Qt.QWidget() l.addWidget(panel, 1) this_dir = os.path.dirname(os.path.abspath(__file__)) ui_filename = os.path.join(this_dir, 'ui', 'TaurusFilterPanel.ui') self.ui = ui = loadUi(ui_filename, baseinstance=panel) comboBox = ui.filterTypeCombo comboBox.addItem(getElementTypeIcon(ElemType.Attribute), "Attribute", ElemType.Attribute) comboBox.addItem(getElementTypeIcon(ElemType.Device), "Device", ElemType.Device) comboBox.addItem(getElementTypeIcon(ElemType.DeviceClass), "Device type", ElemType.DeviceClass) comboBox.addItem(getElementTypeIcon(ElemType.Server), "Server", ElemType.Server) clickedSig = Qt.SIGNAL("clicked()") idxChangedSig = Qt.SIGNAL("currentIndexChanged(int)") ui.serverNameCombo.currentIndexChanged.connect( self._updateServerInstanceCombo) ui.deviceDomainCombo.currentIndexChanged.connect( self._updateDeviceFamilyCombo) ui.deviceFamilyCombo.currentIndexChanged.connect( self._updateDeviceMemberCombo) class clearSelection(object): def __init__(self, cb): self._cb = cb def __call__(self): self._cb.setCurrentIndex(-1) clear_icon = Qt.QIcon.fromTheme("edit-clear") for combo, clearButton in zip(self.combos(), self.clearButtons()): combo.currentIndexChanged.connect(self._updateStatusBar) clearButton.clicked.connect(clearSelection(combo)) clearButton.setIcon(clear_icon) sb = self._statusbar = Qt.QStatusBar() sb.setSizeGripEnabled(False) l.addWidget(sb) sbWarningMsg = self._sbWarningMsg = _MessageWidget() sbWarningMsg.setVisible(False) sb.addWidget(sbWarningMsg)
def load_scan_info_form(widget): ui_name = pkg_resources.resource_filename(__package__ + '.ui', 'ScanInfoForm.ui') uic.loadUi(ui_name, baseinstance=widget) return widget
def load_scan_window(widget): ui_name = pkg_resources.resource_filename(__package__ + '.ui', 'ScanWindow.ui') uic.loadUi(ui_name, baseinstance=widget) return widget