Skip to content

CommandPalette

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
  1473367069664["custom_widgets.CommandPalette"]
  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 --> 1473367069664
  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

A Qt command palette widget.

Source code in prettyqt\custom_widgets\commandpalette.py
class CommandPalette(widgets.Widget):
    """A Qt command palette widget."""

    def __init__(self, parent: widgets.QWidget | None = None):
        super().__init__(parent=parent)
        self.setWindowFlags(
            constants.WindowType.WindowStaysOnTopHint
            | constants.WindowType.FramelessWindowHint
            # | constants.WindowType.ToolTip
        )
        self.set_focus_policy("strong")
        self.setMinimumWidth(700)
        self._line = widgets.LineEdit()
        self.setFocusProxy(self._line)
        self._table = CommandTable()
        # self._line.value_changed.connect(self._table.select_first_row)
        self._line.value_changed.connect(self._table._proxy.set_search_term)
        layout = self.set_layout("vertical")
        layout.addWidget(self._line)
        layout.addWidget(self._table)
        self.add_shortcut("Ctrl+P", callback=self.close)
        self._line.installEventFilter(self)

        # self._line.textChanged.connect(self._on_text_changed)
        # self._table.action_clicked.connect(self._on_action_clicked)
        # self._line.editingFinished.connect(self.hide)

    def eventFilter(self, source: core.QObject, e: core.QEvent) -> bool:
        if source != self._line or e.type() != core.QEvent.Type.KeyPress:
            return super().eventFilter(source, e)
        if e.modifiers() in (
            constants.KeyboardModifier.NoModifier,
            constants.KeyboardModifier.KeypadModifier,
        ):
            match e.key():
                case constants.Key.Key_Escape:
                    self.hide()
                    return True
                case constants.Key.Key_Return:
                    self.hide()
                    self._table.execute_focused()
                    return True
                case constants.Key.Key_Up:
                    self._table.move_row_selection(-1)
                    return True
                case constants.Key.Key_Down:
                    self._table.move_row_selection(1)
                    return True
        return super().eventFilter(source, e)

    def populate_from_widget(self, widget: widgets.QWidget):
        self.add_actions(widget.actions())
        if not callable(widget.parent):
            return
        while widget := widget.parent():
            self.add_actions(widget.actions())

    def add_path_actions(self, path):
        path = pathlib.Path(path)
        actions = [gui.Action(str(p)) for p in path.rglob("*") if p.is_file()]
        self.add_actions(actions)

    def match_color(self) -> str:
        """The color used for the matched characters."""
        return self._table.match_color

    def set_match_color(self, color):
        """Set the color used for the matched characters."""
        self._table.match_color = colors.get_color(color).name()

    def install_to(self, parent: widgets.Widget):
        self.setParent(parent, constants.WindowType.SubWindow)
        self.hide()

    # def focusOutEvent(self, a0: gui.QFocusEvent) -> None:
    #     self.hide()
    #     return super().focusOutEvent(a0)

    def add_actions(self, actions: Sequence[gui.QAction]):
        self._table._model.add_items(actions)

    def show(self):
        self._line.setText("")
        self.resize(1000, 300)
        self.position_on("screen")
        super().show()
        self.raise_()
        self._line.setFocus()

match_color() -> str

The color used for the matched characters.

Source code in prettyqt\custom_widgets\commandpalette.py
def match_color(self) -> str:
    """The color used for the matched characters."""
    return self._table.match_color

set_match_color(color)

Set the color used for the matched characters.

Source code in prettyqt\custom_widgets\commandpalette.py
def set_match_color(self, color):
    """Set the color used for the matched characters."""
    self._table.match_color = colors.get_color(color).name()

⌗ 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