def __init__(self, ui_file, devMode, parent=None): super(MainWindow, self).__init__() self.uiFileName = ui_file # use this if there are multiple UI files if devMode == "development": # use ui file directly made by QDesigner uiFile = QFile(ui_file) uiFile.open(QFile.ReadOnly) # read in UI for the form loader = QUiLoader() self.window = loader.load(uiFile) uiFile.close() else: #deployment - use .py version of ui file, with slightly different setup self.ui = Ui_MainWindow() self.ui.setupUi(self) self.getParts() # identify form objects self.connectParts() # connect buttons to operations self.convs = Converters( ) # load converters for main conversion categories self.yc = YearConverters( ) # load converters for japanese years, zodiac years self.mess = Mess() # instructions and messages in local language self.validFloat = QDoubleValidator() self.validYear = QIntValidator() self.validYear.setRange(1, 9999) # used for years self.btnConvert.hide() self.widgetSetup("start") # initial conditions for form if devMode == "development": self.window.show() else: self.show()
def __init__(self): super().__init__() self.main_layout = QGridLayout() self.main_layout.setAlignment(Qt.AlignTop) self.learning_rate = QLineEdit("0.01") self.learning_rate.setValidator(QDoubleValidator(0., 1., 5)) self.momentum = QLineEdit("0.00") self.momentum.setValidator(QDoubleValidator(0., 1e5, 2)) self.rho = QLineEdit("0.9") self.rho.setValidator(QDoubleValidator(0., 1e5, 10)) self.epsilon = QLineEdit("1e-07") self.epsilon.setValidator(QDoubleValidator(0., 1e-10, 10)) self.centered = QComboBox() self.centered.addItems(["True", "False"]) self.main_layout.addWidget(QLabel("Learning rate:"), 0, 0) self.main_layout.addWidget(self.learning_rate, 0, 1) self.main_layout.addWidget(QLabel("Momentum:"), 1, 0) self.main_layout.addWidget(self.momentum,1, 1) self.main_layout.addWidget(QLabel("rho:"), 2, 0) self.main_layout.addWidget(self.rho,2 , 1) self.main_layout.addWidget(QLabel("epsilon:"),3 ,0) self.main_layout.addWidget(self.epsilon,3, 1) self.main_layout.addWidget(QLabel("centered:"), 4, 0) self.main_layout.addWidget(self.centered, 4, 1) self.setLayout(self.main_layout)
def __init__(self): super().__init__() self.main_layout = QGridLayout() self.main_layout.setAlignment(Qt.AlignTop) self.learning_rate = QLineEdit("0.001") self.learning_rate.setValidator(QDoubleValidator(0., 1., 5)) self.epsilon = QLineEdit("1e-07") self.epsilon.setValidator(QDoubleValidator(0., 1e-10, 10)) self.amsgrad = QComboBox() self.amsgrad.addItems(["True", "False"]) self.beta_1 = QLineEdit("0.9") self.beta_1.setValidator(QDoubleValidator(0., 1e-10, 10)) self.beta_2 = QLineEdit("0.999") self.beta_2.setValidator(QDoubleValidator(0., 1e-10, 10)) self.main_layout.addWidget(QLabel("Learning rate:"), 0, 0) self.main_layout.addWidget(self.learning_rate, 0, 1) self.main_layout.addWidget(QLabel("Epsilon:"),1 ,0) self.main_layout.addWidget(self.epsilon,1, 1) self.main_layout.addWidget(QLabel("Beta 1:"), 2, 0) self.main_layout.addWidget(self.beta_1,2, 1) self.main_layout.addWidget(QLabel("Beta 2:"), 3, 0) self.main_layout.addWidget(self.beta_2,3, 1) self.main_layout.addWidget(QLabel("Amsgrad:"), 4, 0) self.main_layout.addWidget(self.amsgrad, 4, 1) self.setLayout(self.main_layout)
def _add_float_line_edit(self, text="0", min_val=float('-inf'), max_val=float('inf'), decimals=100): validator = QDoubleValidator(min_val, max_val, decimals) validator.setLocale(QLocale.English) numedit = self._add_line_edit(text) numedit.setValidator(validator) return numedit
def __init__(self, ui_file, parent=None): super(AddCompartment, self).__init__(parent) ui_file = QFile(ui_file) ui_file.open(QFile.ReadOnly) self.window = QUiLoader().load(ui_file) add_button = self.window.findChild(QPushButton, 'AddButton') add_button.clicked.connect(self.on_add_clicked) self.nameLE = self.window.findChild(QLineEdit, 'NameLE') self.symbolLE = self.window.findChild(QLineEdit, 'SymbolLE') self.initLE = self.window.findChild(QLineEdit, 'InitLE') self.infectionStateCheckBox = self.window.findChild( QCheckBox, 'InfectionStateCheckBox') # Add Constraints self.initLE.setValidator(QDoubleValidator()) self.nameLE.setMaxLength(32) self.symbolLE.setMaxLength(32) self.initLE.setMaxLength(16) self.window.setWindowIcon(QIcon(os.path.join( 'ui_files', 'icon.png'))) # Set the window icon self.window.show()
def __init__(self, img_name, questions): super().__init__() layout = qtw.QVBoxLayout() img = QPixmap(img_name) img_holder = qtw.QLabel() img_holder.setPixmap(img.scaled(800, 500, Qt.KeepAspectRatio, Qt.SmoothTransformation)) img_holder.setAlignment(Qt.AlignCenter) self.edit_boxes = [] layout.addWidget(img_holder) for q in questions: wid = qtw.QWidget() hlay = qtw.QHBoxLayout() txt = JustText(q) ebox = qtw.QLineEdit() # not sure how many digits to allow depending on currency ebox.setValidator(QDoubleValidator(0, 10000, 2)) ebox.setMaximumWidth(200) fnt = ebox.font() fnt.setPointSize(26) ebox.setFont(fnt) ebox.setStyleSheet('QLineEdit {background-color: yellow; border: 2px solid gray;}') self.edit_boxes.append(ebox) hlay.addWidget(txt, Qt.AlignRight | Qt.AlignVCenter) hlay.addWidget(ebox, Qt.AlignLeft | Qt.AlignVCenter) wid.setLayout(hlay) layout.addWidget(wid) self.setLayout(layout)
def __init__(self, parent=None): QDialog.__init__(self, parent) self.setModal(True) self.setWindowTitle("Abweichender Betrag") layout = QGridLayout(self) self.label = QtWidgets.QLabel(self) self.setLabelText("Betrag eingeben:") layout.addWidget(self.label, 0, 0) self._numEntry = QtWidgets.QLineEdit(self) layout.addWidget(self._numEntry, 1, 0) self._numEntry.setAlignment(Qt.AlignRight | Qt.AlignTrailing | Qt.AlignVCenter) self._numEntry.setValidator(QDoubleValidator(-9999, 9999, 2, self)) self._numEntry.setFocus() self.btnAdd = QPushButton(self, text="+") layout.addWidget(self.btnAdd, 0, 1) self.btnAdd.clicked.connect(self._add) self.btnSub = QPushButton(self, text="-") layout.addWidget(self.btnSub, 1, 1) self.btnSub.clicked.connect(self._sub) self.btnRepl = QPushButton(self, text="=") layout.addWidget(self.btnRepl, 2, 1) self.btnRepl.clicked.connect(self._replace) self.btnCancel = QPushButton(self, text="Cancel") layout.addWidget(self.btnCancel, 2, 0) self.btnCancel.clicked.connect(self._cancel) self.setLayout(layout)
def setupUi(self, Dialog): Dialog.setObjectName("Dialog") Dialog.resize(1200, 360) self.graphicsView = QtWidgets.QGraphicsView(Dialog) self.graphicsView.setGeometry(QtCore.QRect(20, 40, 1020, 130)) self.graphicsView.setObjectName("graphicsView") self.comboBox = QtWidgets.QComboBox(Dialog) self.comboBox.setGeometry(QtCore.QRect(210, 240, 201, 41)) self.comboBox.setObjectName("comboBox") self.comboBox_2 = QtWidgets.QComboBox(Dialog) self.comboBox_2.setGeometry(QtCore.QRect(460, 240, 201, 41)) self.comboBox_2.setObjectName("comboBox_2") self.pushButton = QtWidgets.QPushButton(Dialog) self.pushButton.setGeometry(QtCore.QRect(710, 240, 111, 51)) self.pushButton.setObjectName("pushButton") self.lineEdit = QtWidgets.QLineEdit(Dialog) self.lineEdit.setValidator(QDoubleValidator()) self.lineEdit.setGeometry(QtCore.QRect(50, 238, 113, 41)) self.lineEdit.setObjectName("lineEdit") self.label = QtWidgets.QLabel(Dialog) self.label.setGeometry(QtCore.QRect(220, 200, 111, 21)) self.label.setObjectName("label") self.label_2 = QtWidgets.QLabel(Dialog) self.label_2.setGeometry(QtCore.QRect(460, 200, 121, 21)) self.label_2.setObjectName("label_2") self.label_3 = QtWidgets.QLabel(Dialog) self.label_3.setGeometry(QtCore.QRect(60, 200, 80, 21)) self.label_3.setObjectName("label_3") self.label_R_title = QtWidgets.QLabel(Dialog) self.label_R_title.setGeometry(QtCore.QRect(60, 320, 20, 21)) self.label_R_title.setObjectName("label_R_title") self.label_R = QtWidgets.QLabel(Dialog) self.label_R.setGeometry(QtCore.QRect(80, 320, 40, 21)) self.label_R.setObjectName("label_R") self.label_G_title = QtWidgets.QLabel(Dialog) self.label_G_title.setGeometry(QtCore.QRect(140, 320, 20, 21)) self.label_G_title.setObjectName("label_G_title") self.label_G = QtWidgets.QLabel(Dialog) self.label_G.setGeometry(QtCore.QRect(160, 320, 40, 21)) self.label_G.setObjectName("label_G") self.label_B_title = QtWidgets.QLabel(Dialog) self.label_B_title.setGeometry(QtCore.QRect(220, 320, 20, 21)) self.label_B_title.setObjectName("label_B_title") self.label_B = QtWidgets.QLabel(Dialog) self.label_B.setGeometry(QtCore.QRect(240, 320, 40, 21)) self.label_B.setObjectName("label_B") self.label_input_title = QtWidgets.QLabel(Dialog) self.label_input_title.setGeometry(QtCore.QRect(300, 320, 60, 21)) self.label_input_title.setObjectName("label_input_title") self.label_input = QtWidgets.QLabel(Dialog) self.label_input.setGeometry(QtCore.QRect(400, 320, 40, 21)) self.label_input.setObjectName("label_input") self.retranslateUi(Dialog) QtCore.QMetaObject.connectSlotsByName(Dialog)
def __init__(self): super().__init__() self.main_layout = QGridLayout() self.main_layout.setAlignment(Qt.AlignTop) self.learning_rate = QLineEdit("0.01") self.learning_rate.setValidator(QDoubleValidator(0., 1., 5)) self.momentum = QLineEdit("0.00") self.momentum.setValidator(QDoubleValidator(0., 1e5, 2)) self.nestrov = QComboBox() self.nestrov.addItems(["True", "False"]) self.main_layout.addWidget(QLabel("Learning rate:"), 0, 0) self.main_layout.addWidget(self.learning_rate, 0, 1) self.main_layout.addWidget(QLabel("Momentum:"), 1, 0) self.main_layout.addWidget(self.momentum,1, 1) self.main_layout.addWidget(QLabel("Nestrov:"), 2, 0) self.main_layout.addWidget(self.nestrov) self.setLayout(self.main_layout)
def __init__(self): super().__init__() self.main_layout = QGridLayout() self.main_layout.setAlignment(Qt.AlignTop) self.learning_rate = QLineEdit("0.01") self.learning_rate.setValidator(QDoubleValidator(0., 1., 5)) self.epsilon = QLineEdit("1e-07") self.epsilon.setValidator(QDoubleValidator(0., 1e-10, 10)) self.initial_accumulator_value = QLineEdit("0.1") self.initial_accumulator_value.setValidator(QDoubleValidator(0., 1e-10, 10)) self.main_layout.addWidget(QLabel("Learning rate:"), 0, 0) self.main_layout.addWidget(self.learning_rate, 0, 1) self.main_layout.addWidget(QLabel("Epsilon:"),1 ,0) self.main_layout.addWidget(self.epsilon,1, 1) self.main_layout.addWidget(QLabel("Initial_accumulator_value:"), 2, 0) self.main_layout.addWidget(self.initial_accumulator_value,2 , 1) self.setLayout(self.main_layout)
def __init__(self): super().__init__() self.main_layout = QGridLayout() self.main_layout.setAlignment(Qt.AlignTop) self.learning_rate = QLineEdit("0.001") self.learning_rate.setValidator(QDoubleValidator(0., 1., 5)) self.epsilon = QLineEdit("1e-07") self.epsilon.setValidator(QDoubleValidator(0., 1e-10, 10)) self.rho = QLineEdit("0.95") self.rho.setValidator(QDoubleValidator(0., 1e5, 10)) self.main_layout.addWidget(QLabel("Learning rate:"), 0, 0) self.main_layout.addWidget(self.learning_rate, 0, 1) self.main_layout.addWidget(QLabel("rho:"), 1, 0) self.main_layout.addWidget(self.rho,1 , 1) self.main_layout.addWidget(QLabel("epsilon:"),2 ,0) self.main_layout.addWidget(self.epsilon,2, 1) self.setLayout(self.main_layout)
def _setupGui(self): for m in self._distModes: self._ui.comboBoxDistanceMode.addItem(m) self._ui.lineEditXTol.setValidator(QDoubleValidator()) self._ui.spinBoxPCsToFit.setSingleStep(1) self._ui.spinBoxSurfDisc.setSingleStep(1) self._ui.doubleSpinBoxMWeight.setSingleStep(0.1) self._ui.spinBoxMaxfev.setMaximum(10000) self._ui.spinBoxMaxfev.setSingleStep(100)
def __init__(self): super().__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) # Dialog Open self.dialog_open = DialogOpen() self.dialog_open.ui.buttonBox.button( QDialogButtonBox.Ok).clicked.connect(self.load) # Connect MainWindow view/controller to model self.model = Model() # Connect push buttons to slot functions self.ui.pbShowDialogOpen.clicked.connect(self.show_dialog_open) self.ui.pbExportFolder.clicked.connect(self.on_pbExportFolder_click) self.ui.pbExportTurns.clicked.connect(self.export_turns) self.ui.pbExportRoutes.clicked.connect(self.export_routes) self.ui.pbExportLinksAndTurnsByOD.clicked.connect( self.export_links_and_turns_by_od) self.ui.pbEstimateOD.clicked.connect(self.estimate_od) # Set numeric validators on objective function weight line inputs. double_validator = QDoubleValidator(bottom=0) double_validator.setNotation(QDoubleValidator.StandardNotation) self.ui.leWeightGEH.setValidator(double_validator) self.ui.leWeightODSSE.setValidator(double_validator) self.ui.leWeightRouteRatio.setValidator(double_validator) # set default weights self.ui.leWeightGEH.setText("1") self.ui.leWeightODSSE.setText("0") self.ui.leWeightRouteRatio.setText("1") # Setup graphics view self.schematic_scene = schematic_scene.SchematicScene() self.ui.gvSchematic.setScene(self.schematic_scene) self.ui.gvSchematic.setRenderHints(QPainter.Antialiasing) # Set table behaviors self.ui.tblOD.setSelectionBehavior(QAbstractItemView.SelectRows) self.ui.tblOD.setSelectionMode(QAbstractItemView.SingleSelection)
def Render(self, mdi): widget = QWidget() hbox = QHBoxLayout() self.table = self.RenderGuestsTable() grid = QGridLayout() grid.setMargin(20) grid.rowMinimumHeight(40) name_label = QLabel("Name") self.name_field = QLineEdit() last_name_label = QLabel("Last name") self.last_name_field = QLineEdit() age_label = QLabel("Age") self.age_field = QLineEdit() self.age_field.setValidator(QDoubleValidator(16, 100, 0)) card_label = QLabel("Has card") self.card_field = QLineEdit() grid.addWidget(name_label, 0, 0, 1, 0) grid.addWidget(self.name_field, 1, 0, 1, 0) grid.addWidget(last_name_label, 2, 0, 1, 0) grid.addWidget(self.last_name_field, 3, 0, 1, 0) grid.addWidget(age_label, 4, 0, 1, 0) grid.addWidget(self.age_field, 5, 0, 1, 0) grid.addWidget(card_label, 6, 0, 1, 0) grid.addWidget(self.card_field, 7, 0, 1, 0) delete_btn = QPushButton("Delete") delete_btn.clicked.connect(self.RemoveRow) save_btn = QPushButton("Save") save_btn.clicked.connect(self.SaveRow) grid.addWidget(delete_btn, 8, 0) grid.addWidget(save_btn, 8, 1) new_btn = QPushButton("New") new_btn.clicked.connect(self.NewRow) grid.addWidget(new_btn, 9, 0) filler = QSpacerItem(150, 10, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) grid.addItem(filler, 10, 0) hbox.addWidget(self.table) hbox.addLayout(grid) widget.setLayout(hbox) self.setWidget(widget) self.setWindowTitle("Guests") mdi.addSubWindow(self)
class NumericListValidator(QValidator): """ QValidator for space-separated list of numbers. Works with float or ints """ def __init__(self, float_int: type, parent=None): super().__init__(parent) if float_int is int: self.__numValidator = QIntValidator(self) elif float_int is float: self.__numValidator = QDoubleValidator(self) def validate(self, inputString: str, pos: int) -> QValidator.State: self.__numValidator.setLocale(QLocale(QLocale.English, QLocale.UnitedStates)) inputString = inputString.strip(' ') stringList: List[str] = inputString.split(' ') for string in stringList: if self.__numValidator.validate(string, 0)[0] == QValidator.Invalid: return QValidator.Invalid return QValidator.Acceptable
def __init__(self): self.view = View() self.model = Model() self.only_double = QDoubleValidator() self.today = QDate.currentDate() self.source_table = None self.last_reverse_entry_btn = None # for uncheck reversed entry button group self.settings = QWebEngineSettings.globalSettings() Thread(target=self.fil_upto_today, daemon=True).start() self.set_events() self.set_method_of_trans()
def Render(self, mdi): widget = QWidget() vbox = QHBoxLayout() self.table = self.RenderApartmentsTable() grid = QGridLayout() grid.setMargin(20) grid.rowMinimumHeight(40) name_label = QLabel("Name") self.name_field = QLineEdit() price_label = QLabel("Price") self.price_field = QLineEdit() self.price_field.setValidator(QDoubleValidator(0, 500, 2)) description_label = QLabel("Description") self.description_field = QLineEdit() grid.addWidget(name_label, 0, 0, 1, 0) grid.addWidget(self.name_field, 1, 0, 1, 0) grid.addWidget(price_label, 2, 0, 1, 0) grid.addWidget(self.price_field, 3, 0, 1, 0) grid.addWidget(description_label, 4, 0, 1, 0) grid.addWidget(self.description_field, 5, 0, 1, 0) new_btn = QPushButton("New") new_btn.clicked.connect(self.NewRow) grid.addWidget(new_btn, 6, 0) save_btn = QPushButton("Save") save_btn.clicked.connect(self.SaveRow) grid.addWidget(save_btn, 6, 1) delete_btn = QPushButton("Delete") delete_btn.clicked.connect(self.RemoveRow) grid.addWidget(delete_btn, 6, 2) filler = QSpacerItem(150, 10, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) grid.addItem(filler, 8, 0) vbox.addWidget(self.table) vbox.addLayout(grid) widget.setLayout(vbox) self.setWidget(widget) self.setWindowTitle("Apartments") mdi.addSubWindow(self)
def __init__(self, parent=None): QWidget.__init__(self) self.ui = Ui_Form() self.ui.setupUi(self) # Validator (line Edit 의 input 제한, setupUi 로 객체들을 만든다음에 코드로 수정) # Qt Designer 에는 수정 기능 없음 self.ui.lineEdit_int.setValidator(QIntValidator(self)) # 정수 self.ui.lineEdit_int.setValidator(QIntValidator( 100, 999, self)) # 100..999사이의 정수 self.ui.lineEdit_double.setValidator( QDoubleValidator(self)) # 실수, 1.2, -1.3, 1E-2 등 가능 self.ui.lineEdit_double.setValidator( QDoubleValidator(-0.1, 100, 2, self)) # -0.1, 100 사이의 실수, 2개의 소수자리수만 허용. validator = QDoubleValidator(self) # 0 이상 실수 validator.setBottom(0.) self.ui.lineEdit_over0.setValidator(validator) # 복잡한 패턴 제약 regExp = QRegExpValidator("[A-Za-z][1-9][0-9]{0,2}") # 첫 번째 문자는 대소문자의 알파벳이고, 두 번째는 1-9사이의 숫자가, # 이후 0-9사이의 숫자가 0개부터 2개까지 올 수 있도록 lineEdit의 입력을 제한한다는 의미이다. self.ui.lineEdit_combo.setValidator(QRegExpValidator(regExp, self)) """
def x_max_min_check(self, stringmin, stringmax): validation_rule = QDoubleValidator(-1000, 1000, 0) error = 0 if validation_rule.validate(self.equation_editorMax.text(), 14)[0] == QValidator.State.Invalid: self.textError.setText(" max x parameter is invalid ") error = 1 return error if validation_rule.validate(self.equation_editorMax.text(), 14)[0] == QValidator.State.Intermediate: self.textError.setText(" max x parameter is invalid ") error = 1 return error if validation_rule.validate(self.equation_editorMin.text(), 14)[0] == QValidator.State.Invalid: self.textError.setText(" min x parameter is invalid ") error = 1 return error if validation_rule.validate(self.equation_editorMin.text(), 14)[0] == QValidator.State.Intermediate: self.textError.setText(" min x parameter is invalid ") error = 1 return error if int(stringmin) > int(stringmax): self.textError.setText("error!min x is bigger than max x") error = 1 return error return error
def __init__(self): super().__init__() self.main_layout = QGridLayout() self.main_layout.setAlignment(Qt.AlignTop) self.learning_rate = QLineEdit("0.001") self.learning_rate.setValidator(QDoubleValidator(0., 1., 5)) self.learning_rate_power = QLineEdit("0.5") self.learning_rate_power.setValidator(QDoubleValidator(0., 1., 5)) self.initial_accumulator_value = QLineEdit("0.1") self.initial_accumulator_value.setValidator(QDoubleValidator(0., 1e-10, 10)) self.l1_regularization_strength = QLineEdit("0.0") self.l1_regularization_strength.setValidator(QDoubleValidator(0., 1e-10, 10)) self.l2_regularization_strength = QLineEdit("0.0") self.l2_regularization_strength.setValidator(QDoubleValidator(0., 1e-10, 10)) self.l2_shrinkage_regularization_strength = QLineEdit("0.0") self.l2_shrinkage_regularization_strength.setValidator(QDoubleValidator(0., 1e-10, 10)) self.main_layout.addWidget(QLabel("Learning rate:"), 0, 0) self.main_layout.addWidget(self.learning_rate, 0, 1) self.main_layout.addWidget(QLabel("Initial_accumulator_value:"),1 ,0) self.main_layout.addWidget(self.initial_accumulator_value,1, 1) self.main_layout.addWidget(QLabel("l1_regularization_strength"), 2, 0) self.main_layout.addWidget(self.l1_regularization_strength,2, 1) self.main_layout.addWidget(QLabel("l2_regularization_strength:"), 3, 0) self.main_layout.addWidget(self.l2_regularization_strength,3, 1) self.main_layout.addWidget(QLabel("l2_shrinkage_regularization_strength"), 4, 0) self.main_layout.addWidget(self.l2_shrinkage_regularization_strength, 4 , 1) self.setLayout(self.main_layout)
def Render(self, mdi): widget = QWidget() vbox = QHBoxLayout() self.table = self.RenderGuestsTable() grid = QGridLayout() grid.setMargin(20) grid.rowMinimumHeight(40) name_label = QLabel("Name") self.name_field = QLineEdit() age_label = QLabel("Age") self.age_field = QLineEdit() self.age_field.setValidator(QDoubleValidator(0, 100, 2)) self.card_chekboks = QCheckBox("Is Card") self.card_chekboks.stateChanged.connect(self.is_card_change) grid.addWidget(name_label, 0, 0, 1, 0) grid.addWidget(self.name_field, 1, 0, 1, 0) grid.addWidget(age_label, 2, 0, 1, 0) grid.addWidget(self.age_field, 3, 0, 1, 0) grid.addWidget(self.card_chekboks, 5, 0, 1, 0) new_btn = QPushButton("New") new_btn.clicked.connect(self.NewRow) grid.addWidget(new_btn, 6, 0) save_btn = QPushButton("Save") save_btn.clicked.connect(self.SaveRow) grid.addWidget(save_btn, 6, 1) delete_btn = QPushButton("Delete") delete_btn.clicked.connect(self.RemoveRow) grid.addWidget(delete_btn, 6, 2) filler = QSpacerItem(150, 10, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding) grid.addItem(filler, 8, 0) vbox.addWidget(self.table) vbox.addLayout(grid) widget.setLayout(vbox) self.setWidget(widget) self.setWindowTitle("Guests") mdi.addSubWindow(self)
def createEditor(self, parent): """ Creates a QLineEdit instance for GUI editing of integer values :param parent: the parent of the widget :return: a QLineEdit instance """ res = QLineEdit(parent) v = QDoubleValidator() # QDoubleValidator seems to have a very strange behaviour when bottom and/or top values are set. # Therefore, we don't use this feature and rely on our own implementation. res.setValidator(v) res.setFrame(False) return res
def __init__(self, plugin_manager): super(SummaryWidget, self).__init__() self.plugin_manager = plugin_manager icon_path = os.path.join(c.ICON_PATH, "neutral", "quote.png") self.setWindowIcon(QIcon(icon_path)) self.setWindowTitle("Summary") self.settings = QSettings(c.SETTINGS_PATH, QSettings.IniFormat) self.font = QFont(self.settings.value(c.FONT, defaultValue="Arial", type=str)) self.font.setPointSize(12) self.summary_text = QPlainTextEdit() self.summary_text.setReadOnly(True) self.summary_text.setFont(self.font) self.refresh_btn = QPushButton("Refresh") self.refresh_btn.clicked.connect(self.get_summary) self.threshold_value = 1.2 self.threshold = QLineEdit(str(self.threshold_value)) self.threshold.setFixedSize(40, 25) self.validator = QDoubleValidator() self.validator.setLocale(QLocale.English) self.threshold.setValidator(self.validator) self.threshold.textChanged.connect(self.threshold_changed) self.h_box = QHBoxLayout() self.h_box.addWidget(self.refresh_btn) self.h_box.addWidget(self.threshold) self.v_box = QVBoxLayout() self.v_box.addWidget(self.summary_text) self.v_box.addLayout(self.h_box) self.setLayout(self.v_box) self.resize(500, 500)
def __init__(self, parent=None, double_only=False, int_only=False, fixed=False, comma_sort=False): super().__init__(parent) self.__type = Types.TEXT self._double_only = double_only self._int_only = int_only if self._double_only: self.setValidator(QDoubleValidator()) self.__type = Types.NUMBER elif self._int_only: self.setValidator(QIntValidator()) self.__type = Types.INTEGER if fixed: self.setFixedWidth(250) self._comma_sort = comma_sort self.setMaximumWidth(250)
def __init__( self, #parent = None, min=0, max=100): # super().__init__(parent) super().__init__() self.validator = QDoubleValidator() self.min = min self.max = max self.line_edit.setValidator(self.validator) self.slider.valueChanged.connect( lambda: self._on_slider_moved(self.slider.value())) self.line_edit.editingFinished.connect( lambda: self._on_edit_finished(self.line_edit.text()))
def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) self.mplWidget = MplWidget.warp_a_widget(self.matplotlibWidget) self.model = DataModel(self.mplWidget.canvas) self.tableView.setModel(self.model) validator = QDoubleValidator(0, 1000, 5) self.leastIntLineEdit.setValidator(validator) self.maxZDiffLineEdit.setValidator(validator) self.leastIntLineEdit.setText('200') self.maxZDiffLineEdit.setText('1') # Signals-Slots self.actionImportData.triggered.connect(self.setSampleFile) self.startFindButton.clicked.connect(self.startSearch)
def __init__(self, parent=None, cutoff_value=0.01, limit_type="percent"): super().__init__(parent) self.cutoff_value = cutoff_value self.limit_type = limit_type locale = QLocale(QLocale.English, QLocale.UnitedStates) locale.setNumberOptions(QLocale.RejectGroupSeparator) self.validators = Types(QDoubleValidator(0.001, 100.0, 1, self), QIntValidator(0, 50, self)) self.validators.relative.setLocale(locale) self.validators.topx.setLocale(locale) self.buttons = Types(QRadioButton("Relative"), QRadioButton("Top #")) self.buttons.relative.setChecked(True) self.buttons.relative.setToolTip( "This cut-off type shows the selected top percentage of contributions (for example the \ top 10% contributors)") self.buttons.topx.setToolTip( "This cut-off type shows the selected top number of contributions (for example the top \ 5 contributors)") self.button_group = QButtonGroup() self.button_group.addButton(self.buttons.relative, 0) self.button_group.addButton(self.buttons.topx, 1) self.sliders = Types(LogarithmicSlider(self), QSlider(Qt.Horizontal, self)) self.sliders.relative.setToolTip( "This slider sets the selected percentage of contributions\ to be shown") self.sliders.topx.setToolTip( "This slider sets the selected number of contributions to be \ shown") self.units = Types("% of total", "top #") self.labels = Labels(QLabel(), QLabel(), QLabel()) self.cutoff_slider_line = QLineEdit() self.cutoff_slider_line.setToolTip( "This box can set a precise cut-off value for the \ contributions to be shown") self.cutoff_slider_line.setLocale(locale) self.cutoff_slider_lft_btn = QPushButton("<") self.cutoff_slider_lft_btn.setToolTip( "This button moves the cut-off value one increment") self.cutoff_slider_rght_btn = QPushButton(">") self.cutoff_slider_rght_btn.setToolTip( "This button moves the cut-off value one increment") self.make_layout() self.connect_signals()
class ControlFloat(ControlText): _line_edit_validator = QDoubleValidator() def __init__(self, *args, **kwargs): self._factor = kwargs.pop("factor", 1) super().__init__(*args, **kwargs) @property def value(self): return _str2float(self.control.text()) * self._factor @value.setter def value(self, value): self.control.setText( str(_str2float(value) / self._factor) )
def __init__(self, *a, bottom: float = None, top: float = None, decimals: int = None, **kw): """ Line edit for float. Automates type conversion and includes a Validator. Parameters `bottom`, `top` and `decimals` are used to setup the validator. All other parameters are forwarded to QLineEdit. """ super().__init__(*a, **kw) self.setValidator(QDoubleValidator()) if bottom is not None: self.validator().setBottom(bottom) if top is not None: self.validator().setTop(top) if decimals is not None: self.validator().setDecimals(decimals)
def _float_field( self, min_val: float = 0.0, max_val: float = 1.0, decimals: int = 1, placeholder: str = "", tooltip: str = "", ) -> QLineEdit: result = QLineEdit() # TODO derive the max width from the text repr of min_val, max_val. result.setMaximumWidth(self._FIELD_WIDTH) result.setAlignment(Qt.AlignRight) validator = QDoubleValidator(min_val, max_val, decimals) result.setValidator(validator) if placeholder: result.setPlaceholderText(placeholder) if tooltip: result.setToolTip(tooltip) return result