Skip to content

RegexInput

Qt Base Class: QWidget

Signature: QWidget(self, parent: Optional[PySide6.QtWidgets.QWidget] = None, f: PySide6.QtCore.Qt.WindowType = Default(Qt.WindowFlags)) -> None

Base classes

Name Children Inherits
Widget
prettyqt.widgets.widget

⋔ Inheritance diagram

graph TD
  1473367067712["custom_widgets.RegexInput"]
  1473293661888["widgets.Widget"]
  1473293688240["widgets.WidgetMixin"]
  1473299815024["core.ObjectMixin"]
  140713234304496["builtins.object"]
  1473245548480["gui.PaintDeviceMixin"]
  1473290849680["QtWidgets.QWidget"]
  1473288842240["QtCore.QObject"]
  1473291690208["Shiboken.Object"]
  1473300082368["QtGui.QPaintDevice"]
  1473293661888 --> 1473367067712
  1473293688240 --> 1473293661888
  1473299815024 --> 1473293688240
  140713234304496 --> 1473299815024
  1473245548480 --> 1473293688240
  140713234304496 --> 1473245548480
  1473290849680 --> 1473293661888
  1473288842240 --> 1473290849680
  1473291690208 --> 1473288842240
  140713234304496 --> 1473291690208
  1473300082368 --> 1473290849680
  1473291690208 --> 1473300082368

🛈 DocStrings

Bases: Widget

Source code in prettyqt\custom_widgets\editors\regexinput.py
class RegexInput(widgets.Widget):
    LABEL_MAP = dict(
        multiline="MultiLine",
        ignorecase="Ignore case",
        ascii="ASCII-only matching",
        dotall="Dot matches newline",
        verbose="Ignore whitespace",
    )
    VALUE_MAP = dict(
        multiline=re.MULTILINE,
        ignorecase=re.IGNORECASE,
        ascii=re.ASCII,
        dotall=re.DOTALL,
        verbose=re.VERBOSE,
    )
    Flags = RegexFlag
    core.Enum(Flags)

    value_changed = core.Signal(object)

    def __init__(
        self,
        show_flags: bool = True,
        show_error: bool = True,
        object_name: str = "regex_input",
        **kwargs,
    ):
        super().__init__(object_name=object_name, **kwargs)
        self.set_layout("grid", margin=0)
        self.label_error = widgets.Label()
        self.label_error.set_color("highlight_role")
        self.lineedit = custom_widgets.RegexLineEdit()
        val = self.lineedit.validator
        val.error_occured.connect(self.label_error.set_text)
        val.pattern_updated.connect(self.value_changed)
        self.tb_flags = custom_widgets.BoolDictToolButton(
            text="Flags", icon="mdi.flag-variant-outline"
        )
        self.box[0, 0:1] = self.lineedit
        if show_flags:
            self.box[0, 2] = self.tb_flags
        if show_error:
            self.box[1, 0:2] = self.label_error
        self.tb_flags.value_changed.connect(self._on_value_change)

        self.tb_flags.set_dict(self.LABEL_MAP)

    def _on_value_change(self):
        try:
            val = self.get_value()
        except sre_constants.error:
            return
        else:
            self.value_changed.emit(val)

    def get_pattern(self) -> str:
        return self.lineedit.text()

    def set_pattern(self, value: str):
        self.lineedit.set_text(value)

    def get_flags(self) -> int:
        ret_val = self.Flags(0)
        for identifier, flag in self.VALUE_MAP.items():
            if self.tb_flags[identifier]:
                ret_val |= flag
        return ret_val

    def set_flags(self, value: int):
        for identifier, flag in self.VALUE_MAP.items():
            self.tb_flags[identifier] = bool(value & flag)

    def set_value(self, value: str | Pattern | None):
        match value:
            case None:
                self.set_pattern("")
                self.set_flags(self.Flags(0))
            case str():
                self.set_pattern(value)
                self.set_flags(self.Flags(0))
            case _:
                self.set_pattern(value.pattern)
                self.set_flags(self.Flags(value.flags))

    def get_value(self) -> Pattern:
        return re.compile(self.get_pattern(), self.get_flags())

    def is_valid(self) -> bool:
        return self.lineedit.is_valid()

    pattern = core.Property(
        str,
        get_pattern,
        set_pattern,
        user=True,
        doc="Current pattern as text",
    )

⌗ Property table

Qt Property Type Doc
objectName QString
modal bool
windowModality Qt::WindowModality
enabled bool
geometry QRect
frameGeometry QRect
normalGeometry QRect
x int
y int
pos QPoint
frameSize QSize
size QSize
width int
height int
rect QRect
childrenRect QRect
childrenRegion QRegion
sizePolicy QSizePolicy
minimumSize QSize
maximumSize QSize
minimumWidth int
minimumHeight int
maximumWidth int
maximumHeight int
sizeIncrement QSize
baseSize QSize
palette QPalette
font QFont
cursor QCursor
mouseTracking bool
tabletTracking bool
isActiveWindow bool
focusPolicy Qt::FocusPolicy
focus bool
contextMenuPolicy Qt::ContextMenuPolicy
updatesEnabled bool
visible bool
minimized bool
maximized bool
fullScreen bool
sizeHint QSize
minimumSizeHint QSize
acceptDrops bool
windowTitle QString
windowIcon QIcon
windowIconText QString
windowOpacity double
windowModified bool
toolTip QString
toolTipDuration int
statusTip QString
whatsThis QString
accessibleName QString
accessibleDescription QString
layoutDirection Qt::LayoutDirection
autoFillBackground bool
styleSheet QString
locale QLocale
windowFilePath QString
inputMethodHints QFlags
pattern QString Current pattern as text