def ExtractEntries(self, payload_struct): ''' This method generates a list of all the payload entries throughout the payload structure. This list is used to update the display with all of the payload entries Inputs: payload_struct - The payload structure output from GS_Controller.GetPayloadStructure ''' if isinstance(payload_struct, dict): for item in list(payload_struct.keys()): self.ExtractEntries(payload_struct[item]) elif isinstance(payload_struct, list): for item in payload_struct: self.ExtractEntries(item) elif isinstance(payload_struct, tuple): label = QLabel("{:<30} {}".format(payload_struct[0], payload_struct[1])) if payload_struct[2] == 'entry': payloadinput = QLineEdit() elif payload_struct[2] == 'enum': payloadinput = QComboBox() for enum_label in list(payload_struct[3].keys()): payloadinput.addItem(enum_label) else: ErrorMessage("Error", "Something went wrong in the ExtractEntries function") return self.payload_entries.append((payload_struct[0], payload_struct[1], label, payloadinput)) else: ErrorMessage("Error", "Something went wrong in the ExtractEntries function")
def addLabel(self, grid): count = grid.count() rowStart = int(count / 4) rowEnd = rowStart + 3 positions = [(i, j) for i in range(rowStart, rowEnd) for j in range(4)] names = [ 'Label', '/', '/', '/', 'Type', '//', 'Element number', '', 'Name', '', '/', '/' ] for position, name in zip(positions, names): if name == '': widget = QLineEdit() elif name == '/': widget = QLabel() elif name == '//': widget = QComboBox() widget.addItem('Phase') widget.addItem('Pole') else: widget = QLabel(name) grid.addWidget(widget, *position)
class ConnectionWidget(QWidget): """Class defining a widget containing the fields necessary to connection config.""" connectParameters = pyqtSignal(tuple) def __init__(self, location): """Constructor.""" QWidget.__init__(self) self.ip = "" self.__initUI(location) def __initUI(self, location): """Method used to build the UI of the widget.""" frame = QFrame(self) frame.setFrameShape(QFrame.StyledPanel) frame.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) main_layout = QFormLayout() ip_label = QLabel("Adresse IP :") if location is Locations.RESERVE: self.ip_cb = QComboBox(self) self.ip_cb.activated[str].connect(self.__change_ip) else: self.ip_cb = QLineEdit() self.ip_cb.textChanged.connect(self.__change_ip) main_layout.addRow(ip_label, self.ip_cb) port_label = QLabel("Port de connexion :") self.port_le = QLineEdit() main_layout.addRow(port_label, self.port_le) button = QPushButton("Connexion") button.clicked.connect(lambda: self.connectParameters.emit((self.ip, int(self.port_le.text())))) main_layout.addRow(button) frame.setLayout(main_layout) layout = QHBoxLayout() layout.addWidget(frame) self.setLayout(layout) def __change_ip(self, ip): """Method called when changing the combo box value.""" self.ip = ip def set_ips(self, ips_list): """Method used to populate the combobox with ips.""" if len(ips_list) > 0: self.ip = ips_list[0] for ip in ips_list: self.ip_cb.addItem(ip)
def initUI(self): # define hbox hbox = QHBoxLayout() # Label widget label = QLabel(str(self.data['label']) + ':') label.setFont(boldFont) label.setToolTip(self.data['desc']) hbox.addWidget(label) # Value widget if self.data['type'] == 'float': self.modifiedSig = FloatSig() widget = QLineEdit(self) widget.textChanged[str].connect(self.onchange) widget.setText(str(self.data['value'])) # Value widget if self.data['type'] == 'str': self.modifiedSig = StrSig() widget = QLineEdit(self) widget.textChanged[str].connect(self.onchange) widget.setText(str(self.data['value'])) elif self.data['type'] == 'int': self.modifiedSig = IntSig() widget = QSpinBox(self) widget.valueChanged[int].connect(self.onchange) widget.setValue(self.data['value']) elif self.data['type'] == 'sel': self.modifiedSig = StrSig() widget = QComboBox(self) for i, par in enumerate(self.data['choices']): widget.addItem(par) if par == self.data['value']: widget.setCurrentIndex(i) widget.activated[str].connect(self.onchange) elif self.data['type'] == 'bool': self.modifiedSig = BoolSig() widget = QComboBox(self) for i, par in enumerate([str(False), str(True)]): widget.addItem(par) if par == str(self.data['value']): widget.setCurrentIndex(i) widget.activated[str].connect(self.onchange) self.valueWidget = widget hbox.addWidget(self.valueWidget) # set layout and show self.setLayout(hbox)
def __init__(self, settings, parent=None): """Initialize the dialog. :param version: application version string. """ super().__init__(parent) self.logger = self.parent().logger self.settings = settings self.setWindowTitle("Settings") self.setFixedSize(600, 400) self.layout = QVBoxLayout() # Text boxes for setting values self.val_boxes = dict() self.l0 = QGridLayout() for row, setting in enumerate(self._mutable_settings): key = setting['key'] value = self.settings[key] lab = QLabel(key) wid = None if setting['type'] is str: wid = QLineEdit(text=value) if key == 'registry': wid.setEnabled(False) elif setting['type'] is bool: wid = QCheckBox() wid.setChecked(value) elif issubclass(setting['type'], Enum): wid = QComboBox() for flavour in setting['type']: wid.addItem(flavour.name, flavour.value) wid.setCurrentText(value.name) else: raise TypeError("Unhandled type in settings dialog.") wid.setToolTip(setting['desc']) self.val_boxes[key] = wid self.l0.addWidget(lab, row, 0) self.l0.addWidget(wid, row, 1) self.layout.addLayout(self.l0) # OK / Cancel self.l1 = QHBoxLayout() self.layout.insertStretch(-1) self.set_btn = QPushButton("OK") self.set_btn.clicked.connect(self.store_settings) self.l1.addWidget(self.set_btn) self.set_btn = QPushButton("Defaults") self.set_btn.clicked.connect(self.set_defaults) self.l1.addWidget(self.set_btn) self.cancel_btn = QPushButton("Cancel") self.cancel_btn.clicked.connect(self.close) self.l1.addWidget(self.cancel_btn) self.layout.addLayout(self.l1) self.setLayout(self.layout)
def add_items(self): row1, row2 = 0, 0 for count, item in enumerate(self.items): param_name, param_type = item param_name = param_name.decode() param_help = self.config.get_parameter_help(param_name).decode() param_desc = re.split(':|\(|--', param_help)[0].strip() if len(param_desc) > 35 or len(param_name) > len(param_desc): param_desc = param_name param_help = '[' + param_name + '] ' + param_help opts = format_options(param_help) if param_type == M64TYPE_STRING: row1 += 1 widget = QLineEdit() widget.setToolTip(param_help) self.gridLayout.addWidget(QLabel(format_label(param_desc)), row1, 1, Qt.AlignRight) self.gridLayout.addWidget(widget, row1, 2, Qt.AlignLeft) self.widgets[param_name] = (widget, widget.__class__, opts) elif param_type == M64TYPE_INT: row1 += 1 if not opts: widget = QSpinBox() widget.setMaximum(32767) widget.setMinimum(-32767) if param_help: widget.setToolTip(param_help) else: widget = QComboBox() widget.setToolTip(param_help) widget.setMinimumContentsLength(14) widget.setSizeAdjustPolicy( QComboBox.AdjustToMinimumContentsLength) for idx, key in enumerate(sorted(opts.keys())): value = opts[key] opts[key] = (idx, value) data = (idx, key, value) widget.addItem(value) widget.setItemData(idx, data) self.gridLayout.addWidget(QLabel(format_label(param_desc)), row1, 1, Qt.AlignRight) self.gridLayout.addWidget(widget, row1, 2, Qt.AlignLeft) self.widgets[param_name] = (widget, widget.__class__, opts) elif param_type == M64TYPE_BOOL: row2 += 1 widget = QCheckBox() widget.setText(format_label(param_desc)) if param_help: widget.setToolTip(param_help) self.gridLayout.addWidget(widget, row2, 3) self.widgets[param_name] = (widget, widget.__class__, opts)
def add_items(self): row1, row2 = 0, 0 for count, item in enumerate(self.items): param_name, param_type = item param_name = param_name.decode() param_help = self.config.get_parameter_help(param_name).decode() param_desc = re.split(':|\(|--', param_help)[0].strip() if len(param_desc) > 35 or len(param_name) > len(param_desc): param_desc = param_name param_help = '[' + param_name + '] ' + param_help opts = format_options(param_help) if param_type == M64TYPE_STRING: row1 += 1 widget = QLineEdit() widget.setToolTip(param_help) self.gridLayout.addWidget( QLabel(format_label(param_desc)), row1, 1, Qt.AlignRight) self.gridLayout.addWidget(widget, row1, 2, Qt.AlignLeft) self.widgets[param_name] = (widget, widget.__class__, opts) elif param_type == M64TYPE_INT: row1 += 1 if not opts: widget = QSpinBox() widget.setMaximum(32767) widget.setMinimum(-32767) if param_help: widget.setToolTip(param_help) else: widget = QComboBox() widget.setToolTip(param_help) widget.setMinimumContentsLength(14) widget.setSizeAdjustPolicy(QComboBox.AdjustToMinimumContentsLength) for idx, key in enumerate(sorted(opts.keys())): value = opts[key] opts[key] = (idx, value) data = (idx, key, value) widget.addItem(value) widget.setItemData(idx, data) self.gridLayout.addWidget( QLabel(format_label(param_desc)), row1, 1, Qt.AlignRight) self.gridLayout.addWidget(widget, row1, 2, Qt.AlignLeft) self.widgets[param_name] = (widget, widget.__class__, opts) elif param_type == M64TYPE_BOOL: row2 += 1 widget = QCheckBox() widget.setText(format_label(param_desc)) if param_help: widget.setToolTip(param_help) self.gridLayout.addWidget(widget, row2, 3) self.widgets[param_name] = (widget, widget.__class__, opts)
def createEditor(self, parent, option, index): if index.column() != self.languageColumn: editor = QLineEdit(parent) else: editor = QComboBox(parent) editor.addItem("") for i in range(2, 356): if QLocale(i, QLocale.AnyScript, QLocale.AnyCountry) is not None: languagecode = QLocale(i, QLocale.AnyScript, QLocale.AnyCountry).name().split("_")[0] if languagecode != "C": editor.addItem(languagecode) editor.model().sort(0) if index.column() == self.completerColumn: editor.setCompleter(QCompleter(self.completerStrings)) editor.completer().setCaseSensitivity(False) return editor
def createEditor(self, widget, option, index): if not index.isValid(): return None if index.column() == 0: editor = QLineEdit(widget) editor.setValidator(QRegExpValidator(QRegExp('.+'), self)) editor.setText(index.model().data(index, Qt.EditRole)) return editor if index.column() == 1: editor = QLineEdit(widget) editor.setValidator(QIntValidator(0, 99, self)) editor.setText(str(index.model().data(index, Qt.EditRole))) return editor if index.column() == 2: editor = QComboBox(parent=widget) editor.addItem("MD5") editor.addItem("SHA") editor.setCurrentIndex(editor.findText(index.model().data(index, Qt.EditRole))) return editor return super(SettingsItemDelegate, self).createEditor(widget, option, index)
class VariableLink(QObject): """Bridge between the pyrogue tree and the display element""" updateGui = pyqtSignal([int], [str]) def __init__(self, *, tree, parent, variable): QObject.__init__(self) self._variable = variable self._lock = threading.Lock() self._parent = parent self._tree = tree self._inEdit = False self._swSet = False self._widget = None self._item = QTreeWidgetItem(parent) self._item.setText(0, variable.name) self._item.setText(1, variable.mode) self._item.setText(2, variable.typeStr) self._alarm = QLineEdit() self._alarm.setReadOnly(True) #self._alarm.setText('None') if variable.hasAlarm: self._tree.setItemWidget(self._item, 5, self._alarm) if variable.units: self._item.setText(4, str(variable.units)) if self._variable.disp == 'enum' and self._variable.enum is not None and self._variable.mode != 'RO': self._widget = QComboBox() self._widget.activated.connect(self.cbChanged) self.updateGui.connect(self._widget.setCurrentIndex) for i in self._variable.enum: self._widget.addItem(self._variable.enum[i]) self._widget.installEventFilter(self) elif self._variable.minimum is not None and \ self._variable.maximum is not None and \ self._variable.disp == '{}' and \ self._variable.mode != 'RO': self._widget = QSpinBox() self._widget.setMinimum(self._variable.minimum) self._widget.setMaximum(self._variable.maximum) self._widget.valueChanged.connect(self.sbChanged) self.updateGui.connect(self._widget.setValue) self._widget.installEventFilter(self) else: self._widget = QLineEdit() self._widget.returnPressed.connect(self.returnPressed) self._widget.textEdited.connect(self.valueChanged) self.updateGui[str].connect(self._widget.setText) self._widget.setToolTip(self._variable.description) self._widget.setContextMenuPolicy(Qt.CustomContextMenu) self._widget.customContextMenuRequested.connect(self.openMenu) if self._variable.mode == 'RO': self._widget.setReadOnly(True) self._tree.setItemWidget(self._item, 3, self._widget) self.varListener(None, self._variable.getVariableValue(read=False)) variable.addListener(self.varListener) def openMenu(self, event): menu = QMenu() read_variable = None write_variable = None var_info = menu.addAction('Variable Information') read_recurse = menu.addAction('Read Recursive') write_recurse = menu.addAction('Write Recursive') read_device = menu.addAction('Read Device') write_device = menu.addAction('Write Device') if self._variable.mode != 'WO': read_variable = menu.addAction('Read Variable') if self._variable.mode != 'RO': write_variable = menu.addAction('Write Variable') action = menu.exec_(self._widget.mapToGlobal(event)) try: if action == var_info: self.infoDialog() elif action == read_recurse: self._variable.parent.ReadDevice(True) elif action == write_recurse: self._variable.parent.WriteDevice(True) elif action == read_device: self._variable.parent.ReadDevice(False) elif action == write_device: self._variable.parent.WriteDevice(False) elif action == read_variable: self._variable.get() elif action == write_variable: if isinstance(self._widget, QComboBox): self._variable.setDisp(self._widget.currentText()) elif isinstance(self._widget, QSpinBox): self._variable.set(self._widget.value()) else: self._variable.setDisp(self._widget.text()) except Exception as msg: print(f"Got Exception: {msg}") def infoDialog(self): attrs = [ 'name', 'path', 'description', 'hidden', 'groups', 'enum', 'typeStr', 'disp', 'precision', 'mode', 'units', 'minimum', 'maximum', 'lowWarning', 'lowAlarm', 'highWarning', 'highAlarm', 'alarmStatus', 'alarmSeverity', 'pollInterval' ] if self._variable.isinstance(pyrogue.RemoteVariable): attrs += ['offset', 'bitSize', 'bitOffset', 'verify', 'varBytes'] msgBox = QDialog() msgBox.setWindowTitle("Variable Information For {}".format( self._variable.name)) msgBox.setMinimumWidth(400) vb = QVBoxLayout() msgBox.setLayout(vb) fl = QFormLayout() fl.setRowWrapPolicy(QFormLayout.DontWrapRows) fl.setFormAlignment(Qt.AlignHCenter | Qt.AlignTop) fl.setLabelAlignment(Qt.AlignRight) vb.addLayout(fl) pb = QPushButton('Close') pb.pressed.connect(msgBox.close) vb.addWidget(pb) for a in attrs: le = QLineEdit() le.setReadOnly(True) le.setText(str(getattr(self._variable, a))) fl.addRow(a, le) msgBox.exec() def varListener(self, path, varVal): with self._lock: if self._widget is None or self._inEdit is True: return self._swSet = True if isinstance(self._widget, QComboBox): i = self._widget.findText(varVal.valueDisp) if i < 0: i = 0 if self._widget.currentIndex() != i: self.updateGui.emit(i) elif isinstance(self._widget, QSpinBox): if self._widget.value != varVal.value: self.updateGui.emit(varVal.value) else: if self._widget.text() != varVal.valueDisp: self.updateGui[str].emit(varVal.valueDisp) if varVal.severity == 'AlarmMajor': self._alarm.setText('Major') p = QPalette() p.setColor(QPalette.Base, Qt.red) p.setColor(QPalette.Text, Qt.black) self._alarm.setPalette(p) elif varVal.severity == 'AlarmMinor': self._alarm.setText('Minor') p = QPalette() p.setColor(QPalette.Base, Qt.yellow) p.setColor(QPalette.Text, Qt.black) self._alarm.setPalette(p) elif varVal.severity == 'Good': self._alarm.setText('Good') p = QPalette() p.setColor(QPalette.Base, Qt.green) p.setColor(QPalette.Text, Qt.black) self._alarm.setPalette(p) else: self._alarm.setText('') p = QPalette() self._alarm.setPalette(p) self._swSet = False @pyqtSlot() def valueChanged(self): self._inEdit = True p = QPalette() p.setColor(QPalette.Base, Qt.yellow) p.setColor(QPalette.Text, Qt.black) self._widget.setPalette(p) @pyqtSlot() def returnPressed(self): p = QPalette() self._widget.setPalette(p) try: self._variable.setDisp(self._widget.text()) except Exception as msg: print(f"Got Exception: {msg}") self._inEdit = False self.updateGui.emit(self._variable.valueDisp()) @pyqtSlot(int) def sbChanged(self, value): if self._swSet: return self._inEdit = True try: self._variable.setDisp(value) except Exception as msg: print(f"Got Exception: {msg}") self._inEdit = False @pyqtSlot(int) def cbChanged(self, value): if self._swSet: return self._inEdit = True try: self._variable.setDisp(self._widget.itemText(value)) except Exception as msg: print(f"Got Exception: {msg}") self._inEdit = False def eventFilter(self, obj, event): if event.type() == QEvent.Wheel: return True else: return False
class CommandLink(QObject): """Bridge between the pyrogue tree and the display element""" def __init__(self, *, tree, parent, command): QObject.__init__(self) self._command = command self._parent = parent self._tree = tree self._widget = None self._pb = None self._item = QTreeWidgetItem(parent) self._item.setText(0, command.name) self._item.setText(1, command.typeStr) self._pb = QPushButton('Execute') self._tree.setItemWidget(self._item, 2, self._pb) self._pb.clicked.connect(self.execPressed) self._pb.setToolTip(self._command.description) if self._command.arg: if self._command.disp == 'enum' and self._command.enum is not None: self._widget = QComboBox() for i in self._command.enum: self._widget.addItem(self._command.enum[i]) self._widget.setCurrentIndex( self._widget.findText(self._command.valueDisp())) self._widget.installEventFilter(self) elif self._command.minimum is not None and self._command.maximum is not None: self._widget = QSpinBox() self._widget.setMinimum(self._command.minimum) self._widget.setMaximum(self._command.maximum) self._widget.setValue(self._command.value()) self._widget.installEventFilter(self) else: self._widget = QLineEdit() self._widget.setText(self._command.valueDisp()) self._tree.setItemWidget(self._item, 3, self._widget) @pyqtSlot() def execPressed(self): if self._widget is not None: value = str(self._widget.text()) else: value = None try: if self._command.arg: self._command(self._command.parseDisp(value)) else: self._command() except Exception as msg: print(f"Got Exception: {msg}") def eventFilter(self, obj, event): if event.type() == QEvent.Wheel: return True else: return False
def initUI(self): w = QLabel() text = 'Big wall of text below.' w.setText(text) hbox = QHBoxLayout() hbox.addStretch(1) self.buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) self.buttons.setMinimumSize(QtCore.QSize(50, 50)) for b in self.buttons.buttons(): b.setMinimumHeight(50) hbox.addWidget(self.buttons) vbox = QVBoxLayout() h = QHBoxLayout() vbox.addWidget(w) l = [ 'Name', 'X Positon', 'Y Position', 'Width', 'Height', 'Color', 'Behavior', 'Input' ] behavior_list = ['normal', 'sticky', 'autorepeat', 'combo'] for i in range(8): if i == 0: new_vbox = QVBoxLayout() new_widget = QWidget() lbl = QLabel(l[i]) b = QLineEdit() b.setText('Z1') b.setMinimumHeight(50) new_vbox.addWidget(lbl) new_vbox.addWidget(b) new_widget.setLayout(new_vbox) h.addWidget(new_widget) if i > 0 and i <= 4: new_vbox = QVBoxLayout() new_widget = QWidget() lbl = QLabel(l[i]) b = QSpinBox() b.setMinimum(0) b.setMaximum(100) b.setSingleStep(1) b.setValue(50) b.setMinimumHeight(50) new_vbox.addWidget(lbl) new_vbox.addWidget(b) new_widget.setLayout(new_vbox) h.addWidget(new_widget) if i == 5: new_vbox = QVBoxLayout() new_widget = QWidget() lbl = QLabel(l[i]) b = QPushButton() b.setStyleSheet('background-color:green') b.setMinimumHeight(50) new_vbox.addWidget(lbl) new_vbox.addWidget(b) new_widget.setLayout(new_vbox) h.addWidget(new_widget) if i == 6: new_vbox = QVBoxLayout() new_widget = QWidget() lbl = QLabel(l[i]) b = QComboBox() b.setMinimumHeight(50) b.addItem(behavior_list[0]) b.addItem(behavior_list[1]) b.addItem(behavior_list[2]) new_vbox.addWidget(lbl) new_vbox.addWidget(b) new_widget.setLayout(new_vbox) h.addWidget(new_widget) if i == 7: new_vbox = QVBoxLayout() new_widget = QWidget() lbl = QLabel(l[i]) b = QPushButton() b.setText('key D click 2') b.setMinimumHeight(50) new_vbox.addWidget(lbl) new_vbox.addWidget(b) new_widget.setLayout(new_vbox) h.addWidget(new_widget) scroll = QScrollArea() scroll.setWidgetResizable(True) widget = QLabel() widget.setWordWrap(True) t = ( "<font color='blue'>Some fields in default buttons are disabled. " "This has been done on purpose to define a standard set of buttons. " "However, there are no such restrictions on creating a new button. " "If you want to hide an existing button, set its width and height to zero.</font><br><br>" "<b>Name:</b> Identification label for your button. " "You cannot change names of existing buttons. " "However you can always create a new button with any name.<br><br>" "<b>X Position:</b> Defines horizontal position of a button in terms of percentages of 'Overlay Width'. " "E.g., a value of 6 will postion a button horizontally at 6% of total overlay width value. " "Please note that overlay width may not be your screen width. " "You can change overlay width in settings.<br><br>" "<b>Y Position:</b> Defines vertical position of a button in terms of percentages of 'Overlay Height'. " "E.g., a value of 30 will postion a button vertically at 30% of total overlay height value. " "Please note that overlay height may not be your screen height. " "You can change overlay height in settings.<br><br>" "<b>Width:</b> Defines width of the button. " "If 'Override Button Size' is enabled in settings, this value will have no effect on button.<br><br>" "<b>Height:</b> Defines height of the button. " "If 'Override Button Size' is enabled in settings, this value will have no effect on button.<br><br>" "<font color='blue'><u>Tip:</u> To hide a button, set its width and height to zero.</font><br><br>" "<b>Color:</b> Sets the color of the button.<br><br>" "<b>Behavior:</b> Defines behavior of the button.<br>" "<font color='blue'>Some of the options below will only work if your game/emulator supports it.</font><br>" "<u>Normal:</u> Standard tap or long press on a button. " "Duplicate keys like 'Up, Up, Down, Down' will not work in this mode.<br>" "<u>Sticky:</u> Simulates press and hold behavior on a single press (continues unless stopped). " "Duplicate keys like 'Up, Up, Down, Down' will not work in this mode.<br>" "<u>Autorepeat:</u> Also known as rapid-fire/turbo. After touching once, it goes on and on, unless stopped. " "Duplicate keys like 'Up, Up, Down, Down' will not work in this mode.<br>" "<u>Combo:</u> Auto-executes keys one by one in a time interval defined in the settings. " "Once a combo starts, it cannot be interrupted until its done. " "Duplicate keys like 'Up, Up, Down, Down' will work in this mode if the game/emulator supports it.<br><br>" "<font color='blue'><u>Tip:</u> Tap on 'Stop All Inputs' to halt all sticky and autorepeating keys/clicks.</font><br><br>" "<b>Input:</b> Choose one or multiple keys/clicks to be executed on a button press. " "You can even combine keys and clicks together. " "There are more than 150 options, so you can now execute all those 'Soul Calibur' combos in one hit.<br><br>" "<font color='blue'><u>Tip:</u> If you find that the app is crashing at startup," " delete 'settings.conf' file in main app folder and 'DefaultLayout.conf'" " file in profiles folder and then relaunch the app.</font><br><br>" ) widget.setText(t) widget.setContentsMargins(10, 10, 10, 10) widget.setAlignment(QtCore.Qt.AlignJustify) widget.setStyleSheet('background-color:white;') scroll.setWidget(widget) scroll.setObjectName('scroll1') scroll.setStyleSheet('#scroll1 {background-color:white;}') qs = QScroller.scroller(scroll.viewport()) props = qs.scrollerProperties() props.setScrollMetric(QScrollerProperties.DecelerationFactor, 0.35) props.setScrollMetric(QScrollerProperties.DragStartDistance, .001) qs.setScrollerProperties(props) qs.grabGesture(scroll.viewport(), QScroller.TouchGesture) vbox.addSpacing(10) vbox.addLayout(h) vbox.addSpacing(20) vbox.addWidget(scroll) vbox.addLayout(hbox) self.setLayout(vbox) w, h = self.screen_width * .9, self.sizeHint().height() self.setGeometry((self.screen_width - w) / 2, (self.screen_height - h) / 2, w, h) self.setWindowTitle('Help')
class MySetting(QWidget): def __init__(self): super(MySetting,self).__init__() layout = QVBoxLayout() layout.addWidget(self.ruleBox()) layout.addWidget(self.SVCBox()) self.setLayout(layout) self.setWindowTitle('Setting') # 黑白名单的部分 def ruleBox(self): # 组件 rule = QGroupBox('关键字过滤') self.text = QLineEdit() self.blackButton = QPushButton('black') self.whiteButton = QPushButton('white') self.list = QListWidget(self) self.tag =0 self.list.itemDoubleClicked.connect(self.delfunc) self.blackButton.clicked.connect(self.ruleAct) self.whiteButton.clicked.connect(self.ruleAct) # 布局 hlayout = QHBoxLayout() hlayout.addWidget(self.text) hlayout.addWidget(self.blackButton) hlayout.addWidget(self.whiteButton) layout = QVBoxLayout() layout.addLayout(hlayout) layout.addWidget(self.list) rule.setLayout(layout) return rule # 用于设置程序风格等属性,暂时保留 def styleBox(self): pass # 用来控制机器学习,包括学习算法,参数等 # def SVCBox(self): self.SVC = QGroupBox('机器学习') self.layout = QGridLayout() modelLab = QLabel('model:') self.modelCom = QComboBox() self.modelCom.addItem('SVC') self.modelCom.addItem('KNN') self.modelCom.addItem('Decision') modelLab.setBuddy(self.modelCom) self.modelCom.activated.connect(self.SVCfunc) self.param1Lab = QLabel('kernel: ') self.param1Edit = QComboBox() self.param1Edit.addItem('rbf') self.param1Edit.addItem('linear') self.param1Edit.addItem('poly') self.param1Edit.addItem('sigmoid') self.param2Lab = QLabel('gamma: ') self.param2Edit = QLineEdit('auto') self.param3Lab = QLabel('C: ') self.param3Edit = QLineEdit('1') # 以下是测试时的用例 # self.param1Lab= QLabel('param1:') # self.param1Edit = QLineEdit() # # self.param1Lab.setBuddy(self.param1Edit) # # self.param2Lab = QLabel('param2:') # self.param2Edit = QLineEdit() # # self.param2Lab.setBuddy(self.param2Edit) # # self.param3Lab = QLabel('param3:') # self.param3Edit = QLineEdit() # # self.param3Lab.setBuddy(self.param3Edit) saveButton = QPushButton('save') saveButton.clicked.connect(self.saveModel) self.layout.addWidget(modelLab,0,0,1,1) self.layout.addWidget(self.modelCom,0,1,1,2) self.layout.addWidget(self.param1Lab,1,0,1,1) self.layout.addWidget(self.param1Edit,1,1,1,2) self.layout.addWidget(self.param2Lab,2,0,1,1) self.layout.addWidget(self.param2Edit,2,1,1,2) self.layout.addWidget(self.param3Lab,3,0,1,1) self.layout.addWidget(self.param3Edit,3,1,1,2) self.layout.addWidget(saveButton,4,2,1,2) self.SVC.setLayout(self.layout) return self.SVC # 该模块定义了双击列表中的某项后,产生的删除行为 # 如何删除一项呢,删除了之后,原处为空了,另外在结尾增加了空 def delfunc(self): item = self.list.currentRow() self.list.takeItem(item) list = [] j=0 # 删除黑名单中的元素 if self.tag == 0: with open('../data/blackList','r') as f: for i in f: if j==item: pass elif not i == '\n': list.append(i) j += 1 with open('../data/blackList','w') as f: for i in list: f.write(i) # 删除白名单中的元素 if self.tag == 1: with open('../data/whiteList','r') as f: for i in f: if j==item: pass elif not i == '': list.append(i) j += 1 with open('../data/whiteList','w') as f: for i in list: f.write(i) # 结尾可以没有f.flush(),不能为f.write(i+'\n'),它会自己换行 # 为什么在其他地方,却不会换行呢: # 估计是添加到文件时,每个字符都带有一个\n,如果这里再加入,那么就会出现多个换行 # 定义了列表的呈现和添加行为动作 def ruleAct(self): self.list.clear() if self.sender().text() == 'black': self.tag = 0 if not self.text.text() == '': with open('../data/blackList','a') as f: t = self.text.text() + '\n' f.write(t) f.flush() with open('../data/blackList','r') as f: list=[] for i in f: list.append(i) self.list.addItems(list) if self.sender().text() == 'white': self.tag = 1 if not self.text.text() == '': with open('../data/whiteList','a') as f: t = self.text.text()+'\n' f.write(t) f.flush() with open('../data/whiteList','r') as f: list=[] for i in f: list.append(i) self.list.addItems(list) self.text.setText('') # 定义了 def SVCfunc(self): SVCmode = self.modelCom.currentText() # 显示不同的参数列表 # 构造一个布局管理器 # 先移除: # self.layout.removeWidget(self.param1Lab) # self.layout.removeWidget(self.param1Edit) # self.layout.removeWidget(self.param2Lab) # self.layout.removeWidget(self.param2Edit) # self.layout.removeWidget(self.param3Lab) # self.layout.removeWidget(self.param3Edit) # 使用移除时,表现不理想 self.param1Lab.hide() self.param1Edit.hide() self.param2Lab.hide() self.param2Edit.hide() self.param3Lab.hide() self.param3Edit.hide() # 以下显示的参数均为默认参数,即不传参给机器模型 if SVCmode == 'SVC': self.param1Lab= QLabel('kernel: ') self.param1Edit = QComboBox() self.param1Edit.addItem('rbf') self.param1Edit.addItem('linear') self.param1Edit.addItem('poly') self.param1Edit.addItem('sigmoid') self.param2Lab = QLabel('gamma: ') self.param2Edit = QLineEdit('auto') self.param3Lab = QLabel('C: ') self.param3Edit = QLineEdit('1') if SVCmode =='KNN': self.param1Lab= QLabel('weights: ') self.param1Edit = QComboBox() self.param1Edit.addItem('uniform') self.param1Edit.addItem('distance') self.param2Lab = QLabel('neighbors: ') self.param2Edit = QLineEdit('5') self.param3Lab = QLabel('leaf size:') self.param3Edit = QLineEdit('30') self.param3Edit.setReadOnly(True) if SVCmode =='Decision': self.param1Lab= QLabel('depth ') self.param1Edit = QLineEdit('None') self.param2Lab = QLabel('leafs: ') self.param2Edit = QLineEdit('1') self.param3Lab = QLabel('splits: ') self.param3Edit = QLineEdit('2') self.layout.addWidget(self.param1Lab, 1, 0, 1, 1) self.layout.addWidget(self.param1Edit, 1, 1, 1, 2) self.layout.addWidget(self.param2Lab, 2, 0, 1, 1) self.layout.addWidget(self.param2Edit, 2, 1, 1, 2) self.layout.addWidget(self.param3Lab, 3, 0, 1, 1) self.layout.addWidget(self.param3Edit, 3, 1, 1, 2) # # 读取文件 # param1 = self.param1Edit.text() # param2 = self.param2Edit.text() # param3 = self.param3Edit.text() # with open('F:/学习杂件/程序/python/dataset/data','wb') as f: # f.write(SVCmode+'\n') # f.write(param1+'\n') # f.write(param2+'\n') # f.write(param3) def saveModel(self): model = self.modelCom.currentText() if model == 'Decision': param1 = self.param1Edit.text() else: param1 = self.param1Edit.currentText() param2 = self.param2Edit.text() param3 = self.param3Edit.text() print(model,param1,param2,param3) with open('../data/machineModel/machineParam','w') as f: f.write(model+'\n') f.write(param1+'\n') f.write(param2+'\n') f.write(param3) f.flush() self.showMessage('save success') def showMessage(self, s): message = QMessageBox() message.setText(s) message.exec_()
def setupUi(self, Tab): Tab.setWindowTitle('OpenETran') # Project Tab self.Project = QWidget() grid = QGridLayout() save = QPushButton('Save') load = QPushButton('Load') # RadioButtons to select the simplified or full interface. Simplified selected by default guiSimple = QRadioButton('Simplified interface') guiNormal = QRadioButton('Full interface') guiSimple.setChecked(True) grid.addWidget(save, 0, 0) grid.addWidget(load, 0, 1) grid.addWidget(guiSimple, 0, 3) grid.addWidget(guiNormal, 0, 4) self.Project.setLayout(grid) Tab.addTab(self.Project, 'Project') # Simulation Tab self.Simulation = QWidget() grid = QGridLayout() self.Simulation.setLayout(grid) names = [ 'Number of conductors', '', 'Number of poles', '', 'Line Span (m)', '', 'Left Termination (1/0)', '', 'Right Termination (1/0)', '', 'Time Step (s)', '', 'Simulation Max Time (s)', '' ] addWidgets(grid, names, 7, 2) simulate = QPushButton('Simulate !') grid.addWidget(simulate, 0, 3) # RadioButtons for the simulation mode - One shot mode is selected by default plotMode = QRadioButton('One shot mode simulation') plotMode.setChecked(True) grid.addWidget(plotMode, 1, 3) critMode = QRadioButton('Critical current iteration simulation') grid.addWidget(critMode, 2, 3) # LineEdit fields for Critical current iteration mode pole1 = QLineEdit() pole2 = QLineEdit() wire = QLineEdit() pole1_text = QLabel('First pole to hit') pole2_text = QLabel('Last pole to hit') wire_text = QLabel('Wire sequence') Tab.addTab(self.Simulation, 'Simulation') # Conductor Tab self.Conductor = QWidget() grid = QGridLayout() self.Conductor.setLayout(grid) names = [ 'New', 'Delete', '/', '/', 'Conductor', '/', '/', '/', 'Number', '', 'Height (m)', '', 'Horizontal Position (m)', '', 'Radius (m)', '', 'Voltage Bias (V)', '', 'Sag (m)', '', 'Nb', '', 'Sb (m)', '' ] addWidgets(grid, names, 6, 4) Tab.addTab(self.Conductor, 'Conductors') # Label Tab self.Label = QWidget() grid = QGridLayout() self.Label.setLayout(grid) names = [ 'New', 'Delete', '/', '/', 'Label', '/', '/', '/', 'Type', '//', 'Element number', '', 'Name', '', '/', '/' ] positions = [(i, j) for i in range(4) for j in range(4)] for position, name in zip(positions, names): if name == '': widget = QLineEdit() elif name == 'New' or name == 'Delete': widget = QPushButton(name) elif name == '/': widget = QLabel() elif name == '//': widget = QComboBox() widget.addItem('Phase') widget.addItem('Pole') else: widget = QLabel(name) grid.addWidget(widget, *position) Tab.addTab(self.Label, 'Labels') # Ground Tab self.Ground = QWidget() grid = QGridLayout() self.Ground.setLayout(grid) names = [ 'New', 'Delete', 'Get Counterpoise R60', '/', '/', '/', 'Ground', '/', '/', '/', '/', '/', 'R60 (Ohm)', '', 'Resistivity (Ohm.m)', '', 'Soil Breakdown Gradient (V.m)', '400e+03', 'Downlead Inductance (H/m)', '', 'Length of downlead (m)', '', 'Counterpoise radius (m)', '', 'Counterpoise depth (m)', '', 'Counterpoise length (m)', '', 'Number of segments', '', 'Soil relative permittivity', '', 'Pairs', '', 'Poles', '' ] addWidgets(grid, names, 6, 6) Tab.addTab(self.Ground, 'Ground') # Surge Tab with surge parameters self.Surge = QWidget() grid = QGridLayout() self.Surge.setLayout(grid) names = [ 'Crest Current (A)', '', '30-90 Front Time (s)', '', '50% Fail Time (s)', '', 'Surge Starting Time (s)', '', 'Pairs', '', 'Poles', '' ] addWidgets(grid, names, 6, 2) Tab.addTab(self.Surge, 'Surge') # Steepfront Tab - not added by default (not part of simplified interface) self.Steepfront = QWidget() grid = QGridLayout() self.Steepfront.setLayout(grid) names = [ 'Crest Current (A)', '', '30-90 Front Time (s)', '', '50% Fail Time (s)', '', 'Surge Starting Time (s)', '', 'Max Current Steepness (per unit)', '', 'Pairs', '', 'Poles', '' ] addWidgets(grid, names, 7, 2) # Arrester Tab - not added by default (not part of simplified interface) self.Arrester = QWidget() grid = QGridLayout() self.Arrester.setLayout(grid) names = [ 'New', 'Delete', '/', '/', 'Arrester', '/', '/', '/', 'Sparkover voltage (V)', '', 'Turn-on voltage (V)', '', 'Characteristic"s slope (Ohm)', '', 'Inductance of lead (H/m)', '', 'Lead length (m)', '', 'Pairs', '', 'Poles', '', '/', '/' ] addWidgets(grid, names, 6, 4) # Arrbez Tab self.Arrbez = QWidget() grid = QGridLayout() self.Arrbez.setLayout(grid) names = [ 'New', 'Delete', '/', '/', 'Arrbez', '/', '/', '/', 'Sparkover voltage (V)', '', '10kA 8x20 discharge voltage (V)', '', 'Reference voltage (p.u)', '0.051', 'Inductance of lead (H/m)', '', 'Lead length (m)', '', 'Plot arrester current ? (1/0)', '', 'Pairs', '', 'Poles', '' ] addWidgets(grid, names, 6, 4) Tab.addTab(self.Arrbez, 'Arrbez') # Insulator Tab - not added by default (not part of simplified interface) self.Insulator = QWidget() grid = QGridLayout() self.Insulator.setLayout(grid) names = [ 'New', 'Delete', '/', '/', 'Insulator', '/', '/', '/', 'CFO (V)', '', 'Minimum volt. for destructive effects (V)', '', 'beta (no unit)', '', 'DE', '', 'Pairs', '', 'Poles', '' ] addWidgets(grid, names, 5, 4) # LPM Tab self.LPM = QWidget() grid = QGridLayout() self.LPM.setLayout(grid) names = [ 'New', 'Delete', '/', '/', 'LPM', '/', '/', '/', 'CFO (V)', '', 'E0 (V/m)', '535e+03', 'Kl (no unit)', '7.785e-07', 'Pairs', '', 'Poles', '', '/', '/' ] addWidgets(grid, names, 5, 4) Tab.addTab(self.LPM, 'LPM') # Meter Tab self.Meter = QWidget() grid = QGridLayout() self.Meter.setLayout(grid) names = [ 'New', 'Delete', '/', '/', 'Meter', '/', '/', '/', 'Type', '//', 'Pairs', '', 'Poles', '', '/', '/' ] positions = [(i, j) for i in range(4) for j in range(4)] for position, name in zip(positions, names): if name == '': widget = QLineEdit() elif name == 'New' or name == 'Delete': widget = QPushButton(name) elif name == '/': widget = QLabel() elif name == '//': widget = QComboBox() widget.addItem('Voltage') widget.addItem('Arrester/Arrbez current') widget.addItem('Ground current') widget.addItem('Customer house current') widget.addItem('Transformer X2 term. current') widget.addItem('Pipegap current') else: widget = QLabel(name) grid.addWidget(widget, *position) Tab.addTab(self.Meter, 'Meter') # Resistor Tab - not added by default (not part of simplified interface) self.Resistor = QWidget() grid = QGridLayout() self.Resistor.setLayout(grid) names = [ 'New', 'Delete', '/', '/', 'Resistor', '/', '/', '/', 'Value (Ohm)', '', 'Pairs', '', 'Poles', '', '/', '/' ] addWidgets(grid, names, 4, 4) Tab.addTab(self.Resistor, 'Resistor') # Capacitor Tab - not added by default (not part of simplified interface) self.Capacitor = QWidget() grid = QGridLayout() self.Capacitor.setLayout(grid) names = [ 'New', 'Delete', '/', '/', 'Capacitor', '/', '/', '/', 'Value (F)', '', 'Pairs', '', 'Poles', '', '/', '/' ] addWidgets(grid, names, 4, 4) # Inductor Tab self.Inductor = QWidget() grid = QGridLayout() self.Inductor.setLayout(grid) names = [ 'New', 'Delete', '/', '/', 'Inductor', '/', '/', '/', 'Series resistance (Ohm)', '', 'Value (H)', '', 'Pairs', '', 'Poles', '' ] addWidgets(grid, names, 4, 4) # Customer Tab - not added by default (not part of simplified interface) self.Customer = QWidget() grid = QGridLayout() self.Customer.setLayout(grid) names = [ 'New', 'Delete', '/', '/', '/', '/', 'Customer', '/', '/', '/', '/', '/', 'Rhg (Ohm)', '', 'Soil resistivity (Ohm.m)', '', 'E0 (V/m)', '', 'Lhg (H/m)', '', 'Ground lead length (m)', '', 'Transf. turns ratio', '', 'Lp (H)', '', 'Ls1 (H)', '', 'Ls2 (H)', '', 'Lcm (H/m)', '', 'rA (m)', '', 'rN (m)', '', 'Dan (m)', '', 'Daa (m)', '', 'Service drop length (m)', '', 'Pairs', '', 'Poles', '', '/', '/' ] addWidgets(grid, names, 8, 6) # Pipegap Tab - not added by default (not part of simplified interface) self.Pipegap = QWidget() grid = QGridLayout() self.Pipegap.setLayout(grid) names = [ 'New', 'Delete', '/', '/', 'Pipegap', '/', '/', '/', 'CFO between conductors (V)', '', 'Series resistance (Ohm)', '', 'Pairs', '', 'Poles', '' ] addWidgets(grid, names, 4, 4) @pyqtSlot() def dispNormal(): if guiNormal.isChecked() == True: Tab.addTab(self.Steepfront, 'Steepfront') Tab.addTab(self.Arrester, 'Arrester') Tab.addTab(self.Insulator, 'Insulator') # Tab.addTab(self.Resistor, 'Resistor') Tab.addTab(self.Capacitor, 'Capacitor') Tab.addTab(self.Inductor, 'Inductor') Tab.addTab(self.Customer, 'Customer') Tab.addTab(self.Pipegap, 'Pipegap') @pyqtSlot() def dispSimple(): if guiSimple.isChecked() == True: Tab.removeTab(Tab.indexOf(self.Steepfront)) Tab.removeTab(Tab.indexOf(self.Arrester)) Tab.removeTab(Tab.indexOf(self.Insulator)) # Tab.removeTab( Tab.indexOf(self.Resistor) ) Tab.removeTab(Tab.indexOf(self.Capacitor)) Tab.removeTab(Tab.indexOf(self.Inductor)) Tab.removeTab(Tab.indexOf(self.Customer)) Tab.removeTab(Tab.indexOf(self.Pipegap)) @pyqtSlot() def simOneShot(): if plotMode.isChecked() == True: pole1.setParent(None) pole2.setParent(None) wire.setParent(None) pole1_text.setParent(None) pole2_text.setParent(None) wire_text.setParent(None) @pyqtSlot() def simCrit(): if critMode.isChecked() == True: grid = self.Simulation.layout() grid.addWidget(pole1_text, 7, 0) grid.addWidget(pole2_text, 8, 0) grid.addWidget(wire_text, 9, 0) grid.addWidget(pole1, 7, 1) grid.addWidget(pole2, 8, 1) grid.addWidget(wire, 9, 1) @pyqtSlot() def simulateProject(): openetran = saveProject() Project.simulateProject(plotMode, self, openetran) @pyqtSlot() def saveProject(): # Read the structure in the GUI in case it changed openetran = ReadStruct.read(self, guiNormal) self.lastDirectory = Project.saveProject(self, openetran, self.lastDirectory) return openetran @pyqtSlot() def loadProject(): self.lastDirectory = Project.loadProject(self, guiNormal, self.lastDirectory) @pyqtSlot() def newConductor(): Add_Delete_Widgets.addConductor(self, self.Conductor.layout()) @pyqtSlot() def deleteConductor(): Add_Delete_Widgets.deleteConductor(self, self.Conductor.layout()) @pyqtSlot() def newGround(): Add_Delete_Widgets.addGround(self, self.Ground.layout()) @pyqtSlot() def deleteGround(): Add_Delete_Widgets.deleteGround(self, self.Ground.layout()) @pyqtSlot() def calculateR60(): openetran = ReadStruct.read(self, guiNormal) R60.calcR60(openetran, self.Ground.layout()) @pyqtSlot() def newArrester(): Add_Delete_Widgets.addArrester(self, self.Arrester.layout()) @pyqtSlot() def deleteArrester(): Add_Delete_Widgets.deleteArrester(self, self.Arrester.layout()) @pyqtSlot() def newArrbez(): Add_Delete_Widgets.addArrbez(self, self.Arrbez.layout()) @pyqtSlot() def deleteArrbez(): Add_Delete_Widgets.deleteArrbez(self, self.Arrbez.layout()) @pyqtSlot() def newInsulator(): Add_Delete_Widgets.addInsulator(self, self.Insulator.layout()) @pyqtSlot() def deleteInsulator(): Add_Delete_Widgets.deleteInsulator(self, self.Insulator.layout()) @pyqtSlot() def newLPM(): Add_Delete_Widgets.addLPM(self, self.LPM.layout()) @pyqtSlot() def deleteLPM(): Add_Delete_Widgets.deleteLPM(self, self.LPM.layout()) @pyqtSlot() def newMeter(): Add_Delete_Widgets.addMeter(self, self.Meter.layout()) @pyqtSlot() def deleteMeter(): Add_Delete_Widgets.deleteMeter(self, self.Meter.layout()) @pyqtSlot() def newLabel(): Add_Delete_Widgets.addLabel(self, self.Label.layout()) @pyqtSlot() def deleteLabel(): Add_Delete_Widgets.deleteLabel(self, self.Label.layout()) @pyqtSlot() def newResistor(): Add_Delete_Widgets.addResistor(self, self.Resistor.layout()) @pyqtSlot() def deleteResistor(): Add_Delete_Widgets.deleteResistor(self, self.Resistor.layout()) @pyqtSlot() def newCapacitor(): Add_Delete_Widgets.addCapacitor(self, self.Capacitor.layout()) @pyqtSlot() def deleteCapacitor(): Add_Delete_Widgets.deleteCapacitor(self, self.Capacitor.layout()) @pyqtSlot() def newInductor(): Add_Delete_Widgets.addInductor(self, self.Inductor.layout()) @pyqtSlot() def deleteInductor(): Add_Delete_Widgets.deleteInductor(self, self.Inductor.layout()) @pyqtSlot() def newCustomer(): Add_Delete_Widgets.addCustomer(self, self.Customer.layout()) @pyqtSlot() def deleteCustomer(): Add_Delete_Widgets.deleteCustomer(self, self.Customer.layout()) @pyqtSlot() def newPipegap(): Add_Delete_Widgets.addPipegap(self, self.Pipegap.layout()) @pyqtSlot() def deletePipegap(): Add_Delete_Widgets.deletePipegap(self, self.Pipegap.layout()) # Connect buttons to each actions save.pressed.connect(saveProject) load.pressed.connect(loadProject) simulate.pressed.connect(simulateProject) # Conductor layout = self.Conductor.layout() connectButtons(layout, newConductor, deleteConductor) # Ground layout = self.Ground.layout() connectButtons(layout, newGround, deleteGround) calcR60 = layout.itemAtPosition(0, 2).widget() calcR60.pressed.connect(calculateR60) # Arrester layout = self.Arrester.layout() connectButtons(layout, newArrester, deleteArrester) # Arrbez layout = self.Arrbez.layout() connectButtons(layout, newArrbez, deleteArrbez) # Insulator layout = self.Insulator.layout() connectButtons(layout, newInsulator, deleteInsulator) # LPM layout = self.LPM.layout() connectButtons(layout, newLPM, deleteLPM) # Meter layout = self.Meter.layout() connectButtons(layout, newMeter, deleteMeter) # Labels layout = self.Label.layout() connectButtons(layout, newLabel, deleteLabel) # Resistor layout = self.Resistor.layout() connectButtons(layout, newResistor, deleteResistor) # Capacitor layout = self.Capacitor.layout() connectButtons(layout, newCapacitor, deleteCapacitor) # Inductor layout = self.Inductor.layout() connectButtons(layout, newInductor, deleteInductor) # Customer layout = self.Customer.layout() connectButtons(layout, newCustomer, deleteCustomer) # Pipegap layout = self.Pipegap.layout() connectButtons(layout, newPipegap, deletePipegap) # RadioButtons guiSimple.toggled.connect(dispSimple) guiNormal.toggled.connect(dispNormal) plotMode.toggled.connect(simOneShot) critMode.toggled.connect(simCrit)
def initUI(self): w = QLabel() text = 'Define properties of your new button below.' w.setText(text) hbox = QHBoxLayout() hbox.addStretch(1) self.buttons = QDialogButtonBox( QDialogButtonBox.Ok | QDialogButtonBox.Cancel, QtCore.Qt.Horizontal, self) self.buttons.accepted.connect(self.accept) self.buttons.rejected.connect(self.reject) self.buttons.setMinimumSize(QtCore.QSize(50, 50)) for b in self.buttons.buttons(): b.setMinimumHeight(50) hbox.addWidget(self.buttons) vbox = QVBoxLayout() h = QHBoxLayout() vbox.addWidget(w) l = [ 'Name', 'X Positon', 'Y Position', 'Width', 'Height', 'Color', 'Behavior', 'Input' ] behavior_list = ['normal', 'sticky', 'autorepeat', 'combo'] for i in range(8): if i == 0: new_vbox = QVBoxLayout() new_widget = QWidget() lbl = QLabel(l[i]) b = QLineEdit() b.setMinimumHeight(50) new_vbox.addWidget(lbl) new_vbox.addWidget(b) new_widget.setLayout(new_vbox) h.addWidget(new_widget) b.textChanged.connect( partial(self.write_widget_value, i, b.text)) if i > 0 and i <= 4: new_vbox = QVBoxLayout() new_widget = QWidget() lbl = QLabel(l[i]) b = QSpinBox() b.setMinimum(0) b.setMaximum(100) b.setSingleStep(1) b.setValue(50) b.setMinimumHeight(50) new_vbox.addWidget(lbl) new_vbox.addWidget(b) new_widget.setLayout(new_vbox) h.addWidget(new_widget) b.valueChanged.connect( partial(self.write_widget_value, i, b.value)) if i == 5: new_vbox = QVBoxLayout() new_widget = QWidget() lbl = QLabel(l[i]) b = QPushButton() b.setMinimumHeight(50) new_vbox.addWidget(lbl) new_vbox.addWidget(b) new_widget.setLayout(new_vbox) h.addWidget(new_widget) b.clicked.connect(partial(self.get_color, i, b)) if i == 6: new_vbox = QVBoxLayout() new_widget = QWidget() lbl = QLabel(l[i]) b = QComboBox() b.setMinimumHeight(50) b.addItem(behavior_list[0]) b.addItem(behavior_list[1]) b.addItem(behavior_list[2]) new_vbox.addWidget(lbl) new_vbox.addWidget(b) new_widget.setLayout(new_vbox) h.addWidget(new_widget) b.currentIndexChanged.connect( partial(self.write_widget_value, i, b.currentText)) if i == 7: new_vbox = QVBoxLayout() new_widget = QWidget() lbl = QLabel(l[i]) b = QPushButton() b.setMinimumHeight(50) new_vbox.addWidget(lbl) new_vbox.addWidget(b) new_widget.setLayout(new_vbox) h.addWidget(new_widget) b.clicked.connect(partial(self.keypicker, i, b)) vbox.addSpacing(10) vbox.addLayout(h) vbox.addSpacing(20) vbox.addLayout(hbox) self.setLayout(vbox) w, h = self.screen_width * .9, self.sizeHint().height() self.setGeometry((self.screen_width - w) / 2, (self.screen_height - h) / 2, w, h) self.setWindowTitle('Create a New Button')
def init(self, filename, tab_name): self.scroll = QScrollArea() self.main_box_widget = QWidget() self.vbox = QVBoxLayout() self.hbox = QHBoxLayout() self.hbox.setAlignment(Qt.AlignTop) self.file_name = filename self.tab_name = tab_name self.tab = QGridLayout() widget = QWidget() widget.setLayout(self.tab) self.vbox.addWidget(widget) scan_remove_file(filename) self.edit_list = [] self.lines = inp_load_file(filename) if self.lines == False: error_dlg(self, _("File not found.") + " " + filename) return n = 0 pos = 0 my_token_lib = tokens() widget_number = 0 while (1): ret, pos = inp_get_next_token_array(self.lines, pos) token = ret[0] if token == "#ver": break if token == "#end": break if token.startswith("#"): show = False units = "Units" value = ret[1] result = my_token_lib.find(token) if result != False: units = result.units text_info = result.info show = True #self.set_size_request(600,-1) if show == True: description = QLabel_click() description.setText(latex_to_html(text_info)) if os.path.isfile( os.path.splitext(filename)[0] + "_" + token[1:] + ".ref"): description.setStyleSheet('color: green') description.clicked.connect( functools.partial(self.callback_ref, filename, token, description)) if result.widget == "gtkswitch": edit_box = gtkswitch() edit_box.setFixedSize(300, 25) edit_box.set_value(str2bool(value)) edit_box.changed.connect( functools.partial(self.callback_edit, filename, token, edit_box)) elif result.widget == "leftright": edit_box = leftright() edit_box.setFixedSize(300, 25) edit_box.set_value(str2bool(value)) edit_box.changed.connect( functools.partial(self.callback_edit, filename, token, edit_box)) elif result.widget == "gpvdm_select": edit_box = gpvdm_select(file_box=True) edit_box.setFixedSize(300, 25) edit_box.setText(value) edit_box.edit.textChanged.connect( functools.partial(self.callback_edit, filename, token, edit_box)) elif result.widget == "QLineEdit": edit_box = QLineEdit() edit_box.setFixedSize(300, 25) if self.editable == False: edit_box.setReadOnly(True) edit_box.setText(value) #edit_box.set_text(self.lines[pos]); edit_box.textChanged.connect( functools.partial(self.callback_edit, filename, token, edit_box)) #edit_box.show() elif result.widget == "QColorPicker": r = float(ret[1]) g = float(ret[2]) b = float(ret[3]) edit_box = QColorPicker(r, g, b) edit_box.setFixedSize(300, 25) edit_box.changed.connect( functools.partial(self.callback_edit, filename, token, edit_box)) elif result.widget == "QComboBoxLang": edit_box = QComboBoxLang() edit_box.setFixedSize(300, 25) for i in range(0, len(result.defaults)): edit_box.addItemLang(result.defaults[i][0], result.defaults[i][1]) edit_box.setValue_using_english(value) edit_box.currentIndexChanged.connect( functools.partial(self.callback_edit, filename, token, edit_box)) elif result.widget == "QParasitic": edit_box = QParasitic() edit_box.setFixedSize(300, 25) edit_box.setValue(value) edit_box.textChanged.connect( functools.partial(self.callback_edit, filename, token, edit_box)) elif result.widget == "QChangeLog": edit_box = QChangeLog() edit_box.setMinimumHeight(100) if self.editable == False: edit_box.setReadOnly(True) edit_box.setText(value) edit_box.textChanged.connect( functools.partial(self.callback_edit, filename, token, edit_box)) else: edit_box = QComboBox() edit_box.setFixedSize(300, 25) for i in range(0, len(result.defaults)): edit_box.addItem(result.defaults[i]) all_items = [ edit_box.itemText(i) for i in range(edit_box.count()) ] for i in range(0, len(all_items)): if all_items[i] == value: edit_box.setCurrentIndex(i) break edit_box.currentIndexChanged.connect( functools.partial(self.callback_edit, filename, token, edit_box)) unit = QLabel() unit.setText(latex_to_html(units)) self.tab.addWidget(description, widget_number, 0) self.tab.addWidget(edit_box, widget_number, 1) self.tab.addWidget(unit, widget_number, 2) scan_item_add(filename, token, text_info, 1) widget_number = widget_number + 1 spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.vbox.addWidget(spacer) self.main_box_widget.setLayout(self.vbox) self.scroll.setWidget(self.main_box_widget) self.icon_widget = QWidget() self.icon_widget_vbox = QVBoxLayout() self.icon_widget.setLayout(self.icon_widget_vbox) if self.icon_file != "": self.image = QLabel() icon = QIcon_load(self.icon_file) self.image.setPixmap(icon.pixmap(icon.actualSize(QSize(32, 32)))) self.icon_widget_vbox.addWidget(self.image) spacer2 = QWidget() spacer2.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding) self.icon_widget_vbox.addWidget(spacer2) self.hbox.addWidget(self.icon_widget) self.hbox.addWidget(self.scroll) self.setLayout(self.hbox)
def __init__(self, nameBlock, unit, inout, valInit, parent=None): super(editParam, self).__init__(parent) self.inout = inout self.setWindowTitle('Input parameters') self.setWindowFlags(self.windowFlags() & QtCore.Qt.WindowCloseButtonHint) self.setMinimumWidth(280) nIn = len(inout[0]) self.listField = {} for i in range(0, nIn): self.listField[inout[0][i]] = DefinitType(valInit[i]).returntype() self.vbox = QVBoxLayout(self) hbox = QHBoxLayout() label = QLabel("Block Name : ") hbox.addWidget(label) label = QLineEdit(nameBlock) label.setDisabled(True) label.setAlignment(QtCore.Qt.AlignTop) hbox.addWidget(label) hbox2 = QHBoxLayout() label = QLabel("Block Unit : ") hbox2.addWidget(label) label = QLineEdit(unit) label.setDisabled(True) label.setAlignment(QtCore.Qt.AlignTop) hbox2.addWidget(label) self.vbox.addLayout(hbox) self.vbox.addLayout(hbox2) scrolllayout = QVBoxLayout() scrollwidget = QWidget() scrollwidget.setLayout(scrolllayout) scroll = QScrollArea() # scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) scroll.setWidgetResizable(True) scroll.setWidget(scrollwidget) scroll.setMinimumWidth(200) self.label = [] self.zoneline = [] palette = QPalette() font = QFont("Times", 10) font.setBold(True) for i in range(len(inout[0])): hbox3 = QHBoxLayout() label = QLabel(inout[0][i]) if ('enumerate' not in self.listField[inout[0][i]] and self.listField[inout[0][i]] != 'bool') or ('Node(' in str( inout[1][i])): lab = QLineEdit() lab.setText(str(inout[1][i])) lab.setFont(font) if 'Node(' in lab.text(): lab.setReadOnly(True) self.listField[inout[0][i]] = 'str' palette.setColor(QPalette.Text, QtCore.Qt.darkGray) else: palette.setColor(QPalette.Text, QtCore.Qt.blue) lab.setPalette(palette) self.label.append(inout[0][i]) self.zoneline.append(lab) hbox3.addWidget(label) hbox3.addWidget(self.zoneline[i]) scrolllayout.addLayout(hbox3) else: lab = QComboBox() lab.setMinimumWidth(self.size().width() / 4) if self.listField[inout[0][i]] == 'bool': lab.addItem('True') lab.addItem('False') else: for it in list(eval(valInit[i])): lab.addItem(it[1]) # lab.addItem(str(it)) index = lab.findText(str(inout[1][i]), Qt.MatchFixedString) if index >= 0: lab.setCurrentIndex(index) lab.setFont(font) palette.setColor(QPalette.Text, QtCore.Qt.blue) lab.setPalette(palette) self.label.append(inout[0][i]) self.zoneline.append(lab) hbox3.addWidget(label) hbox3.addWidget(self.zoneline[i]) scrolllayout.addLayout(hbox3) self.vbox.addWidget(scroll) self.info = QLabel() self.vbox.addWidget(self.info) buttonOk = QPushButton('Ok', self) buttonCancel = QPushButton('Cancel', self) hbox4 = QHBoxLayout() hbox4.addWidget(buttonOk) hbox4.addWidget(buttonCancel) self.vbox.addLayout(hbox4) # self.setLayout(self.vbox) self.adjustSize() buttonOk.clicked.connect(self.OK) buttonCancel.clicked.connect(self.CANCEL)
def addMeter(self, grid): names = [ 'Meter', '/', '/', '/', 'Type', '//', 'Pairs', '', 'Poles', '', '/', '/' ] count = grid.count() rowStart = int(count / 4) rowEnd = rowStart + 3 positions = [(i, j) for i in range(rowStart, rowEnd) for j in range(4)] for position, name in zip(positions, names): if name == '': widget = QLineEdit() elif name == '/': widget = QLabel() elif name == '//': widget = QComboBox() widget.addItem('Voltage') widget.addItem('Arrester/Arrbez current') widget.addItem('Ground current') widget.addItem('Customer house current') widget.addItem('Transformer X2 term. current') widget.addItem('Pipegap current') else: widget = QLabel(name) grid.addWidget(widget, *position)
def setupTab5(self, tab): """Container widgets for preview panel""" scrollContainer = QVBoxLayout() scrollArea = QScrollArea() mainWidget = QWidget() layout = QVBoxLayout() mainWidget.setLayout(layout) mainWidget.setMinimumSize(QSize(420, 600)) scrollArea.setWidgetResizable(True) scrollArea.setWidget(mainWidget) scrollContainer.addWidget(scrollArea) tab.setLayout(scrollContainer) group = QGroupBox(self.tr("QGroupBox")) # "QGroupBox控件")) hbox = QHBoxLayout() hbox.addWidget(QLabel( self.tr("this is a QGroupBox widget"))) # "这是一个QGroupBox控件"))) group.setLayout(hbox) layout.addWidget(group) group = QGroupBox(self.tr("QGroupBox")) # "QGroupBox控件")) group.setCheckable(True) hbox = QHBoxLayout() hbox.addWidget(QLabel(self.tr( "this is a checkable QGroupBox widget"))) # "这是一个QGroupBox控件"))) group.setLayout(hbox) layout.addWidget(group) group = QGroupBox(self.tr("StackLayout")) # "StackLayout布局")) group.setCheckable(True) hbox = QHBoxLayout() group.setLayout(hbox) listWidget = QListWidget() stack = QStackedWidget() hbox.addWidget(listWidget) hbox.addWidget(stack) listWidget.currentRowChanged.connect(stack.setCurrentIndex) listWidget.addItem("stack1") listWidget.addItem("stack2") listWidget.addItem("stack3") s1 = QGroupBox("stack1") s2 = QGroupBox("stack2") s3 = QGroupBox("stack3") l1 = QLabel("stack1") l2 = QLabel("stack2") l3 = QLabel("stack3") t1 = QLineEdit() t2 = QLineEdit() t3 = QLineEdit() lay1 = QHBoxLayout() lay2 = QHBoxLayout() lay3 = QHBoxLayout() lay1.addWidget(l1) lay2.addWidget(l2) lay3.addWidget(l3) lay1.addWidget(t1) lay2.addWidget(t2) lay3.addWidget(t3) s1.setLayout(lay1) s2.setLayout(lay2) s3.setLayout(lay3) stack.addWidget(s1) stack.addWidget(s2) stack.addWidget(s3) layout.addWidget(group) group = QGroupBox("ToolBox") group.setCheckable(True) lay = QVBoxLayout() group.setLayout(lay) layout.addWidget(group) t1 = QToolBox() w1 = QWidget() w2 = QWidget() i1 = QVBoxLayout() i2 = QVBoxLayout() w1.setLayout(i1) w2.setLayout(i2) i1.addWidget(QLabel("aaaaa")) i1.addWidget(QLabel("aaaaa")) i1.addWidget(QLabel("aaaaa")) i2.addWidget(QLabel("aaaaa")) i2.addWidget(QLabel("aaaaa")) i1.addStretch(1) t1.addItem(w1, "Tab1") t1.addItem(w2, "Tab2") t1.addItem(QWidget(), "tab3") lay.addWidget(t1) group = QGroupBox("TabWidget") group.setCheckable(True) lay = QVBoxLayout() lay1 = QHBoxLayout() lay2 = QHBoxLayout() lay.addLayout(lay1) lay.addLayout(lay2) group.setLayout(lay) layout.addWidget(group) t1 = QTabWidget() t1.addTab(QWidget(), "tab1") t1.addTab(QWidget(), "tab2") t1.setTabsClosable(True) t1.setMinimumHeight(200) t2 = QTabWidget() t2.addTab(QWidget(), "tab1") t2.addTab(QWidget(), "tab2") t2.setTabPosition(QTabWidget.South) t2.setTabShape(QTabWidget.Triangular) t3 = QTabWidget() t3.addTab(QWidget(), "tab1") t3.addTab(QWidget(), "tab2") t3.setTabPosition(QTabWidget.West) t4 = QTabWidget() t4.addTab(QWidget(), "tab1") t4.addTab(QWidget(), "tab2") t4.setTabPosition(QTabWidget.East) t3.setMinimumHeight(300) lay1.addWidget(t1) lay1.addWidget(t2) lay2.addWidget(t3) lay2.addWidget(t4)
def populate(self,lines): self.f.lines=lines n=0 pos=0 my_token_lib=tokens() widget_number=0 bib=bibtex() if self.file_name!=None: bib.load(os.path.splitext(self.file_name)[0]+".bib") while (1): token,values=self.f.get_next_token_array() if token=="#ver": break if token=="#end": break if token.startswith("#"): show=False units="Units" value=values[0] result=my_token_lib.find(token) if result!=False: #print(token,result.info) units=result.units text_info=result.info show=True if result.hidden==True: show=False if show == True : description=QLabel_click() description.setText(latex_to_html(text_info)) if self.file_name!=None: if bib.get_ref(token)!=False: description.setStyleSheet('color: green') description.clicked.connect(functools.partial(self.callback_ref,token,description)) #units widget if result.units_widget=="QLabel": unit=QLabel() unit.setText(latex_to_html(units)) elif result.units_widget=="QPushButton": unit=QPushButton() unit.setText(latex_to_html(units)) unit.setFixedSize(50, 25) #edit widget if result.widget=="gtkswitch": edit_box=gtkswitch() edit_box.setFixedSize(300, 25) edit_box.changed.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="leftright": edit_box=leftright() edit_box.setFixedSize(300, 25) edit_box.changed.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="gpvdm_select": edit_box=gpvdm_select(file_box=True) edit_box.setFixedSize(300, 25) edit_box.edit.textChanged.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="gpvdm_select_material": edit_box=gpvdm_select_material(file_box=False) edit_box.setFixedSize(300, 25) edit_box.edit.textChanged.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="gpvdm_select_emission": edit_box=gpvdm_select_emission(file_box=False) edit_box.setFixedSize(300, 25) edit_box.edit.textChanged.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="QLineEdit": edit_box=QLineEdit() edit_box.setFixedSize(300, 25) if self.editable==False: edit_box.setReadOnly(True) edit_box.textChanged.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) #edit_box.show() elif result.widget=="QColorPicker": r=float(values[0]) g=float(values[1]) b=float(values[2]) edit_box=QColorPicker(r,g,b) edit_box.setFixedSize(300, 25) edit_box.changed.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="QComboBoxLang": edit_box=QComboBoxLang() edit_box.setFixedSize(300, 25) for i in range(0,len(result.defaults)): edit_box.addItemLang(result.defaults[i][0],result.defaults[i][1]) edit_box.currentIndexChanged.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="QComboBoxNewtonSelect": edit_box=QComboBoxNewtonSelect() edit_box.setFixedSize(300, 25) for i in range(0,len(result.defaults)): edit_box.addItem(result.defaults[i]) edit_box.currentIndexChanged.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="QComboBoxShape": edit_box=QComboBoxShape() edit_box.setFixedSize(300, 25) edit_box.currentIndexChanged.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="QParasitic": edit_box=QParasitic() edit_box.setFixedSize(300, 25) edit_box.textChanged.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="QChangeLog": edit_box=QChangeLog(self) edit_box.setMinimumHeight(100) if self.editable==False: edit_box.setReadOnly(True) edit_box.textChanged.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="generic_switch": edit_box=generic_switch(state0=result.defaults[0][0],state1=result.defaults[1][0],state0_value=result.defaults[0][1],state1_value=result.defaults[1][1],) edit_box.setFixedSize(300, 25) if value=="exponential": unit.setEnabled(False) edit_box.changed.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="mobility_widget": edit_box=mobility_widget(electrons=result.defaults[0]) edit_box.setFixedSize(400, 25) if token=="#symmetric_mobility_e": value = [self.f.get_token(token),self.f.get_token("#mue_z"),self.f.get_token("#mue_x"),self.f.get_token("#mue_y")] if token=="#symmetric_mobility_h": value = [self.f.get_token(token),self.f.get_token("#muh_z"),self.f.get_token("#muh_x"),self.f.get_token("#muh_y")] if token=="#electrical_symmetrical_resistance": value = [self.f.get_token(token),self.f.get_token("#electrical_series_z"),self.f.get_token("#electrical_series_x"),self.f.get_token("#electrical_series_y")] edit_box.changed.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) elif result.widget=="shape_dos_switch": edit_box=shape_dos_switch() edit_box.shape_file=self.file_name edit_box.setFixedSize(300, 25) edit_box.changed.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) if value=="none": unit.setEnabled(False) else: edit_box=QComboBox() edit_box.setFixedSize(300, 25) for i in range(0,len(result.defaults)): edit_box.addItem(result.defaults[i]) edit_box.currentIndexChanged.connect(functools.partial(self.callback_edit,token,edit_box,unit,result)) widget_set_value(edit_box,value) if type(unit)==QPushButton: unit.clicked.connect(functools.partial(self.callback_unit_click,token,edit_box,unit)) a=tab_line() a.token=token a.label=description a.edit_box=edit_box a.units=unit a.widget=result.widget a.hide_on_true_token=result.hide_on_true_token a.hide_on_false_token=result.hide_on_false_token a.hide_on_token_eq=result.hide_on_token_eq self.widget_list.append(a) self.tab.addWidget(description,widget_number,0) self.tab.addWidget(edit_box,widget_number,1) self.tab.addWidget(unit,widget_number,2) widget_number=widget_number+1 self.hide_show_widgets()
def init(self, filename, tab_name): self.vbox = QVBoxLayout() self.file_name = filename self.tab_name = tab_name self.tab = QGridLayout() widget = QWidget() widget.setLayout(self.tab) self.vbox.addWidget(widget) scan_remove_file(filename) self.edit_list = [] inp_load_file(self.lines, filename) n = 0 pos = 0 my_token_lib = tokens() height = 27 widget_number = 0 while pos < len(self.lines): token = self.lines[pos] if token == "#ver": break if token == "#end": break if token.startswith("#"): show = False units = "Units" pos = pos + 1 value = self.lines[pos] result = my_token_lib.find(token) if result != False: units = result.units text_info = result.info show = True # self.set_size_request(600,-1) if show == True: description = QLabel() description.setText(latex_to_html(text_info)) if result.opt[0] == "switch": edit_box = gtkswitch() edit_box.set_value(str2bool(value)) edit_box.changed.connect(functools.partial(self.callback_edit, filename, token, edit_box)) elif result.opt[0] == "leftright": edit_box = leftright() edit_box.set_value(str2bool(value)) edit_box.changed.connect(functools.partial(self.callback_edit, filename, token, edit_box)) elif result.opt[0] == "text": edit_box = QLineEdit() if self.editable == False: edit_box.setReadOnly(True) edit_box.setText(value) # edit_box.set_text(self.lines[pos]); edit_box.textChanged.connect(functools.partial(self.callback_edit, filename, token, edit_box)) # edit_box.show() else: edit_box = QComboBox() for i in range(0, len(result.opt)): edit_box.addItem(result.opt[i]) all_items = [edit_box.itemText(i) for i in range(edit_box.count())] for i in range(0, len(all_items)): if all_items[i] == token: edit_box.setCurrentIndex(i) edit_box.currentIndexChanged.connect( functools.partial(self.callback_edit, filename, token, edit_box) ) edit_box.setFixedSize(300, 25) unit = QLabel() unit.setText(latex_to_html(units)) self.tab.addWidget(description, widget_number, 0) self.tab.addWidget(edit_box, widget_number, 1) self.tab.addWidget(unit, widget_number, 2) scan_item_add(filename, token, text_info, 1) widget_number = widget_number + 1 pos = pos + 1 spacer = QWidget() spacer.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding) self.vbox.addWidget(spacer) self.setLayout(self.vbox)