當前位置: 首頁>>代碼示例>>Python>>正文


Python QLineEdit.value方法代碼示例

本文整理匯總了Python中PyQt5.QtWidgets.QLineEdit.value方法的典型用法代碼示例。如果您正苦於以下問題:Python QLineEdit.value方法的具體用法?Python QLineEdit.value怎麽用?Python QLineEdit.value使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyQt5.QtWidgets.QLineEdit的用法示例。


在下文中一共展示了QLineEdit.value方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import value [as 別名]
    def __init__(self, var_info, initial_values, title="Set Variables:", parent=None):
        super(VariableSetterDialog, self).__init__(parent)

        assert len(var_info) == len(initial_values)

        self.setWindowTitle(title)

        layout = QVBoxLayout(self)

        self.value_holders = []

        for i in range(len(var_info)):
            info_dictionary = var_info[i]
            assert isinstance(info_dictionary, dict)
            h_layout = QHBoxLayout()
            h_layout.addWidget(QLabel(info_dictionary["description"]))
            if info_dictionary["type"] == "int":
                spin_box = QSpinBox()
                spin_box.setMinimum(info_dictionary["min"])
                spin_box.setMaximum(info_dictionary["max"])
                if info_dictionary.has_key("step"):
                    spin_box.setSingleStep(info_dictionary["step"])
                if info_dictionary.has_key("max width"):
                    spin_box.setMaximumWidth(info_dictionary["max width"])
                spin_box.setValue(initial_values[i])
                self.value_holders.append(spin_box)
                h_layout.addWidget(spin_box)
                layout.addLayout(h_layout)
            elif info_dictionary["type"] == "float":
                spin_box = QDoubleSpinBox()
                spin_box.setMinimum(info_dictionary["min"])
                spin_box.setMaximum(info_dictionary["max"])
                if info_dictionary.has_key("step"):
                    spin_box.setSingleStep(info_dictionary["step"])
                if info_dictionary.has_key("decimals"):
                    spin_box.setDecimals(info_dictionary["decimals"])
                if info_dictionary.has_key("max width"):
                    spin_box.setMaximumWidth(info_dictionary["max width"])
                spin_box.setValue(initial_values[i])
                self.value_holders.append(spin_box)
                h_layout.addWidget(spin_box)
                layout.addLayout(h_layout)
            elif info_dictionary["type"] == "string":
                line_edit = QLineEdit()
                if info_dictionary.has_key("max length"):
                    line_edit.setMaxLength(info_dictionary["max length"])
                if info_dictionary.has_key("max width"):
                    line_edit.setMaximumWidth(info_dictionary["max width"])
                if info_dictionary.has_key("max width"):
                    line_edit.setMaximumWidth(info_dictionary["max width"])
                line_edit.setText(initial_values[i])
                line_edit.value = line_edit.text
                self.value_holders.append(line_edit)
                h_layout.addWidget(line_edit)
                layout.addLayout(h_layout)
            elif info_dictionary["type"] == "combo":
                combo_box = QComboBox()
                combo_box.addItems(info_dictionary["options"])

                if info_dictionary.has_key("max width"):
                    combo_box.setMaximumWidth(info_dictionary["max width"])
                combo_box.setCurrentText(initial_values[i])
                combo_box.value = combo_box.currentText
                self.value_holders.append(combo_box)
                h_layout.addWidget(combo_box)
                layout.addLayout(h_layout)
            elif info_dictionary["type"] == "color":
                swatch = ColorSwatchWidget(initial_values[i])
                self.value_holders.append(swatch)
                h_layout.addWidget(swatch)
                layout.addLayout(h_layout)

        # OK and Cancel buttons
        self.buttons = QDialogButtonBox(
            QDialogButtonBox.Ok | QDialogButtonBox.Cancel,
            Qt.Horizontal, self)
        layout.addWidget(self.buttons)

        self.buttons.accepted.connect(self.accept)
        self.buttons.rejected.connect(self.reject)
開發者ID:MarcTheSpark,項目名稱:marcpy,代碼行數:82,代碼來源:dialogs.py

示例2: ConfigParamEditWindow

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import value [as 別名]
class ConfigParamEditWindow(QDialog):
    def __init__(self, parent, model, cli_iface, store_callback):
        super(ConfigParamEditWindow, self).__init__(parent)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self.setWindowTitle('Edit Parameter')
        self.setModal(True)

        self._model = model
        self._cli_iface = cli_iface
        self._store_callback = store_callback

        name_label = QLabel(model.name, self)
        name_label.setFont(get_monospace_font())

        if model.type is bool:
            self._value = QCheckBox(self)
            self._value.setChecked(model.value)
        elif model.type is int:
            self._value = QSpinBox(self)
            if model.minimum is not None:
                self._value.setRange(model.minimum,
                                     model.maximum)
            else:
                self._value.setRange(-0x80000000,
                                     +0x7FFFFFFF)
            self._value.setValue(model.value)
        elif model.type is float:
            self._value = QDoubleSpinBox(self)
            if model.minimum is not None:
                self._value.setRange(model.minimum,
                                     model.maximum)
            else:
                self._value.setRange(-3.4028235e+38,
                                     +3.4028235e+38)
            self._value.setValue(model.value)
        elif model.type is str:
            self._value = QLineEdit(self)
            self._value.setText(model.value)
        else:
            raise ValueError('Unsupported value type %r' % model.type)

        self._ok_button = make_icon_button('check', 'Send changes to the device', self,
                                           text='OK', on_clicked=self._do_ok)

        self._cancel_button = make_icon_button('remove', 'Discard changes and close this window', self,
                                               text='Cancel', on_clicked=self.close)

        layout = QVBoxLayout(self)

        value_layout = QHBoxLayout(self)
        value_layout.addWidget(name_label)
        value_layout.addWidget(self._value, 1)

        controls_layout = QHBoxLayout(self)
        controls_layout.addWidget(self._cancel_button)
        controls_layout.addWidget(self._ok_button)

        layout.addLayout(value_layout)
        layout.addLayout(controls_layout)
        self.setLayout(layout)

    def _do_ok(self):
        if self._model.type is bool:
            value = self._value.isChecked()
        elif self._model.type is int or self._model.type is float:
            value = self._value.value()
        else:
            value = self._value.text()

        self._store_callback(value)
        self.close()
開發者ID:UAVCAN,項目名稱:gui_tool,代碼行數:73,代碼來源:slcan_cli.py

示例3: ConfigParamEditWindow

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import value [as 別名]
class ConfigParamEditWindow(QDialog):
    def __init__(self, parent, node, target_node_id, param_struct, update_callback):
        super(ConfigParamEditWindow, self).__init__(parent)
        self.setWindowTitle("Edit configuration parameter")
        self.setModal(True)

        self._node = node
        self._target_node_id = target_node_id
        self._param_struct = param_struct
        self._update_callback = update_callback

        min_val = get_union_value(param_struct.min_value)
        if "uavcan.protocol.param.Empty" in str(min_val):
            min_val = None

        max_val = get_union_value(param_struct.max_value)
        if "uavcan.protocol.param.Empty" in str(max_val):
            max_val = None

        value = get_union_value(param_struct.value)
        self._value_widget = None
        value_type = uavcan.get_active_union_field(param_struct.value)

        if value_type == "integer_value":
            min_val = min_val if min_val is not None else -0x8000000000000000
            max_val = max_val if max_val is not None else 0x7FFFFFFFFFFFFFFF
            if min_val >= -0x80000000 and max_val <= +0x7FFFFFFF:
                self._value_widget = QSpinBox(self)
                self._value_widget.setMaximum(max_val)
                self._value_widget.setMinimum(min_val)
                self._value_widget.setValue(value)
        if value_type == "real_value":
            min_val = round_float(min_val) if min_val is not None else -3.4028235e38
            max_val = round_float(max_val) if max_val is not None else 3.4028235e38
            value = round_float(value)
        if value_type == "boolean_value":
            self._value_widget = QCheckBox(self)
            self._value_widget.setChecked(bool(value))

        if self._value_widget is None:
            self._value_widget = QLineEdit(self)
            self._value_widget.setText(str(value))
        self._value_widget.setFont(get_monospace_font())

        layout = QGridLayout(self)

        def add_const_field(label, *values):
            row = layout.rowCount()
            layout.addWidget(QLabel(label, self), row, 0)
            if len(values) == 1:
                layout.addWidget(FieldValueWidget(self, values[0]), row, 1)
            else:
                sub_layout = QHBoxLayout(self)
                for idx, v in enumerate(values):
                    sub_layout.addWidget(FieldValueWidget(self, v))
                layout.addLayout(sub_layout, row, 1)

        add_const_field("Name", param_struct.name)
        add_const_field("Type", uavcan.get_active_union_field(param_struct.value).replace("_value", ""))
        add_const_field("Min/Max", min_val, max_val)
        add_const_field("Default", render_union(param_struct.default_value))

        layout.addWidget(QLabel("Value", self), layout.rowCount(), 0)
        layout.addWidget(self._value_widget, layout.rowCount() - 1, 1)

        fetch_button = make_icon_button(
            "refresh", "Read parameter from the node", self, text="Fetch", on_clicked=self._do_fetch
        )
        set_default_button = make_icon_button(
            "fire-extinguisher", "Restore default value", self, text="Restore", on_clicked=self._restore_default
        )
        send_button = make_icon_button(
            "flash", "Send parameter to the node", self, text="Send", on_clicked=self._do_send
        )
        cancel_button = make_icon_button(
            "remove", "Close this window; unsent changes will be lost", self, text="Cancel", on_clicked=self.close
        )

        controls_layout = QGridLayout(self)
        controls_layout.addWidget(fetch_button, 0, 0)
        controls_layout.addWidget(send_button, 0, 1)
        controls_layout.addWidget(set_default_button, 1, 0)
        controls_layout.addWidget(cancel_button, 1, 1)
        layout.addLayout(controls_layout, layout.rowCount(), 0, 1, 2)

        self._status_bar = QStatusBar(self)
        self._status_bar.setSizeGripEnabled(False)
        layout.addWidget(self._status_bar, layout.rowCount(), 0, 1, 2)

        left, top, right, bottom = layout.getContentsMargins()
        bottom = 0
        layout.setContentsMargins(left, top, right, bottom)

        self.setLayout(layout)

    def show_message(self, text, *fmt):
        self._status_bar.showMessage(text % fmt)

    def _assign(self, value_union):
        value = get_union_value(value_union)
#.........這裏部分代碼省略.........
開發者ID:UAVCAN,項目名稱:gui_tool,代碼行數:103,代碼來源:node_properties.py


注:本文中的PyQt5.QtWidgets.QLineEdit.value方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。