Пример #1
0
 def add_custom(
     self,
     label: str = "Other",
     typ: TypeStr = "string",
     default: None | float | str = None,
     regex: str | None = None,
 ):
     if typ == "string":
         self.widget_custom = widgets.LineEdit()
     elif typ == "int":
         self.widget_custom = widgets.SpinBox()
     elif typ == "float":
         self.widget_custom = widgets.DoubleSpinBox()
     else:
         raise ValueError(typ)
     # TODO: Enable this or add BAR radio and option.
     self.widget_custom.set_disabled()  # type: ignore
     if default is not None:
         self.widget_custom.set_value(default)  # type: ignore
     self.rb_other.setText(label)
     self.rb_other.toggled.connect(
         self.widget_custom.set_enabled)  # type: ignore
     self.widget_custom.value_changed.connect(  # type: ignore
         lambda: self.update_choice(True))
     if regex and typ == "string":
         self.widget_custom.set_regex_validator(regex)  # type: ignore
     layout = widgets.BoxLayout("horizontal")
     layout.add(self.rb_other)
     layout.add(self.widget_custom)
     self.box.add(layout)
Пример #2
0
 def add_custom(self, regex):
     self.lineedit_custom_sep = widgets.LineEdit(self)
     # TODO: Enable this or add BAR radio and option.
     self.lineedit_custom_sep.setEnabled(False)
     self.rb_other.toggled.connect(self.lineedit_custom_sep.setEnabled)
     self.lineedit_custom_sep.textChanged.connect(lambda: self.update_choice(True))
     self.lineedit_custom_sep.set_regex_validator(regex)
     self.layout.addWidget(self.rb_other)
     self.layout.addWidget(self.lineedit_custom_sep)
Пример #3
0
 def __init__(self, label, value=None, notempty=False, regex=None):
     super().__init__(label, value=value)
     self.widget = widgets.LineEdit()
     if notempty:
         val = custom_validators.NotEmptyValidator()
         self.widget.set_validator(val)
     if regex is not None:
         val = gui.RegExpValidator()
         val.set_regex(regex)
         self.widget.set_validator(val)
     if value is not None:
         self.widget.set_value(value)
Пример #4
0
def test_lineedit():
    widget = widgets.LineEdit("Test")
    widget.set_regex_validator("[0-9]")
    widget.set_font("Consolas")
    widget.set_text("0")
    widget.append_text("a")
    widget.set_echo_mode("password")
    widget.set_input_mask("X")
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
Пример #5
0
 def _create_widget(self) -> widgets.LineEdit:
     widget = widgets.LineEdit()
     if self.notempty:
         val = custom_validators.NotEmptyValidator()
         widget.set_validator(val)
     if self.regex is not None:
         val = gui.RegularExpressionValidator()
         val.set_regex(self.regex)
         widget.set_validator(val)
     if self.value is not None:
         widget.set_value(self.value)
     return widget
Пример #6
0
 def add_custom(self, label: str = "Other", regex: Optional[str] = None):
     self.lineedit_custom_sep = widgets.LineEdit()
     # TODO: Enable this or add BAR radio and option.
     self.lineedit_custom_sep.set_disabled()
     self.rb_other.setText(label)
     self.rb_other.toggled.connect(self.lineedit_custom_sep.set_enabled)
     self.lineedit_custom_sep.textChanged.connect(
         lambda: self.update_choice(True))
     if regex:
         self.lineedit_custom_sep.set_regex_validator(regex)
     self.box += self.rb_other
     self.box += self.lineedit_custom_sep
Пример #7
0
 def __init__(self, font=None, parent=None):
     super().__init__(parent)
     self.current_font = font
     layout = widgets.BoxLayout("horizontal", self)
     layout.set_margin(0)
     self.lineedit = widgets.LineEdit()
     self.lineedit.set_read_only()
     layout += self.lineedit
     action = widgets.Action()
     action.triggered.connect(self.choose_font)
     self.button = widgets.ToolButton()
     self.button.setDefaultAction(action)
     layout += self.button
Пример #8
0
 def __init__(self, color=None, parent=None):
     super().__init__(parent)
     layout = widgets.BoxLayout("horizontal", self)
     layout.set_margin(0)
     self.lineedit = widgets.LineEdit()
     self.lineedit.set_regex_validator(r"^#(?:[0-9a-fA-F]{6})$")
     layout += self.lineedit
     action = widgets.Action(icon="mdi.format-color-fill")
     action.triggered.connect(self.choose_color)
     self.button = widgets.ToolButton()
     self.button.setDefaultAction(action)
     layout += self.button
     if color is not None:
         self.set_color(color)
Пример #9
0
    def __init__(self, extensions=None, mode="save", parent=None):
        super().__init__(parent)
        self.path = None
        self.extensions = extensions
        self.mode = mode
        layout = widgets.BoxLayout("horizontal", self)
        layout.set_margin(0)
        self.lineedit = widgets.LineEdit()
        self.lineedit.set_read_only()
        layout += self.lineedit
        action = widgets.Action()
        action.set_icon("mdi.file-outline")
        action.triggered.connect(self.open_file)

        self.button = widgets.ToolButton()
        self.button.setDefaultAction(action)
        layout += self.button
Пример #10
0
 def __init__(
     self, color: types.ColorType = None, parent: QtWidgets.QWidget | None = None
 ):
     super().__init__(parent)
     layout = widgets.BoxLayout("horizontal", self)
     layout.set_margin(0)
     self.lineedit = widgets.LineEdit()
     self.lineedit.set_regex_validator(r"^#(?:[0-9a-fA-F]{6})$")
     layout.add(self.lineedit)
     action = widgets.Action(icon="mdi.format-color-fill")
     action.triggered.connect(self.choose_color)
     self.button = widgets.ToolButton()
     self.button.setDefaultAction(action)
     layout.add(self.button)
     self._current_color: gui.Color = gui.Color("white")
     if color is not None:
         self.set_current_color(color)
Пример #11
0
def test_lineedit():
    widget = widgets.LineEdit("Test")
    widget.set_regex_validator("[0-9]")
    widget.set_font("Consolas")
    widget.set_text("0")
    widget.append_text("a")
    widget.set_echo_mode("password")
    with pytest.raises(ValueError):
        widget.set_echo_mode("test")
    assert widget.get_echo_mode() == "password"
    widget.set_input_mask("X")
    with open("data.pkl", "wb") as jar:
        pickle.dump(widget, jar)
    with open("data.pkl", "rb") as jar:
        widget = pickle.load(jar)
    repr(widget)
    widget.set_range(0, 10)
    widget.set_value("5")
    widget += "append"
Пример #12
0
    def __init__(
        self,
        extensions: dict[str, list[str]] | None = None,
        mode: widgets.filedialog.AcceptModeStr = "save",
        file_mode: widgets.filedialog.FileModeStr = "existing_files",
        root: None | str | pathlib.Path = None,
        parent: QtWidgets.QWidget | None = None,
    ):
        """Initialize FileChooserButton.

        Args:
            extensions: dict allowed extensions
                        form: "'name': ['.ext1', '.ext2']"
            mode: Accept mode ("save" or "load")
            file_mode: File mode ("existing_files", "existing_file", "any_file",
                                  or "directory")
            root: Root path
            parent: parent widget
        """
        super().__init__(parent)
        self.path: pathlib.Path | None = None
        self.extensions = extensions
        self.mode: widgets.filedialog.AcceptModeStr = mode
        self.file_mode: widgets.filedialog.FileModeStr = file_mode
        self.root = root
        layout = widgets.BoxLayout("horizontal", self)
        layout.set_margin(0)
        self.lineedit = widgets.LineEdit()
        self.lineedit.set_read_only()
        layout.add(self.lineedit)
        action = widgets.Action()
        if self.file_mode == "directory":
            action.set_icon("mdi.folder-outline")
        else:
            action.set_icon("mdi.file-outline")
        action.triggered.connect(self.open_file)

        self.button = widgets.ToolButton()
        self.button.setDefaultAction(action)
        layout.add(self.button)
Пример #13
0
 def __init__(self, parent: QtWidgets.QWidget | None = None):
     super().__init__(parent)
     layout = widgets.BoxLayout("horizontal")
     row_nb = 14
     cindex = 0
     for k, v in widgets.style.STANDARD_PIXMAP.items():
         if cindex == 0:
             col_layout = widgets.BoxLayout("vertical")
         icon_layout = widgets.BoxLayout("horizontal")
         icon = widgets.Application.get_style_icon(k)
         label = widgets.Label()
         label.setPixmap(icon.pixmap(32, 32))
         icon_layout.addWidget(label)
         icon_layout.addWidget(widgets.LineEdit(k))
         col_layout.addLayout(icon_layout)
         cindex = (cindex + 1) % row_nb
         if cindex == 0:
             layout.addLayout(col_layout)
     self.set_layout(layout)
     self.set_title("Standard Platform Icons")
     icon = widgets.Application.get_style_icon("titlebar_menu_button")
     self.set_icon(icon)
Пример #14
0
 def __init__(self,
              title: str = "",
              parent: QtWidgets.QWidget | None = None):
     super().__init__(checkable=False, title=title)
     self.set_layout("vertical")
     self.rb_lineedit = widgets.RadioButton("String")
     self.lineedit = widgets.LineEdit()
     self.rb_spinbox = widgets.RadioButton("Number")
     self.spinbox = widgets.DoubleSpinBox()
     layout_lineedit = widgets.BoxLayout("horizontal")
     layout_lineedit.add(self.rb_lineedit)
     layout_lineedit.add(self.lineedit)
     layout_spinbox = widgets.BoxLayout("horizontal")
     layout_spinbox.add(self.rb_spinbox)
     layout_spinbox.add(self.spinbox)
     self.box.add(layout_lineedit)
     self.box.add(layout_spinbox)
     self.rb_spinbox.toggled.connect(self.spinbox.setEnabled)
     self.rb_spinbox.toggled.connect(self.lineedit.setDisabled)
     self.rb_lineedit.toggled.connect(self.lineedit.setEnabled)
     self.rb_lineedit.toggled.connect(self.spinbox.setDisabled)
     self.spinbox.value_changed.connect(self.on_value_change)
     self.lineedit.value_changed.connect(self.on_value_change)
     self.rb_lineedit.setChecked(True)
Пример #15
0
    def __eq__(self, other: object):
        if not isinstance(other, type(self)):
            return False
        return self.validators == other.validators

    def validate(  # type: ignore
            self,
            text: str,
            pos: int = 0) -> tuple[QtGui.QValidator.State, str, int]:
        vals = [v.validate(text, pos)[0]
                for v in self.validators]  # type: ignore
        if self.State.Invalid in vals:
            return self.State.Invalid, text, pos
        elif self.State.Intermediate in vals:
            return self.State.Intermediate, text, pos
        else:
            return self.State.Acceptable, text, pos


if __name__ == "__main__":
    from prettyqt import custom_validators, widgets

    val1 = custom_validators.NotEmptyValidator()
    val2 = custom_validators.PathValidator()
    val = CompositeValidator([val1, val2])
    app = widgets.app()
    widget = widgets.LineEdit("This is a test")
    widget.setValidator(val)
    widget.show()
    app.main_loop()
Пример #16
0
 def __init__(self, label, default=None, notempty=None,
              regex=None):
     super().__init__(label, default=default)
     self.widget = widgets.LineEdit()
     if default is not None:
         self.widget.set_value(default)
Пример #17
0
    def __init__(self):
        super().__init__()
        self.setMinimumSize(400, 300)
        self.set_title("Icon Browser")
        from prettyqt import iconprovider

        iconprovider._instance()
        font_maps = iconprovider._instance().charmap

        icon_names = [
            f"{font_collection}.{icon_name}"
            for font_collection, font_data in font_maps.items()
            for icon_name in font_data
        ]
        self._filter_timer = core.Timer(self)
        self._filter_timer.setSingleShot(True)
        self._filter_timer.setInterval(AUTO_SEARCH_TIMEOUT)
        self._filter_timer.timeout.connect(self._update_filter)

        model = IconModel(self.get_palette().get_color("text"))
        model.setStringList(sorted(icon_names))

        self._proxy_model = core.SortFilterProxyModel()
        self._proxy_model.setSourceModel(model)
        self._proxy_model.set_filter_case_sensitive(True)

        self._listview = IconListView(self)
        self._listview.setUniformItemSizes(True)
        self._listview.set_view_mode("icon")
        self._listview.set_model(self._proxy_model)
        self._listview.set_contextmenu_policy("custom")
        self._listview.doubleClicked.connect(self._copy_icon_text)

        self._lineedit = widgets.LineEdit(parent=self)
        self._lineedit.textChanged.connect(self._filter_timer.restart)
        self._lineedit.returnPressed.connect(self._trigger_instant_update)

        self._combobox = widgets.ComboBox(parent=self)
        self._combobox.setMinimumWidth(75)
        self._combobox.currentIndexChanged.connect(
            self._trigger_instant_update)
        self._combobox.addItems([ALL_COLLECTIONS] + sorted(font_maps.keys()))

        lyt = widgets.BoxLayout("horizontal")
        lyt.set_margin(0)
        lyt.add(self._combobox)
        lyt.add(self._lineedit)

        search_bar_frame = widgets.Frame(self)
        search_bar_frame.setLayout(lyt)

        self._copy_button = widgets.PushButton("Copy Name", self)
        self._copy_button.clicked.connect(self._copy_icon_text)

        lyt = widgets.BoxLayout("vertical")
        lyt.add(search_bar_frame)
        lyt.add(self._listview)
        lyt.add(self._copy_button)
        frame = widgets.Frame(self)
        frame.set_layout(lyt)
        self.setCentralWidget(frame)
        widgets.Shortcut(gui.KeySequence("return"), self, self._copy_icon_text)
        self._lineedit.setFocus()
        self.center()
Пример #18
0
            text: str,
            pos: int = 0) -> tuple[QtGui.QValidator.State, str, int]:
        # if text == "":
        #     self.compiled = None
        #     return (self.Intermediate, text, pos)
        try:
            compiled = re.compile(text)
        except sre_constants.error as e:
            self.error_occured.emit(str(e))
            self.pattern_updated.emit(None)
            return self.State.Intermediate, text, pos
        except re._regex_core.error as e:
            self.error_occured.emit(str(e))
            self.pattern_updated.emit(None)
            return self.State.Intermediate, text, pos
        else:
            self.error_occured.emit("")
            self.pattern_updated.emit(compiled)
            return self.State.Acceptable, text, pos


if __name__ == "__main__":
    from prettyqt import widgets

    app = widgets.app()
    w = widgets.LineEdit()
    val = RegexPatternValidator()
    w.set_validator(val)
    w.show()
    app.main_loop()
Пример #19
0
 def __init__(
     self,
     title: str = "Regex Editor",
     regex: str = "",
     teststring: str = "",
     parent: QtWidgets.QWidget | None = None,
 ):
     super().__init__(parent)
     self.resize(1200, 800)
     self.set_title(title)
     self.set_icon("mdi.regex")
     self.set_layout("horizontal")
     self.left_layout = widgets.BoxLayout("vertical")
     self.right_layout = widgets.BoxLayout("vertical")
     self.prog: Pattern | None = None
     self.matches: list[Match] = list()
     self.groupbox = widgets.GroupBox(title="Regular expression")
     self.grid = widgets.GridLayout(self.groupbox)
     self.layout_toprow = widgets.BoxLayout("horizontal")
     self.regexinput = custom_widgets.RegexInput()
     self.regexinput.set_min_size(400, 0)
     self.layout_toprow.add(self.regexinput)
     self.grid.add(self.layout_toprow, 1, 0)
     self.left_layout.add(self.groupbox)
     self.groupbox_teststring = widgets.GroupBox(title="Test strings")
     self.groupbox_teststring.set_layout("grid")
     self.textedit_teststring = widgets.PlainTextEdit(teststring)
     self.textedit_teststring.set_min_size(400, 0)
     self.groupbox_teststring.box.add(self.textedit_teststring, 0, 0)
     self.label_num_matches = widgets.Label("No match")
     self.label_num_matches.set_alignment("center")
     self.left_layout.add(self.groupbox_teststring)
     self.groupbox_sub = widgets.GroupBox(title="Substitution", checkable=True)
     self.layout_sub = widgets.GridLayout(self.groupbox_sub)
     self.lineedit_sub = widgets.LineEdit()
     self.lineedit_sub.textChanged.connect(self.update_sub_textedit)
     self.textedit_sub = widgets.PlainTextEdit()
     self.textedit_sub.set_min_size(400, 0)
     self.textedit_sub.set_read_only()
     self.layout_sub.add(self.lineedit_sub, 0, 0)
     self.layout_sub.add(self.textedit_sub, 1, 0)
     self.left_layout.add(self.groupbox_sub)
     self.cb_quickref = widgets.CheckBox("Show Regular Expression Quick Reference")
     self.left_layout.add(self.cb_quickref)
     self.table_matches = widgets.TableView()
     self.table_matches.setup_list_style()
     self.box.add(self.left_layout)
     self.box.add(self.right_layout)
     self.right_layout.add(self.label_num_matches)
     self.right_layout.add(self.table_matches)
     model = custom_models.RegexMatchesModel()
     self.table_matches.set_model(model)
     self.table_matches.setColumnWidth(0, 60)
     self.table_matches.setColumnWidth(1, 60)
     self.groupbox_sub.toggled.connect(self.lineedit_sub.setVisible)
     self.groupbox_sub.toggled.connect(self.textedit_sub.setVisible)
     doc = self.textedit_teststring.document()
     self._highlighter = RegexMatchHighlighter(doc)
     self._highlighter.rehighlight()
     self.cb_quickref.stateChanged.connect(self.quick_ref_requested)
     self.regexinput.value_changed.connect(self._update_view)
     self.textedit_teststring.textChanged.connect(self._update_view)
     self.regexinput.pattern = regex
     self._update_view()
Пример #20
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self.setLineEdit(widgets.LineEdit())
     self.setGroupSeparatorShown(True)
Пример #21
0
def test_lineedit():
    widget = widgets.LineEdit("Test")
    widget.set_regex_validator("[0-9]")
    widget.show()
    widget.close()
Пример #22
0
        Possible values: "north", "south", "west", "east"

        Returns:
            tab position
        """
        return TAB_POSITIONS.inv[self.tabPosition()]

    def set_background(self, bg_color):
        if isinstance(bg_color, str):
            bg_color = gui.Brush(gui.Color("black"))
        self.setBackground(bg_color)

    def add(self, item: QtWidgets.QWidget):
        if not isinstance(item, QtWidgets.QMdiSubWindow):
            widget = widgets.MdiSubWindow()
            widget.setWidget(item)
            self.addSubWindow(widget)
        else:
            self.addSubWindow(item)


if __name__ == "__main__":
    app = widgets.app()
    widget = MdiArea()
    le = widgets.LineEdit("test")
    le2 = widgets.LineEdit("test")
    widget.add(le)
    widget.add(le2)
    widget.show()
    app.exec_()