Skip to content

custom_widgets

Class info

Classes

Name Children Inherits
AnnotatedScrollBar
prettyqt.custom_widgets.scrollbars.annotatedscrollbar
ScrollBar which can highlight user-defined ranges.
    AstViewer
    prettyqt.custom_widgets.astviewer
    Widget which displays an AST Tree next to the corresponding source code.
      AutoResizePlainTextEdit
      prettyqt.custom_widgets.autoresizingtextedit
      PlainTextEdit which adjusts its height to the contained text.
        AutoResizeTextEdit
        prettyqt.custom_widgets.autoresizingtextedit
        TextEdit which adjusts its height to the contained text.
          BoolDictToolButton
          prettyqt.custom_widgets.booldicttoolbutton
            BorderLayout
            prettyqt.custom_widgets.layouts.borderlayout
            Layout based on 5 Regions (north east, south, west and center).
              BrushEdit
              prettyqt.custom_widgets.editors.brushedit
                ClickableLabel
                prettyqt.custom_widgets.labels.clickablelabel
                A label widget that behaves like a button.
                  CodeEditor
                  prettyqt.custom_widgets.codeeditor
                  Code editor with line numbers, syntax highlighting and line markers.
                    CollapsibleFrame
                    prettyqt.custom_widgets.collapsibleframe
                    Frame containing another widget which can be collapsed.
                      ColorChooserButton
                      prettyqt.custom_widgets.editors.colorchooserbutton
                        ColorComboBox
                        prettyqt.custom_widgets.editors.colorcombobox
                          CommandPalette
                          prettyqt.custom_widgets.commandpalette
                          A Qt command palette widget.
                            CrossFadeWidget
                            prettyqt.custom_widgets.crossfadewidget
                              CursorEdit
                              prettyqt.custom_widgets.editors.cursoredit
                                ElidedLabel
                                prettyqt.custom_widgets.labels.elidedlabel
                                  EnumComboBox
                                  prettyqt.custom_widgets.editors.enumcombobox
                                  ComboBox presenting options from a python Enum.
                                  EnumFlagWidget
                                  prettyqt.custom_widgets.editors.enumflagwidget
                                    FaderWidget
                                    prettyqt.custom_widgets.faderwidget
                                      FileChooserButton
                                      prettyqt.custom_widgets.editors.filechooserbutton
                                        FileTree
                                        prettyqt.custom_widgets.itemviews.filetree
                                          FilterHeader
                                          prettyqt.custom_widgets.itemviews.filterheader
                                          A HeaderView subclass which includes widgets with filter possibilities.
                                            FlagSelectionWidget
                                            prettyqt.custom_widgets.editors.flagselectionwidget
                                              FloatLineEdit
                                              prettyqt.custom_widgets.editors.lineedits
                                                FlowLayout
                                                prettyqt.custom_widgets.layouts.flowlayout
                                                Layout which adjusts its children based on space available.
                                                  FontChooserButton
                                                  prettyqt.custom_widgets.editors.fontchooserbutton
                                                    IconBrowser
                                                    prettyqt.custom_widgets.iconbrowser
                                                    A small browser window that allows the user to search through all icons.
                                                      IconEdit
                                                      prettyqt.custom_widgets.editors.iconedit
                                                        IconLabel
                                                        prettyqt.custom_widgets.labels.iconlabel
                                                          IconWidget
                                                          prettyqt.custom_widgets.labels.iconwidget
                                                            ImageViewer
                                                            prettyqt.custom_widgets.imageviewer
                                                              InputAndSlider
                                                              prettyqt.custom_widgets.editors.inputandslider
                                                                IntLineEdit
                                                                prettyqt.custom_widgets.editors.lineedits
                                                                  KeyCombinationEdit
                                                                  prettyqt.custom_widgets.editors.keycombinationedit
                                                                    LabeledSlider
                                                                    prettyqt.custom_widgets.labeledslider
                                                                      ListInput
                                                                      prettyqt.custom_widgets.editors.listinput
                                                                        LocaleEdit
                                                                        prettyqt.custom_widgets.editors.localeedit
                                                                          LogRecordTableView
                                                                          prettyqt.custom_widgets.logrecordtableview
                                                                          Table view showing a log table.
                                                                            LogTextEdit
                                                                            prettyqt.custom_widgets.logtextedit
                                                                              MappedCheckBox
                                                                              prettyqt.custom_widgets.editors.mappedcheckbox
                                                                                MultiComboBox
                                                                                prettyqt.custom_widgets.multicombobox
                                                                                ComboBox allowing multiple-choice selection.
                                                                                  MultiLineLayout
                                                                                  prettyqt.custom_widgets.layouts.multilinelayout
                                                                                  Nested Boxlayout.
                                                                                    NumFilterWidget
                                                                                    prettyqt.custom_widgets.numfilterwidget
                                                                                    Widget with a button to choose from a comparison op (>\=, >, etc) + a lineedit.
                                                                                      ObjectBrowser
                                                                                      prettyqt.custom_widgets.objectbrowser
                                                                                      Info window for python objects.
                                                                                        OptionalWidget
                                                                                        prettyqt.custom_widgets.optionalwidget
                                                                                        Wraps another widget in a GroupBox with and CheckBock and makes it optional.
                                                                                          OrientedTableView
                                                                                          prettyqt.custom_widgets.orientedtableview
                                                                                          TableView class with some convenience methods for oriented tables.
                                                                                            PaletteEdit
                                                                                            prettyqt.custom_widgets.editors.paletteedit
                                                                                            Simple editor to edit QPalettes.
                                                                                              PointEdit
                                                                                              prettyqt.custom_widgets.editors.pointedit
                                                                                              Simple Editor for QPoints.
                                                                                                PopupInfo
                                                                                                prettyqt.custom_widgets.popupinfo
                                                                                                Dialog overlay to show some info to user.
                                                                                                  PreviewScrollBar
                                                                                                  prettyqt.custom_widgets.scrollbars.previewscrollbar
                                                                                                  Scrollbar showing a small preview of a (Plain)TextEdit.
                                                                                                    QObjectHierarchyTreeView
                                                                                                    prettyqt.custom_widgets.qobjecthierarchytreeview
                                                                                                      QObjectPropertiesTableView
                                                                                                      prettyqt.custom_widgets.qobjectpropertiestableview
                                                                                                        RangeEdit
                                                                                                        prettyqt.custom_widgets.editors.rangeedit
                                                                                                          RectEdit
                                                                                                          prettyqt.custom_widgets.editors.rectedit
                                                                                                            • BaseRectEdit
                                                                                                            RectFEdit
                                                                                                            prettyqt.custom_widgets.editors.rectedit
                                                                                                              • BaseRectEdit
                                                                                                              RegexInput
                                                                                                              prettyqt.custom_widgets.editors.regexinput
                                                                                                                RegexLineEdit
                                                                                                                prettyqt.custom_widgets.editors.regexlineedit
                                                                                                                  RegionEdit
                                                                                                                  prettyqt.custom_widgets.editors.rectedit
                                                                                                                    • BaseRectEdit
                                                                                                                    RoundProgressBar
                                                                                                                    prettyqt.custom_widgets.roundprogressbar
                                                                                                                      ScrollAreaTocWidget
                                                                                                                      prettyqt.custom_widgets.scrollareatocwidget
                                                                                                                        SelectionWidget
                                                                                                                        prettyqt.custom_widgets.editors.selectionwidget
                                                                                                                          SidebarWidget
                                                                                                                          prettyqt.custom_widgets.sidebarwidget
                                                                                                                            SingleLineTextEdit
                                                                                                                            prettyqt.custom_widgets.editors.singlelinetextedit
                                                                                                                            SizeEdit
                                                                                                                            prettyqt.custom_widgets.editors.sizeedit
                                                                                                                              SizePolicyEdit
                                                                                                                              prettyqt.custom_widgets.editors.sizepolicyedit
                                                                                                                                SliceEdit
                                                                                                                                prettyqt.custom_widgets.editors.sliceedit
                                                                                                                                Simple editor to edit slices.
                                                                                                                                  SmoothScrollBar
                                                                                                                                  prettyqt.custom_widgets.scrollbars.smoothscrollbar
                                                                                                                                    SpanSlider
                                                                                                                                    prettyqt.custom_widgets.editors.spanslider
                                                                                                                                      SpanSliderWidget
                                                                                                                                      prettyqt.custom_widgets.editors.spanslider
                                                                                                                                        StandardIconsWidget
                                                                                                                                        prettyqt.custom_widgets.standardiconswidget
                                                                                                                                        Dialog showing standard icons.
                                                                                                                                          StringListEdit
                                                                                                                                          prettyqt.custom_widgets.editors.lineedits
                                                                                                                                            StringOrNumberWidget
                                                                                                                                            prettyqt.custom_widgets.editors.stringornumberwidget
                                                                                                                                              SubsequenceCompleter
                                                                                                                                              prettyqt.custom_widgets.subsequencecompleter
                                                                                                                                              QCompleter specialised for subsequence matching.
                                                                                                                                                Timeline
                                                                                                                                                prettyqt.custom_widgets.timeline
                                                                                                                                                  UrlLineEdit
                                                                                                                                                  prettyqt.custom_widgets.editors.lineedits
                                                                                                                                                    VideoSample
                                                                                                                                                    prettyqt.custom_widgets.timeline
                                                                                                                                                      WaitingSpinner
                                                                                                                                                      prettyqt.custom_widgets.waitingspinner
                                                                                                                                                        • BaseWaitingSpinner
                                                                                                                                                        WidgetEditor
                                                                                                                                                        prettyqt.custom_widgets.widgeteditor

                                                                                                                                                          🛈 DocStrings

                                                                                                                                                          AnnotatedScrollBar

                                                                                                                                                          Bases: ScrollBar

                                                                                                                                                          ScrollBar which can highlight user-defined ranges.

                                                                                                                                                          widget = widgets.PlainTextEdit("\n".join(str(i) for i in range(1000)))
                                                                                                                                                          widget.v_scrollbar = AnnotatedScrollBar(constants.VERTICAL)
                                                                                                                                                          widget.v_scrollbar.set_annotations([(10, 20), (50, 60), (82, 85)])
                                                                                                                                                          
                                                                                                                                                          ![Image title](../../images/annotatedscrollbar.png)
                                                                                                                                                          Annotated ScrollBar
                                                                                                                                                          Source code in prettyqt/custom_widgets/scrollbars/annotatedscrollbar.py
                                                                                                                                                          class AnnotatedScrollBar(widgets.ScrollBar):
                                                                                                                                                              r"""ScrollBar which can highlight user-defined ranges.
                                                                                                                                                          
                                                                                                                                                              ``` py
                                                                                                                                                              widget = widgets.PlainTextEdit("\n".join(str(i) for i in range(1000)))
                                                                                                                                                              widget.v_scrollbar = AnnotatedScrollBar(constants.VERTICAL)
                                                                                                                                                              widget.v_scrollbar.set_annotations([(10, 20), (50, 60), (82, 85)])
                                                                                                                                                              ```
                                                                                                                                                          
                                                                                                                                                              <figure markdown>
                                                                                                                                                                ![Image title](../../images/annotatedscrollbar.png)
                                                                                                                                                                <figcaption>Annotated ScrollBar</figcaption>
                                                                                                                                                              </figure>
                                                                                                                                                              """
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args, **kwargs):
                                                                                                                                                                  super().__init__(*args, **kwargs)
                                                                                                                                                                  self._annotation_color = gui.QColor("gold")
                                                                                                                                                                  self._annotations = []
                                                                                                                                                                  self._document_length = 100
                                                                                                                                                          
                                                                                                                                                              @classmethod
                                                                                                                                                              def create_example(cls):
                                                                                                                                                                  widget = widgets.PlainTextEdit("\n".join(str(i) for i in range(1000)))
                                                                                                                                                                  scrollbar = AnnotatedScrollBar(constants.VERTICAL)
                                                                                                                                                                  scrollbar.set_annotations([(10, 20), (50, 60), (82, 85)])
                                                                                                                                                                  widget.v_scrollbar = scrollbar
                                                                                                                                                                  return widget
                                                                                                                                                          
                                                                                                                                                              def set_annotations(self, annotations: list[tuple[int, int]]):
                                                                                                                                                                  self._annotations = annotations
                                                                                                                                                          
                                                                                                                                                              def get_annotations(self) -> list[tuple[int, int]]:
                                                                                                                                                                  return self._annotations
                                                                                                                                                          
                                                                                                                                                              def add_annotation(self, annotation: tuple[int, int]):
                                                                                                                                                                  self._annotations.append(annotation)
                                                                                                                                                          
                                                                                                                                                              def paintEvent(self, event):
                                                                                                                                                                  super().paintEvent(event)
                                                                                                                                                                  with gui.Painter(self) as p:
                                                                                                                                                                      opt = widgets.QStyleOptionSlider()
                                                                                                                                                                      self.initStyleOption(opt)
                                                                                                                                                                      gr = self.style().subControlRect(
                                                                                                                                                                          CC_ScrollBar, opt, SubControl.SC_ScrollBarGroove, self
                                                                                                                                                                      )
                                                                                                                                                                      sr = self.style().subControlRect(
                                                                                                                                                                          CC_ScrollBar, opt, SubControl.SC_ScrollBarSlider, self
                                                                                                                                                                      )
                                                                                                                                                                      p.setClipRegion(
                                                                                                                                                                          gui.QRegion(gr) - gui.QRegion(sr), constants.ClipOperation.IntersectClip
                                                                                                                                                                      )
                                                                                                                                                                      x, y, w, h = gr.x(), gr.y(), gr.width(), gr.height()
                                                                                                                                                                      c = gui.QColor(self._annotation_color)
                                                                                                                                                                      p.setBrush(c)
                                                                                                                                                                      c.setAlphaF(0.3)
                                                                                                                                                                      p.setPen(gui.QPen(c, 2.0))
                                                                                                                                                                      scale = 1.0 / self._document_length
                                                                                                                                                                      if self.orientation() == constants.VERTICAL:
                                                                                                                                                                          rects = [
                                                                                                                                                                              core.QRectF(
                                                                                                                                                                                  x + 1,
                                                                                                                                                                                  y + h * start * scale - 0.5,
                                                                                                                                                                                  w - 2,
                                                                                                                                                                                  h * (end - start) * scale + 1,
                                                                                                                                                                              )
                                                                                                                                                                              for start, end in self._annotations
                                                                                                                                                                          ]
                                                                                                                                                                      else:
                                                                                                                                                                          rects = [
                                                                                                                                                                              core.QRectF(
                                                                                                                                                                                  x + w * start * scale - 0.5,
                                                                                                                                                                                  y + 1,
                                                                                                                                                                                  w * (end - start) * scale + 1,
                                                                                                                                                                                  h - 2,
                                                                                                                                                                              )
                                                                                                                                                                              for start, end in self._annotations
                                                                                                                                                                          ]
                                                                                                                                                                      if rects:
                                                                                                                                                                          p.drawRects(rects)
                                                                                                                                                          
                                                                                                                                                              def set_annotation_color(self, color: datatypes.ColorType):
                                                                                                                                                                  self._annotation_color = colors.get_color(color).as_qt()
                                                                                                                                                          
                                                                                                                                                              def get_annotation_color(self) -> gui.QColor:
                                                                                                                                                                  return self._annotation_color
                                                                                                                                                          
                                                                                                                                                              def set_document_length(self, length: int):
                                                                                                                                                                  self._document_length = length
                                                                                                                                                          
                                                                                                                                                              def get_document_length(self) -> int:
                                                                                                                                                                  return self._document_length
                                                                                                                                                          
                                                                                                                                                              annotation_color = core.Property(
                                                                                                                                                                  gui.QColor,
                                                                                                                                                                  get_annotation_color,
                                                                                                                                                                  set_annotation_color,
                                                                                                                                                                  doc="Color for the annotated regions",
                                                                                                                                                              )
                                                                                                                                                              annotations = core.Property(
                                                                                                                                                                  list,
                                                                                                                                                                  get_annotations,
                                                                                                                                                                  set_annotations,
                                                                                                                                                                  doc="Current set of annotations",
                                                                                                                                                              )
                                                                                                                                                              document_length = core.Property(
                                                                                                                                                                  int,
                                                                                                                                                                  get_document_length,
                                                                                                                                                                  set_document_length,
                                                                                                                                                                  doc="Total document length",
                                                                                                                                                              )
                                                                                                                                                          

                                                                                                                                                          AstViewer

                                                                                                                                                          Bases: Splitter

                                                                                                                                                          Widget which displays an AST Tree next to the corresponding source code.

                                                                                                                                                          Selecting a node in the tree will highlight the corresponing text section in source.

                                                                                                                                                          widget = custom_widgets.AstViewer()
                                                                                                                                                          widget.show()
                                                                                                                                                          
                                                                                                                                                          ![Image title](../../images/astviewer.png)
                                                                                                                                                          AstViewer widget
                                                                                                                                                          Source code in prettyqt/custom_widgets/astviewer.py
                                                                                                                                                          class AstViewer(widgets.Splitter):
                                                                                                                                                              """Widget which displays an AST Tree next to the corresponding source code.
                                                                                                                                                          
                                                                                                                                                              Selecting a node in the tree will highlight the corresponing text section in source.
                                                                                                                                                          
                                                                                                                                                              ``` py
                                                                                                                                                              widget = custom_widgets.AstViewer()
                                                                                                                                                              widget.show()
                                                                                                                                                              ```
                                                                                                                                                          
                                                                                                                                                              <figure markdown>
                                                                                                                                                                ![Image title](../../images/astviewer.png)
                                                                                                                                                                <figcaption>AstViewer widget</figcaption>
                                                                                                                                                              </figure>
                                                                                                                                                              """
                                                                                                                                                          
                                                                                                                                                              def __init__(
                                                                                                                                                                  self,
                                                                                                                                                                  object_name="ast_viewer",
                                                                                                                                                                  **kwargs,
                                                                                                                                                              ):
                                                                                                                                                                  super().__init__(orientation="horizontal", object_name=object_name, **kwargs)
                                                                                                                                                                  self.tree = widgets.TreeView()
                                                                                                                                                                  self.ast_textedit = widgets.PlainTextEdit()
                                                                                                                                                                  self.tabwidget = widgets.TabWidget()
                                                                                                                                                                  self.tabwidget.add_tab(self.tree, "Tree")
                                                                                                                                                                  self.tabwidget.add_tab(self.ast_textedit, "Dumped")
                                                                                                                                                          
                                                                                                                                                                  self.textedit = custom_widgets.CodeEditor()
                                                                                                                                                                  self.textedit.set_syntaxhighlighter("python")
                                                                                                                                                                  self.textedit.textChanged.connect(self._on_text_change)
                                                                                                                                                                  self.add(self.tabwidget)
                                                                                                                                                                  self.add(self.textedit)
                                                                                                                                                          
                                                                                                                                                              def _on_text_change(self):
                                                                                                                                                                  self.set_ast(self.textedit.get_value())
                                                                                                                                                          
                                                                                                                                                              def _on_current_change(self, new_index: core.ModelIndex, _):
                                                                                                                                                                  node = new_index.data(constants.USER_ROLE)
                                                                                                                                                                  if not hasattr(node, "lineno"):
                                                                                                                                                                      return
                                                                                                                                                                  with self.textedit.selecter.current_cursor() as cursor:
                                                                                                                                                                      cursor.select_text(
                                                                                                                                                                          (node.lineno - 1, node.col_offset),
                                                                                                                                                                          (node.end_lineno - 1, node.end_col_offset),
                                                                                                                                                                      )
                                                                                                                                                          
                                                                                                                                                              def set_ast(self, ast_or_str: str | ast.AST):
                                                                                                                                                                  model = self.tree.get_model(skip_proxies=True)
                                                                                                                                                                  if not isinstance(model, itemmodels.AstModel):
                                                                                                                                                                      model = itemmodels.AstModel(ast_or_str, show_root=True, parent=self.tree)
                                                                                                                                                                      self.tree.set_model(model)
                                                                                                                                                                      self.tree.selectionModel().currentChanged.connect(self._on_current_change)
                                                                                                                                                                  else:
                                                                                                                                                                      model.set_ast(ast_or_str)
                                                                                                                                                                  self.tree.show_root(False)
                                                                                                                                                                  self.tree.expandAll()
                                                                                                                                                                  ast_tree = model.ast_tree
                                                                                                                                                                  text = ast_or_str if isinstance(ast_or_str, str) else ast.unparse(ast_or_str)
                                                                                                                                                                  with self.textedit.signals_blocked():
                                                                                                                                                                      self.textedit.set_text(text)
                                                                                                                                                                  dumped = ast.dump(ast_tree, indent=4) if ast_tree is not None else ""
                                                                                                                                                                  self.ast_textedit.set_text(dumped)
                                                                                                                                                          
                                                                                                                                                              def rename_variable(
                                                                                                                                                                  self,
                                                                                                                                                                  old: str,
                                                                                                                                                                  new: str,
                                                                                                                                                                  ignore: list[str] | None = None,
                                                                                                                                                                  scope: list[str] | None = None,
                                                                                                                                                              ):
                                                                                                                                                                  """Rename all identifiers named `old` to `new` (see AstModel.rename_variable)."""
                                                                                                                                                                  model = self.tree.get_model(skip_proxies=True)
                                                                                                                                                                  if not isinstance(model, itemmodels.AstModel):
                                                                                                                                                                      raise TypeError(model)
                                                                                                                                                                  model.rename_variable(old, new, ignore=ignore, scope=scope)
                                                                                                                                                                  if model.ast_tree is not None:
                                                                                                                                                                      self.set_ast(model.ast_tree)
                                                                                                                                                          

                                                                                                                                                          rename_variable(old: str, new: str, ignore: list[str] | None = None, scope: list[str] | None = None)

                                                                                                                                                          Rename all identifiers named old to new (see AstModel.rename_variable).

                                                                                                                                                          Source code in prettyqt/custom_widgets/astviewer.py
                                                                                                                                                          def rename_variable(
                                                                                                                                                              self,
                                                                                                                                                              old: str,
                                                                                                                                                              new: str,
                                                                                                                                                              ignore: list[str] | None = None,
                                                                                                                                                              scope: list[str] | None = None,
                                                                                                                                                          ):
                                                                                                                                                              """Rename all identifiers named `old` to `new` (see AstModel.rename_variable)."""
                                                                                                                                                              model = self.tree.get_model(skip_proxies=True)
                                                                                                                                                              if not isinstance(model, itemmodels.AstModel):
                                                                                                                                                                  raise TypeError(model)
                                                                                                                                                              model.rename_variable(old, new, ignore=ignore, scope=scope)
                                                                                                                                                              if model.ast_tree is not None:
                                                                                                                                                                  self.set_ast(model.ast_tree)
                                                                                                                                                          

                                                                                                                                                          AutoResizePlainTextEdit

                                                                                                                                                          Bases: AutoResizeTextEditMixin, PlainTextEdit

                                                                                                                                                          PlainTextEdit which adjusts its height to the contained text.

                                                                                                                                                          Source code in prettyqt/custom_widgets/autoresizingtextedit.py
                                                                                                                                                          class AutoResizePlainTextEdit(AutoResizeTextEditMixin, widgets.PlainTextEdit):
                                                                                                                                                              """PlainTextEdit which adjusts its height to the contained text."""
                                                                                                                                                          
                                                                                                                                                              def get_document_size(self) -> core.QSize:
                                                                                                                                                                  doc = self.document()
                                                                                                                                                                  layout = doc.documentLayout()
                                                                                                                                                                  size = layout.documentSize().toSize()
                                                                                                                                                                  block = doc.firstBlock()
                                                                                                                                                                  line_height = layout.blockBoundingRect(block).height() / block.lineCount()
                                                                                                                                                                  height = int(size.height() * line_height + 2 * doc.documentMargin())
                                                                                                                                                                  return core.QSize(size.width(), height)
                                                                                                                                                          

                                                                                                                                                          AutoResizeTextEdit

                                                                                                                                                          Bases: AutoResizeTextEditMixin, TextEdit

                                                                                                                                                          TextEdit which adjusts its height to the contained text.

                                                                                                                                                          Source code in prettyqt/custom_widgets/autoresizingtextedit.py
                                                                                                                                                          class AutoResizeTextEdit(AutoResizeTextEditMixin, widgets.TextEdit):
                                                                                                                                                              """TextEdit which adjusts its height to the contained text."""
                                                                                                                                                          
                                                                                                                                                              def get_document_size(self) -> core.QSize:
                                                                                                                                                                  return self.document().documentLayout().documentSize().toSize()
                                                                                                                                                          

                                                                                                                                                          BorderLayout

                                                                                                                                                          Bases: Layout

                                                                                                                                                          Layout based on 5 Regions (north east, south, west and center).

                                                                                                                                                          Source code in prettyqt/custom_widgets/layouts/borderlayout.py
                                                                                                                                                          class BorderLayout(widgets.Layout):
                                                                                                                                                              """Layout based on 5 Regions (north east, south, west and center)."""
                                                                                                                                                          
                                                                                                                                                              ID = "border"
                                                                                                                                                          
                                                                                                                                                              class Position(enum.IntEnum):
                                                                                                                                                                  """Item position."""
                                                                                                                                                          
                                                                                                                                                                  West = 0
                                                                                                                                                                  North = 1
                                                                                                                                                                  South = 2
                                                                                                                                                                  East = 3
                                                                                                                                                                  Center = 4
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args, **kwargs):
                                                                                                                                                                  super().__init__(*args, **kwargs)
                                                                                                                                                                  self.items: list[ItemWrapper] = []
                                                                                                                                                          
                                                                                                                                                              def addItem(self, item: widgets.QWidgetItem):
                                                                                                                                                                  self.add_widgetitem(item, BorderLayout.Position.West)
                                                                                                                                                          
                                                                                                                                                              def addWidget(
                                                                                                                                                                  self,
                                                                                                                                                                  widget: widgets.QWidget,
                                                                                                                                                                  position: Position | None = None,
                                                                                                                                                              ):
                                                                                                                                                                  position = BorderLayout.Position.West if position is None else position
                                                                                                                                                                  self.add_widgetitem(widgets.WidgetItem(widget), position)
                                                                                                                                                          
                                                                                                                                                              def expandingDirections(self) -> constants.Orientation:
                                                                                                                                                                  return constants.HORIZONTAL | constants.VERTICAL
                                                                                                                                                          
                                                                                                                                                              def hasHeightForWidth(self) -> bool:
                                                                                                                                                                  return False
                                                                                                                                                          
                                                                                                                                                              def count(self) -> int:
                                                                                                                                                                  return len(self.items)
                                                                                                                                                          
                                                                                                                                                              def itemAt(self, index: int) -> widgets.QWidgetItem | None:
                                                                                                                                                                  return self.items[index].item if 0 <= index < len(self.items) else None
                                                                                                                                                          
                                                                                                                                                              def minimumSize(self):
                                                                                                                                                                  return self.calculate_size("minimum")
                                                                                                                                                          
                                                                                                                                                              def setGeometry(self, rect: core.QRect):
                                                                                                                                                                  center = None
                                                                                                                                                                  east_width = 0
                                                                                                                                                                  west_width = 0
                                                                                                                                                                  north_height = 0
                                                                                                                                                                  south_height = 0
                                                                                                                                                                  super().setGeometry(rect)
                                                                                                                                                                  for wrapper in self.items:
                                                                                                                                                                      item = wrapper.item
                                                                                                                                                                      match wrapper.position:
                                                                                                                                                                          case BorderLayout.Position.North:
                                                                                                                                                                              h = item.sizeHint().height()
                                                                                                                                                                              geom = core.Rect(rect.x(), north_height, rect.width(), h)
                                                                                                                                                                              item.setGeometry(geom)
                                                                                                                                                                              north_height += item.geometry().height() + self.spacing()
                                                                                                                                                                          case BorderLayout.Position.South:
                                                                                                                                                                              geo = item.geometry()
                                                                                                                                                                              h = item.sizeHint().height()
                                                                                                                                                                              geom = core.Rect(geo.x(), geo.y(), rect.width(), h)
                                                                                                                                                                              item.setGeometry(geom)
                                                                                                                                                                              south_height += item.geometry().height() + self.spacing()
                                                                                                                                                                              y = rect.y() + rect.height() - south_height + self.spacing()
                                                                                                                                                                              geo = item.geometry()
                                                                                                                                                                              geom = core.Rect(rect.x(), y, geo.width(), geo.height())
                                                                                                                                                                              item.setGeometry(geom)
                                                                                                                                                                          case BorderLayout.Position.Center:
                                                                                                                                                                              center = wrapper
                                                                                                                                                          
                                                                                                                                                                  center_height = rect.height() - north_height - south_height
                                                                                                                                                          
                                                                                                                                                                  for wrapper in self.items:
                                                                                                                                                                      item = wrapper.item
                                                                                                                                                                      match wrapper.position:
                                                                                                                                                                          case BorderLayout.Position.West:
                                                                                                                                                                              x = rect.x() + west_width
                                                                                                                                                                              w = item.sizeHint().width()
                                                                                                                                                                              geom = core.Rect(x, north_height, w, center_height)
                                                                                                                                                                              item.setGeometry(geom)
                                                                                                                                                                              west_width += item.geometry().width() + self.spacing()
                                                                                                                                                                          case BorderLayout.Position.East:
                                                                                                                                                                              geo = item.geometry()
                                                                                                                                                                              w = item.sizeHint().width()
                                                                                                                                                                              geom = core.Rect(geo.x(), geo.y(), w, center_height)
                                                                                                                                                                              item.setGeometry(geom)
                                                                                                                                                                              east_width += item.geometry().width() + self.spacing()
                                                                                                                                                                              x = rect.x() + rect.width() - east_width + self.spacing()
                                                                                                                                                                              geo = item.geometry()
                                                                                                                                                                              geom = core.Rect(x, north_height, geo.width(), geo.height())
                                                                                                                                                                              item.setGeometry(geom)
                                                                                                                                                          
                                                                                                                                                                  if center:
                                                                                                                                                                      w = rect.width() - east_width - west_width
                                                                                                                                                                      rect = core.Rect(west_width, north_height, w, center_height)
                                                                                                                                                                      center.item.setGeometry(rect)
                                                                                                                                                          
                                                                                                                                                              def sizeHint(self) -> core.Size:
                                                                                                                                                                  return self.calculate_size("size_hint")
                                                                                                                                                          
                                                                                                                                                              def takeAt(self, index: int) -> widgets.QWidgetItem | None:
                                                                                                                                                                  if 0 <= index < len(self.items):
                                                                                                                                                                      layout_struct = self.items.pop(index)
                                                                                                                                                                      return layout_struct.item
                                                                                                                                                          
                                                                                                                                                                  return None
                                                                                                                                                          
                                                                                                                                                              def add_widgetitem(self, item: widgets.QWidgetItem, position: Position):
                                                                                                                                                                  self.items.append(ItemWrapper(item, position))
                                                                                                                                                          
                                                                                                                                                              def calculate_size(self, size_type: Literal["minimum", "size_hint"]) -> core.Size:
                                                                                                                                                                  total_size = core.Size()
                                                                                                                                                                  pos = BorderLayout.Position
                                                                                                                                                                  for wrapper in self.items:
                                                                                                                                                                      item_size = (
                                                                                                                                                                          wrapper.item.minimumSize()
                                                                                                                                                                          if size_type == "minimum"
                                                                                                                                                                          else wrapper.item.sizeHint()
                                                                                                                                                                      )
                                                                                                                                                                      if wrapper.position in (pos.North, pos.South, pos.Center):
                                                                                                                                                                          total_size.setHeight(total_size.height() + item_size.height())
                                                                                                                                                                      if wrapper.position in (pos.West, pos.East, pos.Center):
                                                                                                                                                                          total_size.setWidth(total_size.width() + item_size.width())
                                                                                                                                                                  return total_size
                                                                                                                                                          

                                                                                                                                                          Position

                                                                                                                                                          Bases: IntEnum

                                                                                                                                                          Item position.

                                                                                                                                                          Source code in prettyqt/custom_widgets/layouts/borderlayout.py
                                                                                                                                                          class Position(enum.IntEnum):
                                                                                                                                                              """Item position."""
                                                                                                                                                          
                                                                                                                                                              West = 0
                                                                                                                                                              North = 1
                                                                                                                                                              South = 2
                                                                                                                                                              East = 3
                                                                                                                                                              Center = 4
                                                                                                                                                          

                                                                                                                                                          ClickableLabel

                                                                                                                                                          Bases: Label

                                                                                                                                                          A label widget that behaves like a button.

                                                                                                                                                          Source code in prettyqt/custom_widgets/labels/clickablelabel.py
                                                                                                                                                          class ClickableLabel(widgets.Label):
                                                                                                                                                              """A label widget that behaves like a button."""
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args, **kwargs):
                                                                                                                                                                  super().__init__(*args, **kwargs, alignment="left")
                                                                                                                                                                  self.setFont(gui.QFont("Arial"))
                                                                                                                                                                  self.setFixedHeight(24)
                                                                                                                                                                  self.set_size_policy("minimum", "expanding")
                                                                                                                                                          
                                                                                                                                                              def setText(self, text: str):
                                                                                                                                                                  fm = gui.FontMetrics(self.font())
                                                                                                                                                                  width = fm.horizontalAdvance(text)
                                                                                                                                                                  self.setFixedWidth(width + 18)
                                                                                                                                                                  super().setText(text)
                                                                                                                                                          
                                                                                                                                                              def enterEvent(self, event: gui.QEnterEvent):
                                                                                                                                                                  with self.edit_font() as font:
                                                                                                                                                                      font.setUnderline(True)
                                                                                                                                                                  self.set_cursor("pointing_hand")
                                                                                                                                                                  self.update()
                                                                                                                                                                  return super().enterEvent(event)
                                                                                                                                                          
                                                                                                                                                              def leaveEvent(self, event: core.QEvent):
                                                                                                                                                                  with self.edit_font() as font:
                                                                                                                                                                      font.setUnderline(False)
                                                                                                                                                                  self.unsetCursor()
                                                                                                                                                                  return super().leaveEvent(event)
                                                                                                                                                          

                                                                                                                                                          CodeEditor

                                                                                                                                                          Bases: PlainTextEdit

                                                                                                                                                          Code editor with line numbers, syntax highlighting and line markers.

                                                                                                                                                          Line markers (errors / warnings / infos) tint the line and its number; hovering the line number or the line shows the marker messages as tooltip. set_text() keeps cursor and scroll position (and the undo history).

                                                                                                                                                          Source code in prettyqt/custom_widgets/codeeditor.py
                                                                                                                                                          class CodeEditor(widgets.PlainTextEdit):
                                                                                                                                                              """Code editor with line numbers, syntax highlighting and line markers.
                                                                                                                                                          
                                                                                                                                                              Line markers (errors / warnings / infos) tint the line and its number;
                                                                                                                                                              hovering the line number or the line shows the marker messages as tooltip.
                                                                                                                                                              `set_text()` keeps cursor and scroll position (and the undo history).
                                                                                                                                                              """
                                                                                                                                                          
                                                                                                                                                              def __init__(self, language: str = "python", **kwargs):
                                                                                                                                                                  super().__init__(**kwargs)
                                                                                                                                                                  self._markers: dict[int, list[LineMarker]] = {}
                                                                                                                                                                  self.line_area = LineNumberArea(self)
                                                                                                                                                                  self.blockCountChanged.connect(self.update_line_area_width)
                                                                                                                                                                  self.updateRequest.connect(self.update_line_area)
                                                                                                                                                                  self.set_font(gui.Font.mono(as_qt=True))
                                                                                                                                                                  self.update_line_area_width(0)
                                                                                                                                                                  self.set_current_line_color(gui.Color(128, 128, 128, 20))
                                                                                                                                                                  self.set_syntaxhighlighter(language)
                                                                                                                                                          
                                                                                                                                                              #     self.delimiter = "    "
                                                                                                                                                              #     self.completion_state = 0
                                                                                                                                                              #     self.completing = False
                                                                                                                                                              #     self.cursorPositionChanged.connect(self.reset_completion)
                                                                                                                                                          
                                                                                                                                                              # def keyPressEvent(self, event):
                                                                                                                                                              #     match event.key():
                                                                                                                                                              #         case constants.Key.Key_Backtab if self.textCursor().hasSelection():
                                                                                                                                                              #             start_cursor = self.get_textCursor()
                                                                                                                                                              #             with start_cursor.edit_block():
                                                                                                                                                              #                 start_pos = start_cursor.selectionStart()
                                                                                                                                                              #                 start_cursor.setPosition(start_pos)
                                                                                                                                                              #                 start_cursor.move_position("start_of_line")
                                                                                                                                                              #                 start_cursor.clearSelection()
                                                                                                                                                              #                 end_cursor = self.get_text_cursor()
                                                                                                                                                              #                 end_pos = end_cursor.selectionEnd()
                                                                                                                                                              #                 end_cursor.setPosition(end_pos)
                                                                                                                                                              #                 end_cursor.move_position("start_of_line")
                                                                                                                                                              #                 delimit_len = len(self.delimiter)
                                                                                                                                                              #                 while start_cursor.anchor() != end_cursor.position():
                                                                                                                                                              #                     start_cursor.move_position(
                                                                                                                                                              #                         "next_character", mode="keep", n=delimit_len
                                                                                                                                                              #                     )
                                                                                                                                                              #                     if start_cursor.selectedText() == self.delimiter:
                                                                                                                                                              #                         start_cursor.removeSelectedText()
                                                                                                                                                              #                     start_cursor.move_position("next_block")
                                                                                                                                                              #                 start_cursor.move_position(
                                                                                                                                                              #                     "next_character", mode="keep", n=delimit_len
                                                                                                                                                              #                 )
                                                                                                                                                              #                 if start_cursor.selectedText() == self.delimiter:
                                                                                                                                                              #                     start_cursor.removeSelectedText()
                                                                                                                                                              #         case constants.Key.Key_Tab if self.textCursor().hasSelection():
                                                                                                                                                              #             start_cursor = self.get_text_cursor()
                                                                                                                                                              #             with start_cursor.edit_block():
                                                                                                                                                              #                 start_pos = start_cursor.selectionStart()
                                                                                                                                                              #                 start_cursor.setPosition(start_pos)
                                                                                                                                                              #                 start_cursor.move_position("start_of_line")
                                                                                                                                                              #                 end_cursor = self.get_text_cursor()
                                                                                                                                                              #                 end_pos = end_cursor.selectionEnd()
                                                                                                                                                              #                 end_cursor.setPosition(end_pos)
                                                                                                                                                              #                 end_cursor.move_position("start_of_line")
                                                                                                                                                              #                 while start_cursor.position() != end_cursor.position():
                                                                                                                                                              #                     start_cursor.insertText(self.delimiter)
                                                                                                                                                              #                     start_cursor.move_position("next_block")
                                                                                                                                                              #                 start_cursor.insertText(self.delimiter)
                                                                                                                                                              #         case constants.Key.Key_Escape if self.completion_state > 0:
                                                                                                                                                              #             self.completion_state = 0
                                                                                                                                                              #             cursor = self.get_text_cursor()
                                                                                                                                                              #             with cursor.edit_block():
                                                                                                                                                              #                 self.selecter.replace_block_at_cursor(self._orig_text)
                                                                                                                                                              #             self._orig_text == None
                                                                                                                                                              #         case constants.Key.Key_Tab:
                                                                                                                                                              #             if self.is_start():
                                                                                                                                                              #                 self.textCursor().insertText(self.delimiter)
                                                                                                                                                              #             else:
                                                                                                                                                              #                 cursor = self.get_text_cursor()
                                                                                                                                                              #                 with cursor.edit_block():
                                                                                                                                                              #                     self.completing = True
                                                                                                                                                              #                     if self.completion_state == 0:
                                                                                                                                                              #                         self._orig_text = self.textCursor().block().text()
                                                                                                                                                              #                     if self.completion_state > 0:
                                                                                                                                                              #                         self.selecter.replace_block_at_cursor(self._orig_text)
                                                                                                                                                              #                     new_text = self.completer.complete(
                                                                                                                                                              #                         self._orig_text, self.completion_state
                                                                                                                                                              #                     )
                                                                                                                                                              #                     if new_text:
                                                                                                                                                              #                         if new_text.find("(") > 0:
                                                                                                                                                              #                             new_text = new_text[0 : new_text.find("(") + 1]
                                                                                                                                                              #                         self.completion_state += 1
                                                                                                                                                              #                         self.selecter.replace_block_at_cursor(new_text)
                                                                                                                                                              #                     else:
                                                                                                                                                              #                         self.completion_state = 0
                                                                                                                                                              #                         self.selecter.replace_block_at_cursor(self._orig_text)
                                                                                                                                                              #                         self._orig_text == None
                                                                                                                                                              #                 self.completing = False
                                                                                                                                                              #         case _:
                                                                                                                                                              #             return super().keyPressEvent(event)
                                                                                                                                                          
                                                                                                                                                              # def reset_completion(self):
                                                                                                                                                              #     if not self.completing:
                                                                                                                                                              #         self.completion_state = 0
                                                                                                                                                          
                                                                                                                                                              # def is_start(self) -> bool:
                                                                                                                                                              #     temp_cursor = self.textCursor()
                                                                                                                                                              #     if temp_cursor.positionInBlock() == 0:
                                                                                                                                                              #         return True
                                                                                                                                                              #     start_text = temp_cursor.block().text()[0 : temp_cursor.positionInBlock()]
                                                                                                                                                              #     delim = set(self.delimiter)
                                                                                                                                                              #     return set(start_text) - delim == set()
                                                                                                                                                          
                                                                                                                                                              def set_syntaxhighlighter(
                                                                                                                                                                  self,
                                                                                                                                                                  syntax: str | gui.QSyntaxHighlighter,
                                                                                                                                                                  style: syntaxhighlighters.pygmentshighlighter.StyleStr | None = None,
                                                                                                                                                              ):
                                                                                                                                                                  """Set the highlighter; the previous one is detached from the document."""
                                                                                                                                                                  old = getattr(self, "_hl", None)
                                                                                                                                                                  if old is not None and old is not syntax:
                                                                                                                                                                      old.setDocument(None)
                                                                                                                                                                      old.deleteLater()
                                                                                                                                                                  super().set_syntaxhighlighter(syntax, style)
                                                                                                                                                          
                                                                                                                                                              def set_text(self, text: str, *, keep_position: bool = True):
                                                                                                                                                                  """Set the text.
                                                                                                                                                          
                                                                                                                                                                  Args:
                                                                                                                                                                      text: new text
                                                                                                                                                                      keep_position: keep cursor position, selection and scroll position, and
                                                                                                                                                                                     make the change undoable (instead of resetting the document)
                                                                                                                                                                  """
                                                                                                                                                                  if not keep_position:
                                                                                                                                                                      self.setPlainText(text)
                                                                                                                                                                      return
                                                                                                                                                                  if text == self.toPlainText():
                                                                                                                                                                      return
                                                                                                                                                                  cursor = self.textCursor()
                                                                                                                                                                  anchor, position = cursor.anchor(), cursor.position()
                                                                                                                                                                  h_value = self.horizontalScrollBar().value()
                                                                                                                                                                  v_value = self.verticalScrollBar().value()
                                                                                                                                                                  edit_cursor = gui.QTextCursor(self.document())
                                                                                                                                                                  edit_cursor.beginEditBlock()
                                                                                                                                                                  edit_cursor.select(gui.QTextCursor.SelectionType.Document)
                                                                                                                                                                  edit_cursor.insertText(text)
                                                                                                                                                                  edit_cursor.endEditBlock()
                                                                                                                                                                  last = max(len(text), 0)
                                                                                                                                                                  cursor = self.textCursor()
                                                                                                                                                                  cursor.setPosition(min(anchor, last))
                                                                                                                                                                  cursor.setPosition(min(position, last), gui.QTextCursor.MoveMode.KeepAnchor)
                                                                                                                                                                  self.setTextCursor(cursor)
                                                                                                                                                                  self.verticalScrollBar().setValue(v_value)
                                                                                                                                                                  self.horizontalScrollBar().setValue(h_value)
                                                                                                                                                          
                                                                                                                                                              def set_value(self, value: str):
                                                                                                                                                                  self.set_text(value)
                                                                                                                                                          
                                                                                                                                                              # --- line markers -----------------------------------------------------
                                                                                                                                                          
                                                                                                                                                              def add_line_marker(self, line: int, message: str, kind: MarkerKindStr = "error"):
                                                                                                                                                                  """Attach a message to a line (1-based line number)."""
                                                                                                                                                                  if kind not in MARKER_COLORS:
                                                                                                                                                                      msg = f"Invalid marker kind {kind!r}"
                                                                                                                                                                      raise ValueError(msg)
                                                                                                                                                                  self._markers.setdefault(line, []).append(LineMarker(line, message, kind))
                                                                                                                                                                  self._update_markers()
                                                                                                                                                          
                                                                                                                                                              def set_line_markers(
                                                                                                                                                                  self,
                                                                                                                                                                  markers: Mapping[int, str] | Iterable[LineMarker | tuple[int, str]],
                                                                                                                                                                  kind: MarkerKindStr = "error",
                                                                                                                                                              ):
                                                                                                                                                                  """Replace all markers.
                                                                                                                                                          
                                                                                                                                                                  Args:
                                                                                                                                                                      markers: {line: message}, LineMarkers or (line, message) tuples
                                                                                                                                                                      kind: kind for markers given as mapping / tuples
                                                                                                                                                                  """
                                                                                                                                                                  self._markers.clear()
                                                                                                                                                                  if isinstance(markers, Mapping):
                                                                                                                                                                      items: Iterable[LineMarker | tuple[int, str]] = cast(
                                                                                                                                                                          "Mapping[int, str]", markers
                                                                                                                                                                      ).items()
                                                                                                                                                                  else:
                                                                                                                                                                      items = markers
                                                                                                                                                                  for item in items:
                                                                                                                                                                      if isinstance(item, LineMarker):
                                                                                                                                                                          marker = item
                                                                                                                                                                      else:
                                                                                                                                                                          marker = LineMarker(item[0], item[1], kind)
                                                                                                                                                                      self._markers.setdefault(marker.line, []).append(marker)
                                                                                                                                                                  self._update_markers()
                                                                                                                                                          
                                                                                                                                                              def clear_line_markers(self, line: int | None = None):
                                                                                                                                                                  """Remove the markers of a line, or all markers."""
                                                                                                                                                                  if line is None:
                                                                                                                                                                      self._markers.clear()
                                                                                                                                                                  else:
                                                                                                                                                                      self._markers.pop(line, None)
                                                                                                                                                                  self._update_markers()
                                                                                                                                                          
                                                                                                                                                              def get_line_markers(self) -> list[LineMarker]:
                                                                                                                                                                  return [m for line in sorted(self._markers) for m in self._markers[line]]
                                                                                                                                                          
                                                                                                                                                              def get_line_marker_text(self, line: int) -> str:
                                                                                                                                                                  """Return the messages of a line, one per row ("" if none)."""
                                                                                                                                                                  return "\n".join(m.message for m in self._markers.get(line, []))
                                                                                                                                                          
                                                                                                                                                              def _marker_color(self, line: int, alpha: int) -> gui.Color | None:
                                                                                                                                                                  if not (markers := self._markers.get(line)):
                                                                                                                                                                      return None
                                                                                                                                                                  kind = min((m.kind for m in markers), key=list(MARKER_COLORS).index)
                                                                                                                                                                  return gui.Color(*MARKER_COLORS[kind], alpha)
                                                                                                                                                          
                                                                                                                                                              def _update_markers(self):
                                                                                                                                                                  selections = []
                                                                                                                                                                  doc = self.document()
                                                                                                                                                                  for line in sorted(self._markers):
                                                                                                                                                                      block = doc.findBlockByNumber(line - 1)
                                                                                                                                                                      if not block.isValid():
                                                                                                                                                                          continue
                                                                                                                                                                      selection = widgets.QTextEdit.ExtraSelection()
                                                                                                                                                                      selection.format.setBackground(self._marker_color(line, 50))
                                                                                                                                                                      prop = gui.QTextFormat.Property.FullWidthSelection
                                                                                                                                                                      selection.format.setProperty(prop, True)
                                                                                                                                                                      selection.cursor = gui.QTextCursor(block)
                                                                                                                                                                      selections.append(selection)
                                                                                                                                                                  self.setExtraSelections(selections)
                                                                                                                                                                  self.line_area.update()
                                                                                                                                                          
                                                                                                                                                              def _line_at(self, y: int) -> int | None:
                                                                                                                                                                  block = self.firstVisibleBlock()
                                                                                                                                                                  top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()
                                                                                                                                                                  while block.isValid():
                                                                                                                                                                      bottom = top + self.blockBoundingRect(block).height()
                                                                                                                                                                      if top <= y < bottom:
                                                                                                                                                                          return block.blockNumber() + 1
                                                                                                                                                                      top = bottom
                                                                                                                                                                      block = block.next()
                                                                                                                                                                  return None
                                                                                                                                                          
                                                                                                                                                              def show_marker_tooltip(self, pos: core.QPoint, global_pos: core.QPoint) -> bool:
                                                                                                                                                                  line = self._line_at(pos.y())
                                                                                                                                                                  if line is None or not (text := self.get_line_marker_text(line)):
                                                                                                                                                                      widgets.ToolTip.hideText()
                                                                                                                                                                      return False
                                                                                                                                                                  widgets.ToolTip.showText(global_pos, text)
                                                                                                                                                                  return True
                                                                                                                                                          
                                                                                                                                                              def viewportEvent(self, event):
                                                                                                                                                                  if event.type() == core.QEvent.Type.ToolTip:
                                                                                                                                                                      self.show_marker_tooltip(event.pos(), event.globalPos())
                                                                                                                                                                      return True
                                                                                                                                                                  return super().viewportEvent(event)
                                                                                                                                                          
                                                                                                                                                              def resizeEvent(self, event):
                                                                                                                                                                  super().resizeEvent(event)
                                                                                                                                                          
                                                                                                                                                                  cr = self.contentsRect()
                                                                                                                                                                  rect = core.Rect(cr.left(), cr.top(), self.line_area_width(), cr.height())
                                                                                                                                                                  self.line_area.setGeometry(rect)
                                                                                                                                                          
                                                                                                                                                              def line_area_width(self) -> int:
                                                                                                                                                                  digits = max(2, len(str(self.blockCount())))
                                                                                                                                                                  return 10 + self.fontMetrics().horizontalAdvance("9") * digits
                                                                                                                                                          
                                                                                                                                                              def update_line_area_width(self, _):
                                                                                                                                                                  self.setViewportMargins(self.line_area_width(), 0, 0, 0)
                                                                                                                                                          
                                                                                                                                                              def update_line_area(self, rect: core.QRect, dy: int):
                                                                                                                                                                  if dy:
                                                                                                                                                                      self.line_area.scroll(0, dy)
                                                                                                                                                                  else:
                                                                                                                                                                      self.line_area.update(0, rect.y(), self.line_area.width(), rect.height())
                                                                                                                                                          
                                                                                                                                                                  if rect.contains(self.viewport().rect()):
                                                                                                                                                                      self.update_line_area_width(0)
                                                                                                                                                          
                                                                                                                                                              def line_area_paintevent(self, event):
                                                                                                                                                                  with gui.Painter(self.line_area) as painter:
                                                                                                                                                                      painter.fill_rect(event.rect(), "lightgray")
                                                                                                                                                          
                                                                                                                                                                      block = self.firstVisibleBlock()
                                                                                                                                                                      block_number = block.blockNumber()
                                                                                                                                                                      top = self.blockBoundingGeometry(block).translated(self.contentOffset()).top()
                                                                                                                                                                      bottom = top + self.blockBoundingRect(block).height()
                                                                                                                                                                      width = self.line_area.width()
                                                                                                                                                                      height = self.fontMetrics().height()
                                                                                                                                                                      painter.set_color("black")
                                                                                                                                                                      while block.isValid() and (top <= event.rect().bottom()):
                                                                                                                                                                          if block.isVisible() and (bottom >= event.rect().top()):
                                                                                                                                                                              number = str(block_number + 1)
                                                                                                                                                                              if color := self._marker_color(block_number + 1, 160):
                                                                                                                                                                                  painter.fill_rect(
                                                                                                                                                                                      core.QRectF(0, top, width, bottom - top).toRect(), color
                                                                                                                                                                                  )
                                                                                                                                                                              painter.drawText(
                                                                                                                                                                                  0, int(top), width - 4, height, constants.ALIGN_RIGHT, number
                                                                                                                                                                              )
                                                                                                                                                                          block = block.next()
                                                                                                                                                                          top = bottom
                                                                                                                                                                          bottom = top + self.blockBoundingRect(block).height()
                                                                                                                                                                          block_number += 1
                                                                                                                                                          

                                                                                                                                                          add_line_marker(line: int, message: str, kind: MarkerKindStr = 'error')

                                                                                                                                                          Attach a message to a line (1-based line number).

                                                                                                                                                          Source code in prettyqt/custom_widgets/codeeditor.py
                                                                                                                                                          def add_line_marker(self, line: int, message: str, kind: MarkerKindStr = "error"):
                                                                                                                                                              """Attach a message to a line (1-based line number)."""
                                                                                                                                                              if kind not in MARKER_COLORS:
                                                                                                                                                                  msg = f"Invalid marker kind {kind!r}"
                                                                                                                                                                  raise ValueError(msg)
                                                                                                                                                              self._markers.setdefault(line, []).append(LineMarker(line, message, kind))
                                                                                                                                                              self._update_markers()
                                                                                                                                                          

                                                                                                                                                          clear_line_markers(line: int | None = None)

                                                                                                                                                          Remove the markers of a line, or all markers.

                                                                                                                                                          Source code in prettyqt/custom_widgets/codeeditor.py
                                                                                                                                                          def clear_line_markers(self, line: int | None = None):
                                                                                                                                                              """Remove the markers of a line, or all markers."""
                                                                                                                                                              if line is None:
                                                                                                                                                                  self._markers.clear()
                                                                                                                                                              else:
                                                                                                                                                                  self._markers.pop(line, None)
                                                                                                                                                              self._update_markers()
                                                                                                                                                          

                                                                                                                                                          get_line_marker_text(line: int) -> str

                                                                                                                                                          Return the messages of a line, one per row ("" if none).

                                                                                                                                                          Source code in prettyqt/custom_widgets/codeeditor.py
                                                                                                                                                          def get_line_marker_text(self, line: int) -> str:
                                                                                                                                                              """Return the messages of a line, one per row ("" if none)."""
                                                                                                                                                              return "\n".join(m.message for m in self._markers.get(line, []))
                                                                                                                                                          

                                                                                                                                                          set_line_markers(markers: Mapping[int, str] | Iterable[LineMarker | tuple[int, str]], kind: MarkerKindStr = 'error')

                                                                                                                                                          Replace all markers.

                                                                                                                                                          Parameters:

                                                                                                                                                          Name Type Description Default
                                                                                                                                                          markers Mapping[int, str] | Iterable[LineMarker | tuple[int, str]]

                                                                                                                                                          {line: message}, LineMarkers or (line, message) tuples

                                                                                                                                                          required
                                                                                                                                                          kind MarkerKindStr

                                                                                                                                                          kind for markers given as mapping / tuples

                                                                                                                                                          'error'
                                                                                                                                                          Source code in prettyqt/custom_widgets/codeeditor.py
                                                                                                                                                          def set_line_markers(
                                                                                                                                                              self,
                                                                                                                                                              markers: Mapping[int, str] | Iterable[LineMarker | tuple[int, str]],
                                                                                                                                                              kind: MarkerKindStr = "error",
                                                                                                                                                          ):
                                                                                                                                                              """Replace all markers.
                                                                                                                                                          
                                                                                                                                                              Args:
                                                                                                                                                                  markers: {line: message}, LineMarkers or (line, message) tuples
                                                                                                                                                                  kind: kind for markers given as mapping / tuples
                                                                                                                                                              """
                                                                                                                                                              self._markers.clear()
                                                                                                                                                              if isinstance(markers, Mapping):
                                                                                                                                                                  items: Iterable[LineMarker | tuple[int, str]] = cast(
                                                                                                                                                                      "Mapping[int, str]", markers
                                                                                                                                                                  ).items()
                                                                                                                                                              else:
                                                                                                                                                                  items = markers
                                                                                                                                                              for item in items:
                                                                                                                                                                  if isinstance(item, LineMarker):
                                                                                                                                                                      marker = item
                                                                                                                                                                  else:
                                                                                                                                                                      marker = LineMarker(item[0], item[1], kind)
                                                                                                                                                                  self._markers.setdefault(marker.line, []).append(marker)
                                                                                                                                                              self._update_markers()
                                                                                                                                                          

                                                                                                                                                          set_syntaxhighlighter(syntax: str | gui.QSyntaxHighlighter, style: syntaxhighlighters.pygmentshighlighter.StyleStr | None = None)

                                                                                                                                                          Set the highlighter; the previous one is detached from the document.

                                                                                                                                                          Source code in prettyqt/custom_widgets/codeeditor.py
                                                                                                                                                          def set_syntaxhighlighter(
                                                                                                                                                              self,
                                                                                                                                                              syntax: str | gui.QSyntaxHighlighter,
                                                                                                                                                              style: syntaxhighlighters.pygmentshighlighter.StyleStr | None = None,
                                                                                                                                                          ):
                                                                                                                                                              """Set the highlighter; the previous one is detached from the document."""
                                                                                                                                                              old = getattr(self, "_hl", None)
                                                                                                                                                              if old is not None and old is not syntax:
                                                                                                                                                                  old.setDocument(None)
                                                                                                                                                                  old.deleteLater()
                                                                                                                                                              super().set_syntaxhighlighter(syntax, style)
                                                                                                                                                          

                                                                                                                                                          set_text(text: str, *, keep_position: bool = True)

                                                                                                                                                          Set the text.

                                                                                                                                                          Parameters:

                                                                                                                                                          Name Type Description Default
                                                                                                                                                          text str

                                                                                                                                                          new text

                                                                                                                                                          required
                                                                                                                                                          keep_position bool

                                                                                                                                                          keep cursor position, selection and scroll position, and make the change undoable (instead of resetting the document)

                                                                                                                                                          True
                                                                                                                                                          Source code in prettyqt/custom_widgets/codeeditor.py
                                                                                                                                                          def set_text(self, text: str, *, keep_position: bool = True):
                                                                                                                                                              """Set the text.
                                                                                                                                                          
                                                                                                                                                              Args:
                                                                                                                                                                  text: new text
                                                                                                                                                                  keep_position: keep cursor position, selection and scroll position, and
                                                                                                                                                                                 make the change undoable (instead of resetting the document)
                                                                                                                                                              """
                                                                                                                                                              if not keep_position:
                                                                                                                                                                  self.setPlainText(text)
                                                                                                                                                                  return
                                                                                                                                                              if text == self.toPlainText():
                                                                                                                                                                  return
                                                                                                                                                              cursor = self.textCursor()
                                                                                                                                                              anchor, position = cursor.anchor(), cursor.position()
                                                                                                                                                              h_value = self.horizontalScrollBar().value()
                                                                                                                                                              v_value = self.verticalScrollBar().value()
                                                                                                                                                              edit_cursor = gui.QTextCursor(self.document())
                                                                                                                                                              edit_cursor.beginEditBlock()
                                                                                                                                                              edit_cursor.select(gui.QTextCursor.SelectionType.Document)
                                                                                                                                                              edit_cursor.insertText(text)
                                                                                                                                                              edit_cursor.endEditBlock()
                                                                                                                                                              last = max(len(text), 0)
                                                                                                                                                              cursor = self.textCursor()
                                                                                                                                                              cursor.setPosition(min(anchor, last))
                                                                                                                                                              cursor.setPosition(min(position, last), gui.QTextCursor.MoveMode.KeepAnchor)
                                                                                                                                                              self.setTextCursor(cursor)
                                                                                                                                                              self.verticalScrollBar().setValue(v_value)
                                                                                                                                                              self.horizontalScrollBar().setValue(h_value)
                                                                                                                                                          

                                                                                                                                                          CollapsibleFrame

                                                                                                                                                          Bases: Frame

                                                                                                                                                          Frame containing another widget which can be collapsed.

                                                                                                                                                          Source code in prettyqt/custom_widgets/collapsibleframe.py
                                                                                                                                                          class CollapsibleFrame(widgets.Frame):
                                                                                                                                                              """Frame containing another widget which can be collapsed."""
                                                                                                                                                          
                                                                                                                                                              expanded = core.Signal()
                                                                                                                                                              collapsed = core.Signal()
                                                                                                                                                          
                                                                                                                                                              def __init__(self, text: str = "", **kwargs):
                                                                                                                                                                  super().__init__(frame_shape="styled_panel", frame_shadow="plain", **kwargs)
                                                                                                                                                                  _layout = self.set_layout("vertical", margin=0, spacing=0)
                                                                                                                                                                  # button
                                                                                                                                                                  self._button = widgets.ToolButton(
                                                                                                                                                                      self,
                                                                                                                                                                      clicked=self.on_button_click,
                                                                                                                                                                      arrow_type="right",
                                                                                                                                                                      auto_raise=False,
                                                                                                                                                                      text=text,
                                                                                                                                                                      visible=True,
                                                                                                                                                                  )
                                                                                                                                                                  self._button.set_style("text_beside_icon")
                                                                                                                                                                  self.set_size_policy("minimum_expanding", "fixed")
                                                                                                                                                                  _layout.addWidget(self._button, 0)
                                                                                                                                                                  # group box
                                                                                                                                                                  self._panel = widgets.Widget(self, visible=False)
                                                                                                                                                                  _layout.addWidget(self._panel)
                                                                                                                                                                  self._panel_layout = self._panel.set_layout("vertical", margin=1, spacing=2)
                                                                                                                                                                  self._is_collapsed = True
                                                                                                                                                          
                                                                                                                                                              def set_title(self, title: str):
                                                                                                                                                                  self._button.set_text(title)
                                                                                                                                                          
                                                                                                                                                              def add_widget(self, widget: widgets.QWidget):
                                                                                                                                                                  self._panel_layout.addWidget(widget)
                                                                                                                                                          
                                                                                                                                                              def remove_widget(self, widget: widgets.QWidget):
                                                                                                                                                                  self._panel_layout.removeWidget(widget)
                                                                                                                                                          
                                                                                                                                                              def is_expanded(self) -> bool:
                                                                                                                                                                  return not self._is_collapsed
                                                                                                                                                          
                                                                                                                                                              def expand(self):
                                                                                                                                                                  self._button.set_arrow_type("down")
                                                                                                                                                                  self._panel.setVisible(True)
                                                                                                                                                                  self._is_collapsed = False
                                                                                                                                                                  self.set_size_policy("minimum_expanding", "minimum_expanding")
                                                                                                                                                          
                                                                                                                                                              def collapse(self):
                                                                                                                                                                  self._panel.setVisible(False)
                                                                                                                                                                  self._button.set_arrow_type("right")
                                                                                                                                                                  self._is_collapsed = True
                                                                                                                                                                  self.set_size_policy("preferred", "preferred")
                                                                                                                                                          
                                                                                                                                                              @core.Slot()
                                                                                                                                                              def on_button_click(self):
                                                                                                                                                                  if self._is_collapsed:
                                                                                                                                                                      self.expand()
                                                                                                                                                                      self.expanded.emit()
                                                                                                                                                                  else:
                                                                                                                                                                      self.collapse()
                                                                                                                                                                      self.collapsed.emit()
                                                                                                                                                          

                                                                                                                                                          CommandPalette

                                                                                                                                                          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.setAutoFillBackground(True)
                                                                                                                                                                  self.setAttribute(constants.WidgetAttribute.WA_StyledBackground, True)
                                                                                                                                                                  self.set_focus_policy("strong")
                                                                                                                                                                  self.setMinimumWidth(420)
                                                                                                                                                                  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)
                                                                                                                                                                  self._table.action_clicked.connect(self.hide)
                                                                                                                                                                  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
                                                                                                                                                                      or not isinstance(e, gui.QKeyEvent)
                                                                                                                                                                  ):
                                                                                                                                                                      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
                                                                                                                                                                  obj: core.QObject | None = widget
                                                                                                                                                                  while (obj := obj.parent()) is not None:
                                                                                                                                                                      if isinstance(obj, widgets.QWidget):
                                                                                                                                                                          self.add_actions(obj.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._proxy.get_match_color().name()
                                                                                                                                                          
                                                                                                                                                              def set_match_color(self, color: datatypes.ColorType):
                                                                                                                                                                  """Set the color used for the matched characters."""
                                                                                                                                                                  self._table._proxy.set_match_color(colors.get_color(color))
                                                                                                                                                          
                                                                                                                                                              def install_to(self, parent: widgets.QWidget):
                                                                                                                                                                  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: Iterable[gui.QAction]):
                                                                                                                                                                  """Append actions to the palette."""
                                                                                                                                                                  self._table._model.add_items(actions)
                                                                                                                                                          
                                                                                                                                                              def set_actions(self, actions: Iterable[gui.QAction]):
                                                                                                                                                                  """Replace all actions of the palette (also refreshes changed action texts)."""
                                                                                                                                                                  self._table._model.set_list(list(actions))
                                                                                                                                                          
                                                                                                                                                              def get_actions(self) -> list[gui.QAction]:
                                                                                                                                                                  """Return the actions of the palette."""
                                                                                                                                                                  return list(self._table._model.items)
                                                                                                                                                          
                                                                                                                                                              def clear(self):
                                                                                                                                                                  """Remove all actions from the palette."""
                                                                                                                                                                  self.set_actions([])
                                                                                                                                                          
                                                                                                                                                              def show(self):
                                                                                                                                                                  self._line.setText("")
                                                                                                                                                                  parent = self.parentWidget()
                                                                                                                                                                  if parent is not None and self.windowType() == constants.WindowType.SubWindow:
                                                                                                                                                                      width = min(680, max(420, parent.width() - 80))
                                                                                                                                                                      height = min(380, max(240, parent.height() - 120))
                                                                                                                                                                      x = max(12, (parent.width() - width) // 2)
                                                                                                                                                                      y = max(36, int(parent.height() * 0.12))
                                                                                                                                                                      self.setGeometry(x, y, width, height)
                                                                                                                                                                  else:
                                                                                                                                                                      self.resize(1000, 300)
                                                                                                                                                                      self.position_on("screen")
                                                                                                                                                                  super().show()
                                                                                                                                                                  self.raise_()
                                                                                                                                                                  self._line.setFocus()
                                                                                                                                                          

                                                                                                                                                          add_actions(actions: Iterable[gui.QAction])

                                                                                                                                                          Append actions to the palette.

                                                                                                                                                          Source code in prettyqt/custom_widgets/commandpalette.py
                                                                                                                                                          def add_actions(self, actions: Iterable[gui.QAction]):
                                                                                                                                                              """Append actions to the palette."""
                                                                                                                                                              self._table._model.add_items(actions)
                                                                                                                                                          

                                                                                                                                                          clear()

                                                                                                                                                          Remove all actions from the palette.

                                                                                                                                                          Source code in prettyqt/custom_widgets/commandpalette.py
                                                                                                                                                          def clear(self):
                                                                                                                                                              """Remove all actions from the palette."""
                                                                                                                                                              self.set_actions([])
                                                                                                                                                          

                                                                                                                                                          get_actions() -> list[gui.QAction]

                                                                                                                                                          Return the actions of the palette.

                                                                                                                                                          Source code in prettyqt/custom_widgets/commandpalette.py
                                                                                                                                                          def get_actions(self) -> list[gui.QAction]:
                                                                                                                                                              """Return the actions of the palette."""
                                                                                                                                                              return list(self._table._model.items)
                                                                                                                                                          

                                                                                                                                                          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._proxy.get_match_color().name()
                                                                                                                                                          

                                                                                                                                                          set_actions(actions: Iterable[gui.QAction])

                                                                                                                                                          Replace all actions of the palette (also refreshes changed action texts).

                                                                                                                                                          Source code in prettyqt/custom_widgets/commandpalette.py
                                                                                                                                                          def set_actions(self, actions: Iterable[gui.QAction]):
                                                                                                                                                              """Replace all actions of the palette (also refreshes changed action texts)."""
                                                                                                                                                              self._table._model.set_list(list(actions))
                                                                                                                                                          

                                                                                                                                                          set_match_color(color: datatypes.ColorType)

                                                                                                                                                          Set the color used for the matched characters.

                                                                                                                                                          Source code in prettyqt/custom_widgets/commandpalette.py
                                                                                                                                                          def set_match_color(self, color: datatypes.ColorType):
                                                                                                                                                              """Set the color used for the matched characters."""
                                                                                                                                                              self._table._proxy.set_match_color(colors.get_color(color))
                                                                                                                                                          

                                                                                                                                                          CrossFadeWidget

                                                                                                                                                          Bases: Widget

                                                                                                                                                          Source code in prettyqt/custom_widgets/crossfadewidget.py
                                                                                                                                                          class CrossFadeWidget(widgets.Widget):
                                                                                                                                                              def __init__(
                                                                                                                                                                  self,
                                                                                                                                                                  pixmap_1: gui.QPixmap | os.PathLike[str] | str | widgets.QWidget | None = None,
                                                                                                                                                                  pixmap_2: gui.QPixmap | os.PathLike[str] | str | widgets.QWidget | None = None,
                                                                                                                                                                  **kwargs,
                                                                                                                                                              ):
                                                                                                                                                                  super().__init__(**kwargs)
                                                                                                                                                                  self.pixmap_1 = None
                                                                                                                                                                  self.pixmap_2 = None
                                                                                                                                                                  self.set_pixmap_1(pixmap_1)
                                                                                                                                                                  self.set_pixmap_2(pixmap_2)
                                                                                                                                                                  self.set_blend_factor(0.0)
                                                                                                                                                                  self.timeline = core.TimeLine(finished=self.close)
                                                                                                                                                                  self.timeline.valueChanged.connect(self.set_blend_factor)
                                                                                                                                                                  self.set_size_policy("fixed", "fixed")
                                                                                                                                                          
                                                                                                                                                              def start_fade(self, duration: int = 500):
                                                                                                                                                                  self.timeline.setDuration(duration)
                                                                                                                                                                  self.timeline.start()
                                                                                                                                                                  # self.show()
                                                                                                                                                          
                                                                                                                                                              def set_pixmap_1(
                                                                                                                                                                  self, pixmap: gui.QPixmap | os.PathLike[str] | str | widgets.QWidget | None
                                                                                                                                                              ):
                                                                                                                                                                  self.pixmap_1 = self._get_pixmap(pixmap)
                                                                                                                                                                  self.updateGeometry()
                                                                                                                                                                  self.repaint()
                                                                                                                                                          
                                                                                                                                                              def set_pixmap_2(
                                                                                                                                                                  self, pixmap: gui.QPixmap | os.PathLike[str] | str | widgets.QWidget | None
                                                                                                                                                              ):
                                                                                                                                                                  self.pixmap_2 = self._get_pixmap(pixmap)
                                                                                                                                                                  self.updateGeometry()
                                                                                                                                                                  self.repaint()
                                                                                                                                                          
                                                                                                                                                              @staticmethod
                                                                                                                                                              def _get_pixmap(
                                                                                                                                                                  pixmap: gui.QPixmap | os.PathLike[str] | str | widgets.QWidget | None,
                                                                                                                                                              ):
                                                                                                                                                                  match pixmap:
                                                                                                                                                                      case gui.QPixmap():
                                                                                                                                                                          return pixmap
                                                                                                                                                                      case os.PathLike() | str():
                                                                                                                                                                          return gui.Pixmap(os.fspath(pixmap))
                                                                                                                                                                      case widgets.QWidget():
                                                                                                                                                                          return pixmap.grab()
                                                                                                                                                                      case None:
                                                                                                                                                                          return gui.Pixmap()
                                                                                                                                                          
                                                                                                                                                              def set_blend_factor(self, factor: float):
                                                                                                                                                                  self._blend_factor = factor
                                                                                                                                                                  self.repaint()
                                                                                                                                                          
                                                                                                                                                              def get_blend_factor(self) -> float:
                                                                                                                                                                  """Pixmap blending factor between 0.0 and 1.0."""
                                                                                                                                                                  return self._blend_factor
                                                                                                                                                          
                                                                                                                                                              def sizeHint(self):
                                                                                                                                                                  """Return max size of both."""
                                                                                                                                                                  size1 = self.pixmap_1.size() if self.pixmap_1 else super().sizeHint()
                                                                                                                                                                  size2 = self.pixmap_2.size() if self.pixmap_2 else super().sizeHint()
                                                                                                                                                                  return size1.expandedTo(size2)
                                                                                                                                                          
                                                                                                                                                              def paintEvent(self, event):
                                                                                                                                                                  """Paint the interpolated pixmap image."""
                                                                                                                                                                  with gui.Painter(self) as p:
                                                                                                                                                                      p.setClipRect(event.rect())
                                                                                                                                                                      factor = self.get_blend_factor() ** 2
                                                                                                                                                                      if self.pixmap_1 and 1.0 - factor:
                                                                                                                                                                          p.setOpacity(1.0 - factor)
                                                                                                                                                                          p.drawPixmap(core.Point(0, 0), self.pixmap_1)
                                                                                                                                                                      if self.pixmap_2 and factor:
                                                                                                                                                                          p.setOpacity(factor)
                                                                                                                                                                          p.drawPixmap(core.Point(0, 0), self.pixmap_2)
                                                                                                                                                          
                                                                                                                                                              blend_factor = core.Property(
                                                                                                                                                                  float,
                                                                                                                                                                  get_blend_factor,
                                                                                                                                                                  set_blend_factor,
                                                                                                                                                                  doc="Blend factor between the two pixmaps.",
                                                                                                                                                              )
                                                                                                                                                          

                                                                                                                                                          get_blend_factor() -> float

                                                                                                                                                          Pixmap blending factor between 0.0 and 1.0.

                                                                                                                                                          Source code in prettyqt/custom_widgets/crossfadewidget.py
                                                                                                                                                          def get_blend_factor(self) -> float:
                                                                                                                                                              """Pixmap blending factor between 0.0 and 1.0."""
                                                                                                                                                              return self._blend_factor
                                                                                                                                                          

                                                                                                                                                          paintEvent(event)

                                                                                                                                                          Paint the interpolated pixmap image.

                                                                                                                                                          Source code in prettyqt/custom_widgets/crossfadewidget.py
                                                                                                                                                          def paintEvent(self, event):
                                                                                                                                                              """Paint the interpolated pixmap image."""
                                                                                                                                                              with gui.Painter(self) as p:
                                                                                                                                                                  p.setClipRect(event.rect())
                                                                                                                                                                  factor = self.get_blend_factor() ** 2
                                                                                                                                                                  if self.pixmap_1 and 1.0 - factor:
                                                                                                                                                                      p.setOpacity(1.0 - factor)
                                                                                                                                                                      p.drawPixmap(core.Point(0, 0), self.pixmap_1)
                                                                                                                                                                  if self.pixmap_2 and factor:
                                                                                                                                                                      p.setOpacity(factor)
                                                                                                                                                                      p.drawPixmap(core.Point(0, 0), self.pixmap_2)
                                                                                                                                                          

                                                                                                                                                          sizeHint()

                                                                                                                                                          Return max size of both.

                                                                                                                                                          Source code in prettyqt/custom_widgets/crossfadewidget.py
                                                                                                                                                          def sizeHint(self):
                                                                                                                                                              """Return max size of both."""
                                                                                                                                                              size1 = self.pixmap_1.size() if self.pixmap_1 else super().sizeHint()
                                                                                                                                                              size2 = self.pixmap_2.size() if self.pixmap_2 else super().sizeHint()
                                                                                                                                                              return size1.expandedTo(size2)
                                                                                                                                                          

                                                                                                                                                          EnumComboBox

                                                                                                                                                          Bases: ComboBox

                                                                                                                                                          ComboBox presenting options from a python Enum.

                                                                                                                                                          If the Enum class does not implement __str__ then a human readable name is created from the name of the enum member, replacing underscores with spaces.

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/enumcombobox.py
                                                                                                                                                          class EnumComboBox(widgets.ComboBox):
                                                                                                                                                              """ComboBox presenting options from a python Enum.
                                                                                                                                                          
                                                                                                                                                              If the Enum class does not implement `__str__` then a human readable name
                                                                                                                                                              is created from the name of the enum member, replacing underscores with spaces.
                                                                                                                                                              """
                                                                                                                                                          
                                                                                                                                                              # current_enum_changed = core.Signal(object)
                                                                                                                                                              value_changed = core.Signal(object)
                                                                                                                                                          
                                                                                                                                                              def __init__(self, value=None, object_name: str = "enum_combobox", **kwargs):
                                                                                                                                                                  self._enum_class: type[enum.Enum] | None = None
                                                                                                                                                                  self._allow_none = False
                                                                                                                                                                  super().__init__(object_name=object_name, **kwargs)
                                                                                                                                                                  if value is not None:
                                                                                                                                                                      self.set_value(value)
                                                                                                                                                                  # self.currentIndexChanged.connect(self._emit_signal)
                                                                                                                                                          
                                                                                                                                                              def __repr__(self):
                                                                                                                                                                  return get_repr(self, self.get_value())
                                                                                                                                                          
                                                                                                                                                              def set_allow_none(self, value: bool):
                                                                                                                                                                  self._allow_none = value
                                                                                                                                                          
                                                                                                                                                              def is_none_allowed(self) -> bool:
                                                                                                                                                                  return self._allow_none
                                                                                                                                                          
                                                                                                                                                              def _set_enum_class(self, enum: type[enum.Enum] | None):
                                                                                                                                                                  """Set enum class from which members value should be selected."""
                                                                                                                                                                  if enum == self._enum_class:
                                                                                                                                                                      return
                                                                                                                                                                  self._enum_class = enum
                                                                                                                                                                  super().clear()
                                                                                                                                                                  if self._enum_class is None:
                                                                                                                                                                      return
                                                                                                                                                                  if self._allow_none:
                                                                                                                                                                      super().addItem(NONE_STRING)
                                                                                                                                                                  items = [i.name.replace("_", " ") for i in self._enum_class.__members__.values()]
                                                                                                                                                                  super().addItems(items)
                                                                                                                                                          
                                                                                                                                                              def get_enum_class(self) -> type[enum.Enum] | None:
                                                                                                                                                                  """Return current Enum class."""
                                                                                                                                                                  return self._enum_class
                                                                                                                                                          
                                                                                                                                                              def is_optional(self) -> bool:
                                                                                                                                                                  """Return if current enum is with optional annotation."""
                                                                                                                                                                  return self._allow_none
                                                                                                                                                          
                                                                                                                                                              def clear(self):
                                                                                                                                                                  self._enum_class = None
                                                                                                                                                                  self._allow_none = False
                                                                                                                                                                  super().clear()
                                                                                                                                                          
                                                                                                                                                              def get_value(self) -> enum.Enum | None:
                                                                                                                                                                  """Current value as Enum member."""
                                                                                                                                                                  if self._enum_class is None:
                                                                                                                                                                      return None
                                                                                                                                                                  class_members = list(self._enum_class.__members__.values())
                                                                                                                                                                  if not self._allow_none:
                                                                                                                                                                      return class_members[self.currentIndex()]
                                                                                                                                                                  is_none = self.currentText() == NONE_STRING
                                                                                                                                                                  return None if is_none else class_members[self.currentIndex() - 1]
                                                                                                                                                          
                                                                                                                                                              def set_value(self, value: enum.Enum | None) -> None:
                                                                                                                                                                  """Set value with Enum."""
                                                                                                                                                                  if value is None:
                                                                                                                                                                      if not self._allow_none:
                                                                                                                                                                          raise ValueError(value)
                                                                                                                                                                      self.setCurrentIndex(0)
                                                                                                                                                                      return
                                                                                                                                                                  if not isinstance(value, enum.Enum):
                                                                                                                                                                      if self._enum_class is None:
                                                                                                                                                                          raise ValueError(value)
                                                                                                                                                                      value = self._enum_class(value)
                                                                                                                                                                  self._set_enum_class(value.__class__)
                                                                                                                                                                  self.setCurrentText(value.name.replace("_", " "))
                                                                                                                                                          
                                                                                                                                                              # def _emit_signal(self):
                                                                                                                                                              #     if self._enum_class is not None:
                                                                                                                                                              #         self.current_enum_changed.emit(self.get_value())
                                                                                                                                                          
                                                                                                                                                              allowNone = core.Property(  # noqa: N815
                                                                                                                                                                  bool,
                                                                                                                                                                  is_none_allowed,
                                                                                                                                                                  set_allow_none,
                                                                                                                                                                  doc="Whether None is allowed as a value",
                                                                                                                                                              )
                                                                                                                                                              enumValue = core.Property(  # noqa: N815
                                                                                                                                                                  enum.Enum,
                                                                                                                                                                  get_value,
                                                                                                                                                                  set_value,
                                                                                                                                                                  user=True,
                                                                                                                                                                  doc="Currently chosen value",
                                                                                                                                                              )
                                                                                                                                                          

                                                                                                                                                          get_enum_class() -> type[enum.Enum] | None

                                                                                                                                                          Return current Enum class.

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/enumcombobox.py
                                                                                                                                                          def get_enum_class(self) -> type[enum.Enum] | None:
                                                                                                                                                              """Return current Enum class."""
                                                                                                                                                              return self._enum_class
                                                                                                                                                          

                                                                                                                                                          get_value() -> enum.Enum | None

                                                                                                                                                          Current value as Enum member.

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/enumcombobox.py
                                                                                                                                                          def get_value(self) -> enum.Enum | None:
                                                                                                                                                              """Current value as Enum member."""
                                                                                                                                                              if self._enum_class is None:
                                                                                                                                                                  return None
                                                                                                                                                              class_members = list(self._enum_class.__members__.values())
                                                                                                                                                              if not self._allow_none:
                                                                                                                                                                  return class_members[self.currentIndex()]
                                                                                                                                                              is_none = self.currentText() == NONE_STRING
                                                                                                                                                              return None if is_none else class_members[self.currentIndex() - 1]
                                                                                                                                                          

                                                                                                                                                          is_optional() -> bool

                                                                                                                                                          Return if current enum is with optional annotation.

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/enumcombobox.py
                                                                                                                                                          def is_optional(self) -> bool:
                                                                                                                                                              """Return if current enum is with optional annotation."""
                                                                                                                                                              return self._allow_none
                                                                                                                                                          

                                                                                                                                                          set_value(value: enum.Enum | None) -> None

                                                                                                                                                          Set value with Enum.

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/enumcombobox.py
                                                                                                                                                          def set_value(self, value: enum.Enum | None) -> None:
                                                                                                                                                              """Set value with Enum."""
                                                                                                                                                              if value is None:
                                                                                                                                                                  if not self._allow_none:
                                                                                                                                                                      raise ValueError(value)
                                                                                                                                                                  self.setCurrentIndex(0)
                                                                                                                                                                  return
                                                                                                                                                              if not isinstance(value, enum.Enum):
                                                                                                                                                                  if self._enum_class is None:
                                                                                                                                                                      raise ValueError(value)
                                                                                                                                                                  value = self._enum_class(value)
                                                                                                                                                              self._set_enum_class(value.__class__)
                                                                                                                                                              self.setCurrentText(value.name.replace("_", " "))
                                                                                                                                                          

                                                                                                                                                          EnumFlagWidget

                                                                                                                                                          Bases: ToolButton

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/enumflagwidget.py
                                                                                                                                                          class EnumFlagWidget(widgets.ToolButton):
                                                                                                                                                              value_changed = core.Signal(enum.Flag)
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args, object_name: str = "enum_flag_widget", **kwargs):
                                                                                                                                                                  self._enum_class: type[enum.Flag] | None = None
                                                                                                                                                                  self._action_map: dict[enum.Flag, gui.Action] = {}
                                                                                                                                                                  self.button_menu = widgets.Menu(triggered=self._on_menu_click)
                                                                                                                                                                  super().__init__(*args, object_name=object_name, **kwargs)
                                                                                                                                                                  self.setMenu(self.button_menu)
                                                                                                                                                                  self.set_popup_mode("instant")
                                                                                                                                                          
                                                                                                                                                              def _on_menu_click(self):
                                                                                                                                                                  value = self.get_value()
                                                                                                                                                                  if self._enum_class is None or value is None:
                                                                                                                                                                      return
                                                                                                                                                                  values = []
                                                                                                                                                                  for i in self._enum_class.__members__.values():
                                                                                                                                                                      if i.value == 0:
                                                                                                                                                                          continue
                                                                                                                                                                      # self._action_map[i].setChecked(value & i == i)
                                                                                                                                                                      if value & i == i:
                                                                                                                                                                          values.append(i)
                                                                                                                                                                  text = (
                                                                                                                                                                      " | ".join(i.name for i in values if i.name)
                                                                                                                                                                      if values
                                                                                                                                                                      else (self._enum_class(0).name or "")
                                                                                                                                                                  )
                                                                                                                                                                  self.set_text(text)
                                                                                                                                                                  self.value_changed.emit(value)
                                                                                                                                                          
                                                                                                                                                              def clear(self):
                                                                                                                                                                  self._action_map = {}
                                                                                                                                                                  self.button_menu.clear()
                                                                                                                                                          
                                                                                                                                                              def _set_enum_class(self, enum: type[enum.Enum] | None):
                                                                                                                                                                  """Set enum class from which members value should be selected."""
                                                                                                                                                                  if enum == self._enum_class:
                                                                                                                                                                      return
                                                                                                                                                                  if enum is not None and not issubclass(enum, Flag):
                                                                                                                                                                      raise TypeError(enum)
                                                                                                                                                                  self._enum_class = enum
                                                                                                                                                                  self.clear()
                                                                                                                                                                  if self._enum_class is None:
                                                                                                                                                                      return
                                                                                                                                                                  for name, i in self._enum_class.__members__.items():
                                                                                                                                                                      if i.value == 0:
                                                                                                                                                                          continue
                                                                                                                                                                      action = gui.Action(text=name.replace("_", " "), checkable=True)
                                                                                                                                                                      action.setData(i)
                                                                                                                                                                      self._action_map[i] = action
                                                                                                                                                                      self.button_menu.add(action)
                                                                                                                                                          
                                                                                                                                                              def get_enum_class(self) -> type[enum.Flag] | None:
                                                                                                                                                                  """Return current Enum class."""
                                                                                                                                                                  return self._enum_class
                                                                                                                                                          
                                                                                                                                                              def get_value(self) -> enum.Flag | None:
                                                                                                                                                                  """Current value as Enum member."""
                                                                                                                                                                  if self._enum_class is None:
                                                                                                                                                                      return None
                                                                                                                                                                  flag = self._enum_class(0)
                                                                                                                                                                  for k, v in self._action_map.items():
                                                                                                                                                                      if v.isChecked():
                                                                                                                                                                          flag |= k
                                                                                                                                                                  return flag
                                                                                                                                                          
                                                                                                                                                              def set_value(self, value: enum.Flag) -> None:
                                                                                                                                                                  """Set value with Enum."""
                                                                                                                                                                  if not isinstance(value, enum.Flag):
                                                                                                                                                                      if self._enum_class is None:
                                                                                                                                                                          msg = (
                                                                                                                                                                              "setValue(self, Enum): argument 1 has unexpected type "
                                                                                                                                                                              f"{type(value).__name__!r}"
                                                                                                                                                                          )
                                                                                                                                                                          raise TypeError(msg)
                                                                                                                                                                      value = self._enum_class(value)
                                                                                                                                                                  self._set_enum_class(value.__class__)
                                                                                                                                                                  enum_cls = self._enum_class
                                                                                                                                                                  if enum_cls is None or not isinstance(value, enum_cls):
                                                                                                                                                                      msg = (
                                                                                                                                                                          "setValue(self, Enum): argument 1 has unexpected type "
                                                                                                                                                                          f"{type(value).__name__!r}"
                                                                                                                                                                      )
                                                                                                                                                                      raise TypeError(msg)
                                                                                                                                                                  # this filter shouldnt be needed, see https://bugreports.qt.io/browse/PYSIDE-2369
                                                                                                                                                                  values = []
                                                                                                                                                                  for i in enum_cls.__members__.values():
                                                                                                                                                                      if i.value == 0:
                                                                                                                                                                          continue
                                                                                                                                                                      checked = (value & i) == i
                                                                                                                                                                      self._action_map[i].setChecked(checked)
                                                                                                                                                                      if checked:
                                                                                                                                                                          values.append(i)
                                                                                                                                                                  text = (
                                                                                                                                                                      " | ".join(i.name for i in values if i.name)
                                                                                                                                                                      if values
                                                                                                                                                                      else (enum_cls(0).name or "")
                                                                                                                                                                  )
                                                                                                                                                                  self.set_text(text)
                                                                                                                                                          
                                                                                                                                                              value = core.Property(
                                                                                                                                                                  enum.Flag,
                                                                                                                                                                  get_value,
                                                                                                                                                                  set_value,
                                                                                                                                                                  user=True,
                                                                                                                                                                  doc="Currently chosen value",
                                                                                                                                                              )
                                                                                                                                                          

                                                                                                                                                          get_enum_class() -> type[enum.Flag] | None

                                                                                                                                                          Return current Enum class.

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/enumflagwidget.py
                                                                                                                                                          def get_enum_class(self) -> type[enum.Flag] | None:
                                                                                                                                                              """Return current Enum class."""
                                                                                                                                                              return self._enum_class
                                                                                                                                                          

                                                                                                                                                          get_value() -> enum.Flag | None

                                                                                                                                                          Current value as Enum member.

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/enumflagwidget.py
                                                                                                                                                          def get_value(self) -> enum.Flag | None:
                                                                                                                                                              """Current value as Enum member."""
                                                                                                                                                              if self._enum_class is None:
                                                                                                                                                                  return None
                                                                                                                                                              flag = self._enum_class(0)
                                                                                                                                                              for k, v in self._action_map.items():
                                                                                                                                                                  if v.isChecked():
                                                                                                                                                                      flag |= k
                                                                                                                                                              return flag
                                                                                                                                                          

                                                                                                                                                          set_value(value: enum.Flag) -> None

                                                                                                                                                          Set value with Enum.

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/enumflagwidget.py
                                                                                                                                                          def set_value(self, value: enum.Flag) -> None:
                                                                                                                                                              """Set value with Enum."""
                                                                                                                                                              if not isinstance(value, enum.Flag):
                                                                                                                                                                  if self._enum_class is None:
                                                                                                                                                                      msg = (
                                                                                                                                                                          "setValue(self, Enum): argument 1 has unexpected type "
                                                                                                                                                                          f"{type(value).__name__!r}"
                                                                                                                                                                      )
                                                                                                                                                                      raise TypeError(msg)
                                                                                                                                                                  value = self._enum_class(value)
                                                                                                                                                              self._set_enum_class(value.__class__)
                                                                                                                                                              enum_cls = self._enum_class
                                                                                                                                                              if enum_cls is None or not isinstance(value, enum_cls):
                                                                                                                                                                  msg = (
                                                                                                                                                                      "setValue(self, Enum): argument 1 has unexpected type "
                                                                                                                                                                      f"{type(value).__name__!r}"
                                                                                                                                                                  )
                                                                                                                                                                  raise TypeError(msg)
                                                                                                                                                              # this filter shouldnt be needed, see https://bugreports.qt.io/browse/PYSIDE-2369
                                                                                                                                                              values = []
                                                                                                                                                              for i in enum_cls.__members__.values():
                                                                                                                                                                  if i.value == 0:
                                                                                                                                                                      continue
                                                                                                                                                                  checked = (value & i) == i
                                                                                                                                                                  self._action_map[i].setChecked(checked)
                                                                                                                                                                  if checked:
                                                                                                                                                                      values.append(i)
                                                                                                                                                              text = (
                                                                                                                                                                  " | ".join(i.name for i in values if i.name)
                                                                                                                                                                  if values
                                                                                                                                                                  else (enum_cls(0).name or "")
                                                                                                                                                              )
                                                                                                                                                              self.set_text(text)
                                                                                                                                                          

                                                                                                                                                          FileChooserButton

                                                                                                                                                          Bases: Widget

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/filechooserbutton.py
                                                                                                                                                          class FileChooserButton(widgets.Widget):
                                                                                                                                                              value_changed = core.Signal(pathlib.Path)
                                                                                                                                                          
                                                                                                                                                              def __init__(
                                                                                                                                                                  self,
                                                                                                                                                                  extensions: dict[str, list[str]] | None = None,
                                                                                                                                                                  mode: widgets.filedialog.AcceptModeStr = "save",
                                                                                                                                                                  file_mode: widgets.filedialog.FileModeStr = "existing_files",
                                                                                                                                                                  root: str | pathlib.Path | None = None,
                                                                                                                                                                  object_name: str = "file_chooser_button",
                                                                                                                                                                  **kwargs: Any,
                                                                                                                                                              ):
                                                                                                                                                                  """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
                                                                                                                                                                      object_name: Object name
                                                                                                                                                                      kwargs: kwargs passed to parent
                                                                                                                                                                  """
                                                                                                                                                                  super().__init__(object_name=object_name, **kwargs)
                                                                                                                                                                  self._path: pathlib.Path | None = None
                                                                                                                                                                  self._extensions: dict[str, list[str]] = extensions or {}
                                                                                                                                                                  self.mode = mode
                                                                                                                                                                  self.file_mode = file_mode
                                                                                                                                                                  self.root = root
                                                                                                                                                                  layout = widgets.HBoxLayout(self)
                                                                                                                                                                  layout.set_margin(0)
                                                                                                                                                                  self.lineedit = widgets.LineEdit()
                                                                                                                                                                  self.lineedit.set_read_only()
                                                                                                                                                                  layout.add(self.lineedit)
                                                                                                                                                                  action = gui.Action(triggered=self.open_file)
                                                                                                                                                                  if self.file_mode == "directory":
                                                                                                                                                                      action.set_icon("mdi.folder-outline")
                                                                                                                                                                  else:
                                                                                                                                                                      action.set_icon("mdi.file-outline")
                                                                                                                                                          
                                                                                                                                                                  self.button = widgets.ToolButton()
                                                                                                                                                                  self.button.setDefaultAction(action)
                                                                                                                                                                  layout.add(self.button)
                                                                                                                                                          
                                                                                                                                                              @classmethod
                                                                                                                                                              def supports(cls, instance) -> bool:
                                                                                                                                                                  return isinstance(instance, pathlib.Path)
                                                                                                                                                          
                                                                                                                                                              @core.Slot()
                                                                                                                                                              def open_file(self):
                                                                                                                                                                  dialog = widgets.FileDialog(
                                                                                                                                                                      parent=self,
                                                                                                                                                                      path_id="file_path",
                                                                                                                                                                      mode=self.mode,
                                                                                                                                                                      path=self.root,
                                                                                                                                                                      file_mode=self.file_mode,
                                                                                                                                                                  )
                                                                                                                                                                  if self._extensions:
                                                                                                                                                                      dialog.set_extension_filter(self._extensions)
                                                                                                                                                                  if not dialog.choose():
                                                                                                                                                                      return
                                                                                                                                                                  self.set_path(dialog.selected_file())
                                                                                                                                                                  self.value_changed.emit(self._path)
                                                                                                                                                          
                                                                                                                                                              def set_path(self, path: datatypes.PathType | None):
                                                                                                                                                                  if path is None:
                                                                                                                                                                      self._path = None
                                                                                                                                                                      self.lineedit.set_text("")
                                                                                                                                                                  else:
                                                                                                                                                                      self._path = pathlib.Path(path)
                                                                                                                                                                      self.lineedit.set_text(os.fspath(path))
                                                                                                                                                          
                                                                                                                                                              def get_value(self) -> pathlib.Path | None:
                                                                                                                                                                  return self._path
                                                                                                                                                          
                                                                                                                                                              def set_value(self, value: datatypes.PathType | None):
                                                                                                                                                                  self.set_path(value)
                                                                                                                                                          
                                                                                                                                                              def get_extensions(self) -> dict[str, list[str]]:
                                                                                                                                                                  return self._extensions
                                                                                                                                                          
                                                                                                                                                              def set_extensions(self, extensions: dict[str, list[str]]):
                                                                                                                                                                  self._extensions = extensions
                                                                                                                                                          

                                                                                                                                                          __init__(extensions: dict[str, list[str]] | None = None, mode: widgets.filedialog.AcceptModeStr = 'save', file_mode: widgets.filedialog.FileModeStr = 'existing_files', root: str | pathlib.Path | None = None, object_name: str = 'file_chooser_button', **kwargs: Any)

                                                                                                                                                          Initialize FileChooserButton.

                                                                                                                                                          Parameters:

                                                                                                                                                          Name Type Description Default
                                                                                                                                                          extensions dict[str, list[str]] | None

                                                                                                                                                          dict allowed extensions form: "'name': ['.ext1', '.ext2']"

                                                                                                                                                          None
                                                                                                                                                          mode AcceptModeStr

                                                                                                                                                          Accept mode ("save" or "load")

                                                                                                                                                          'save'
                                                                                                                                                          file_mode FileModeStr

                                                                                                                                                          File mode ("existing_files", "existing_file", "any_file", or "directory")

                                                                                                                                                          'existing_files'
                                                                                                                                                          root str | Path | None

                                                                                                                                                          Root path

                                                                                                                                                          None
                                                                                                                                                          object_name str

                                                                                                                                                          Object name

                                                                                                                                                          'file_chooser_button'
                                                                                                                                                          kwargs Any

                                                                                                                                                          kwargs passed to parent

                                                                                                                                                          {}
                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/filechooserbutton.py
                                                                                                                                                          def __init__(
                                                                                                                                                              self,
                                                                                                                                                              extensions: dict[str, list[str]] | None = None,
                                                                                                                                                              mode: widgets.filedialog.AcceptModeStr = "save",
                                                                                                                                                              file_mode: widgets.filedialog.FileModeStr = "existing_files",
                                                                                                                                                              root: str | pathlib.Path | None = None,
                                                                                                                                                              object_name: str = "file_chooser_button",
                                                                                                                                                              **kwargs: Any,
                                                                                                                                                          ):
                                                                                                                                                              """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
                                                                                                                                                                  object_name: Object name
                                                                                                                                                                  kwargs: kwargs passed to parent
                                                                                                                                                              """
                                                                                                                                                              super().__init__(object_name=object_name, **kwargs)
                                                                                                                                                              self._path: pathlib.Path | None = None
                                                                                                                                                              self._extensions: dict[str, list[str]] = extensions or {}
                                                                                                                                                              self.mode = mode
                                                                                                                                                              self.file_mode = file_mode
                                                                                                                                                              self.root = root
                                                                                                                                                              layout = widgets.HBoxLayout(self)
                                                                                                                                                              layout.set_margin(0)
                                                                                                                                                              self.lineedit = widgets.LineEdit()
                                                                                                                                                              self.lineedit.set_read_only()
                                                                                                                                                              layout.add(self.lineedit)
                                                                                                                                                              action = gui.Action(triggered=self.open_file)
                                                                                                                                                              if self.file_mode == "directory":
                                                                                                                                                                  action.set_icon("mdi.folder-outline")
                                                                                                                                                              else:
                                                                                                                                                                  action.set_icon("mdi.file-outline")
                                                                                                                                                          
                                                                                                                                                              self.button = widgets.ToolButton()
                                                                                                                                                              self.button.setDefaultAction(action)
                                                                                                                                                              layout.add(self.button)
                                                                                                                                                          

                                                                                                                                                          FileTree

                                                                                                                                                          Bases: TreeView

                                                                                                                                                          Source code in prettyqt/custom_widgets/itemviews/filetree.py
                                                                                                                                                          class FileTree(widgets.TreeView):
                                                                                                                                                              def __init__(self, *args, filters: list[str] | None = None, **kwargs):
                                                                                                                                                                  super().__init__(*args, **kwargs)
                                                                                                                                                                  self.setRootIsDecorated(True)
                                                                                                                                                                  self.setup_dragdrop_move()
                                                                                                                                                                  self._model = widgets.FileSystemModel()
                                                                                                                                                                  self._model.resolve_sym_links(False)
                                                                                                                                                                  if filters:
                                                                                                                                                                      self._model.set_name_filters(filters, hide=False)
                                                                                                                                                                  self.set_model(self._model)
                                                                                                                                                                  self._expanded_ids: list[str] = []
                                                                                                                                                          
                                                                                                                                                              def get_expanded_state(self, root_index: core.ModelIndex | None = None) -> list[str]:
                                                                                                                                                                  """Get a list of all expanded paths.
                                                                                                                                                          
                                                                                                                                                                  Can be used to re-expand to the same state.
                                                                                                                                                                  """
                                                                                                                                                                  root = root_index or self.rootIndex()
                                                                                                                                                                  model = self.model()
                                                                                                                                                                  self._expanded_ids = []
                                                                                                                                                          
                                                                                                                                                                  def _save_expanded_on_level(index: core.ModelIndex):
                                                                                                                                                                      if not self.isExpanded(index):
                                                                                                                                                                          return
                                                                                                                                                                      if index.isValid():
                                                                                                                                                                          path = model.data(index, self._model.Roles.FilePathRole)
                                                                                                                                                                          self._expanded_ids.append(path)
                                                                                                                                                                      for i in range(model.rowCount(index)):
                                                                                                                                                                          val = model.index(i, 0, index)
                                                                                                                                                                          _save_expanded_on_level(val)
                                                                                                                                                          
                                                                                                                                                                  for i in range(model.rowCount(root)):
                                                                                                                                                                      _save_expanded_on_level(model.index(i, 0, root))
                                                                                                                                                                  return self._expanded_ids
                                                                                                                                                          
                                                                                                                                                              def set_expanded_state(
                                                                                                                                                                  self, state: list[str], root_index: core.ModelIndex | None = None
                                                                                                                                                              ):
                                                                                                                                                                  """Set all indexes which correspond to given paths to expanded."""
                                                                                                                                                                  root = root_index or self.rootIndex()
                                                                                                                                                                  model = self.model()
                                                                                                                                                                  self._expanded_ids = state
                                                                                                                                                          
                                                                                                                                                                  def _restore_expanded_on_level(index: core.ModelIndex):
                                                                                                                                                                      model = self._model
                                                                                                                                                                      path = index.data(model.Roles.FilePathRole)
                                                                                                                                                                      if path not in self._expanded_ids:
                                                                                                                                                                          return
                                                                                                                                                                      self.setExpanded(index, True)
                                                                                                                                                                      if not model.hasChildren(index):
                                                                                                                                                                          return
                                                                                                                                                                      path = pathlib.Path(path)
                                                                                                                                                                      for it in path.iterdir():
                                                                                                                                                                          child_index = model.index(str(path / it))
                                                                                                                                                                          _restore_expanded_on_level(child_index)
                                                                                                                                                          
                                                                                                                                                                  with self.updates_off():
                                                                                                                                                                      for i in range(model.rowCount(root)):
                                                                                                                                                                          _restore_expanded_on_level(model.index(i, 0, root))
                                                                                                                                                          
                                                                                                                                                              def set_root_path(self, path: datatypes.PathType):
                                                                                                                                                                  """Set tree rootpath to given path."""
                                                                                                                                                                  path = os.fspath(path)
                                                                                                                                                                  self._model.set_root_path(path)
                                                                                                                                                                  index = self._model.index(path)
                                                                                                                                                                  self.setRootIndex(index)
                                                                                                                                                          

                                                                                                                                                          get_expanded_state(root_index: core.ModelIndex | None = None) -> list[str]

                                                                                                                                                          Get a list of all expanded paths.

                                                                                                                                                          Can be used to re-expand to the same state.

                                                                                                                                                          Source code in prettyqt/custom_widgets/itemviews/filetree.py
                                                                                                                                                          def get_expanded_state(self, root_index: core.ModelIndex | None = None) -> list[str]:
                                                                                                                                                              """Get a list of all expanded paths.
                                                                                                                                                          
                                                                                                                                                              Can be used to re-expand to the same state.
                                                                                                                                                              """
                                                                                                                                                              root = root_index or self.rootIndex()
                                                                                                                                                              model = self.model()
                                                                                                                                                              self._expanded_ids = []
                                                                                                                                                          
                                                                                                                                                              def _save_expanded_on_level(index: core.ModelIndex):
                                                                                                                                                                  if not self.isExpanded(index):
                                                                                                                                                                      return
                                                                                                                                                                  if index.isValid():
                                                                                                                                                                      path = model.data(index, self._model.Roles.FilePathRole)
                                                                                                                                                                      self._expanded_ids.append(path)
                                                                                                                                                                  for i in range(model.rowCount(index)):
                                                                                                                                                                      val = model.index(i, 0, index)
                                                                                                                                                                      _save_expanded_on_level(val)
                                                                                                                                                          
                                                                                                                                                              for i in range(model.rowCount(root)):
                                                                                                                                                                  _save_expanded_on_level(model.index(i, 0, root))
                                                                                                                                                              return self._expanded_ids
                                                                                                                                                          

                                                                                                                                                          set_expanded_state(state: list[str], root_index: core.ModelIndex | None = None)

                                                                                                                                                          Set all indexes which correspond to given paths to expanded.

                                                                                                                                                          Source code in prettyqt/custom_widgets/itemviews/filetree.py
                                                                                                                                                          def set_expanded_state(
                                                                                                                                                              self, state: list[str], root_index: core.ModelIndex | None = None
                                                                                                                                                          ):
                                                                                                                                                              """Set all indexes which correspond to given paths to expanded."""
                                                                                                                                                              root = root_index or self.rootIndex()
                                                                                                                                                              model = self.model()
                                                                                                                                                              self._expanded_ids = state
                                                                                                                                                          
                                                                                                                                                              def _restore_expanded_on_level(index: core.ModelIndex):
                                                                                                                                                                  model = self._model
                                                                                                                                                                  path = index.data(model.Roles.FilePathRole)
                                                                                                                                                                  if path not in self._expanded_ids:
                                                                                                                                                                      return
                                                                                                                                                                  self.setExpanded(index, True)
                                                                                                                                                                  if not model.hasChildren(index):
                                                                                                                                                                      return
                                                                                                                                                                  path = pathlib.Path(path)
                                                                                                                                                                  for it in path.iterdir():
                                                                                                                                                                      child_index = model.index(str(path / it))
                                                                                                                                                                      _restore_expanded_on_level(child_index)
                                                                                                                                                          
                                                                                                                                                              with self.updates_off():
                                                                                                                                                                  for i in range(model.rowCount(root)):
                                                                                                                                                                      _restore_expanded_on_level(model.index(i, 0, root))
                                                                                                                                                          

                                                                                                                                                          set_root_path(path: datatypes.PathType)

                                                                                                                                                          Set tree rootpath to given path.

                                                                                                                                                          Source code in prettyqt/custom_widgets/itemviews/filetree.py
                                                                                                                                                          def set_root_path(self, path: datatypes.PathType):
                                                                                                                                                              """Set tree rootpath to given path."""
                                                                                                                                                              path = os.fspath(path)
                                                                                                                                                              self._model.set_root_path(path)
                                                                                                                                                              index = self._model.index(path)
                                                                                                                                                              self.setRootIndex(index)
                                                                                                                                                          

                                                                                                                                                          FilterHeader

                                                                                                                                                          Bases: HeaderView

                                                                                                                                                          A HeaderView subclass which includes widgets with filter possibilities.

                                                                                                                                                          When setting the header view on an ItemView, a proxy model will be created which is linked to the filter widgets. The correct filter widget is automatically inferred from the content of the columns.

                                                                                                                                                          So basically everything that needs to be done is the following:

                                                                                                                                                          model = MyModel()
                                                                                                                                                          widget = widgets.TableView()
                                                                                                                                                          widget.set_model(model)
                                                                                                                                                          widget.h_header = custom_widgets.FilterHeader()  # same as setHorizontalHeader()
                                                                                                                                                          

                                                                                                                                                          and you will get filter capabilities for your table.

                                                                                                                                                          !!! note Since the FilterHeader will infer the column content type based on the first few rows, it will only work correctly for tables with homogenous data.

                                                                                                                                                          ![Image title](../../images/filterheader.png)
                                                                                                                                                          FilterHeader widget
                                                                                                                                                          Source code in prettyqt/custom_widgets/itemviews/filterheader.py
                                                                                                                                                          class FilterHeader(widgets.HeaderView):
                                                                                                                                                              """A HeaderView subclass which includes widgets with filter possibilities.
                                                                                                                                                          
                                                                                                                                                              When setting the header view on an ItemView, a proxy model will be created which is
                                                                                                                                                              linked to the filter widgets.
                                                                                                                                                              The correct filter widget is automatically inferred from the content of the columns.
                                                                                                                                                          
                                                                                                                                                              So basically everything that needs to be done is the following:
                                                                                                                                                          
                                                                                                                                                              ```py
                                                                                                                                                              model = MyModel()
                                                                                                                                                              widget = widgets.TableView()
                                                                                                                                                              widget.set_model(model)
                                                                                                                                                              widget.h_header = custom_widgets.FilterHeader()  # same as setHorizontalHeader()
                                                                                                                                                              ```
                                                                                                                                                          
                                                                                                                                                              and you will get filter capabilities for your table.
                                                                                                                                                          
                                                                                                                                                              !!! note
                                                                                                                                                                  Since the FilterHeader will infer the column content type based on the first few
                                                                                                                                                                  rows, it will only work correctly for tables with homogenous data.
                                                                                                                                                          
                                                                                                                                                              <figure markdown>
                                                                                                                                                                ![Image title](../../images/filterheader.png)
                                                                                                                                                                <figcaption>FilterHeader widget</figcaption>
                                                                                                                                                              </figure>
                                                                                                                                                          
                                                                                                                                                              """
                                                                                                                                                          
                                                                                                                                                              def __init__(self, parent: widgets.TableView | widgets.TreeView):
                                                                                                                                                                  self._editors_visible = False
                                                                                                                                                                  self._editors = []
                                                                                                                                                                  self._proxy: MultiColumnFilterProxyModel = parent.proxifier.get_proxy(  # type: ignore
                                                                                                                                                                      "multi_column_filter",
                                                                                                                                                                      recursive_filtering_enabled=True,
                                                                                                                                                                  )
                                                                                                                                                                  self._padding = 6
                                                                                                                                                                  super().__init__(constants.HORIZONTAL, parent)
                                                                                                                                                                  self.setStretchLastSection(True)
                                                                                                                                                                  # self.setResizeMode(QHeaderView.Stretch)
                                                                                                                                                                  self.setDefaultAlignment(constants.ALIGN_CENTER_LEFT)
                                                                                                                                                                  # self.setSortIndicatorShown(False)
                                                                                                                                                                  self.sectionResized.connect(self._adjust_positions)
                                                                                                                                                                  parent.h_scrollbar.valueChanged.connect(self._adjust_positions)
                                                                                                                                                                  parent.model_changed.connect(self._update_filter_boxes)
                                                                                                                                                                  self._update_filter_boxes()
                                                                                                                                                                  self.updateGeometries()
                                                                                                                                                          
                                                                                                                                                              @classmethod
                                                                                                                                                              def setup_example(cls):
                                                                                                                                                                  w = widgets.TableView()
                                                                                                                                                                  return cls(parent=w)
                                                                                                                                                          
                                                                                                                                                              def are_editors_visible(self) -> bool:
                                                                                                                                                                  return self._editors_visible
                                                                                                                                                          
                                                                                                                                                              def set_editors_visible(self, visible: bool):
                                                                                                                                                                  self._editors_visible = visible
                                                                                                                                                                  for editor in self._editors:
                                                                                                                                                                      editor.setVisible(visible)
                                                                                                                                                                  self.updateGeometries()
                                                                                                                                                          
                                                                                                                                                              def _update_filter_boxes(self):
                                                                                                                                                                  # TODO: deal with column changes by connecting to Model signals.
                                                                                                                                                                  # That way we wouldnt have to update all editors on change.
                                                                                                                                                                  while self._editors:
                                                                                                                                                                      editor = self._editors.pop()
                                                                                                                                                                      editor.deleteLater()
                                                                                                                                                                  self.create_editors()
                                                                                                                                                                  self._adjust_positions()
                                                                                                                                                          
                                                                                                                                                              def create_editors(self):
                                                                                                                                                                  # using parent model here bc we cant guarantee that we are already set to view.
                                                                                                                                                                  parent = self.parent()
                                                                                                                                                                  if not isinstance(parent, widgets.QAbstractItemView):
                                                                                                                                                                      return
                                                                                                                                                                  self._proxy.clear_filters()
                                                                                                                                                                  raw_model = parent.model()
                                                                                                                                                                  if raw_model is None:
                                                                                                                                                                      return
                                                                                                                                                                  model = cast("core.AbstractItemModel", raw_model)
                                                                                                                                                                  for i in range(model.columnCount()):
                                                                                                                                                                      typ = model.get_column_type(i)
                                                                                                                                                                      if typ is bool:
                                                                                                                                                          
                                                                                                                                                                          def set_filter(val, i=i):
                                                                                                                                                                              self._proxy.set_filter_value(i, val, constants.CHECKSTATE_ROLE)
                                                                                                                                                          
                                                                                                                                                                          name = f"filter_combo_{i}"
                                                                                                                                                                          widget = widgets.ComboBox(margin=0, object_name=name, parent=self)
                                                                                                                                                                          widget.add_items(BOOL_ITEMS)
                                                                                                                                                                          widget.value_changed.connect(set_filter)
                                                                                                                                                                      elif typ in [int, float]:
                                                                                                                                                          
                                                                                                                                                                          def set_filter(val, i=i):
                                                                                                                                                                              self._proxy.set_filter_value(i, val)
                                                                                                                                                          
                                                                                                                                                                          name = f"filter_numwidget_{i}"
                                                                                                                                                                          widget = custom_widgets.NumFilterWidget(
                                                                                                                                                                              margin=0, object_name=name, parent=self
                                                                                                                                                                          )
                                                                                                                                                                          widget.filter_changed.connect(set_filter)
                                                                                                                                                                          title = model.headerData(i, constants.HORIZONTAL, constants.DISPLAY_ROLE)
                                                                                                                                                                          widget.lineedit.setPlaceholderText(f"Filter {title}...")
                                                                                                                                                                      elif typ is str:
                                                                                                                                                          
                                                                                                                                                                          def set_filter(val, i=i):
                                                                                                                                                                              self._proxy.set_filter_value(i, val)
                                                                                                                                                          
                                                                                                                                                                          name = f"filter_lineedit_{i}"
                                                                                                                                                                          widget = widgets.LineEdit(margin=0, object_name=name, parent=self)
                                                                                                                                                                          widget.value_changed.connect(set_filter)
                                                                                                                                                                          title = model.headerData(i, constants.HORIZONTAL, constants.DISPLAY_ROLE)
                                                                                                                                                                          widget.setPlaceholderText(f"Filter {title}...")
                                                                                                                                                                      else:
                                                                                                                                                                          widget = widgets.Widget(parent=self)
                                                                                                                                                                      widget.setVisible(self._editors_visible)
                                                                                                                                                                      self._editors.append(widget)
                                                                                                                                                          
                                                                                                                                                              def sizeHint(self) -> core.QSize:
                                                                                                                                                                  size = super().sizeHint()
                                                                                                                                                                  if self._editors:
                                                                                                                                                                      height = self._editors[0].sizeHint().height()
                                                                                                                                                                      size.setHeight(size.height() + height + self._padding)
                                                                                                                                                                  return size
                                                                                                                                                          
                                                                                                                                                              def updateGeometries(self):
                                                                                                                                                                  if self._editors:
                                                                                                                                                                      height = self._editors[0].sizeHint().height()
                                                                                                                                                                      self.setViewportMargins(0, 0, 0, height + self._padding)
                                                                                                                                                                  else:
                                                                                                                                                                      self.setViewportMargins(0, 0, 0, 0)
                                                                                                                                                                  super().updateGeometries()
                                                                                                                                                                  self._adjust_positions()
                                                                                                                                                          
                                                                                                                                                              def _adjust_positions(self):
                                                                                                                                                                  for index, editor in enumerate(self._editors):
                                                                                                                                                                      height = editor.sizeHint().height()
                                                                                                                                                                      compensate_y = 0
                                                                                                                                                                      compensate_x = 0
                                                                                                                                                                      match editor:
                                                                                                                                                                          case widgets.QComboBox():
                                                                                                                                                                              compensate_y = +2
                                                                                                                                                                          case widgets.QPushButton():
                                                                                                                                                                              compensate_y = -1
                                                                                                                                                                          case widgets.QCheckBox():
                                                                                                                                                                              compensate_y = 4
                                                                                                                                                                              compensate_x = 4
                                                                                                                                                                          case widgets.QWidget():
                                                                                                                                                                              compensate_y = -1
                                                                                                                                                                      editor.move(
                                                                                                                                                                          self.sectionPosition(index) - self.offset() + 1 + compensate_x,
                                                                                                                                                                          height + (self._padding // 2) + compensate_y,
                                                                                                                                                                      )
                                                                                                                                                                      editor.resize(self.sectionSize(index), height)
                                                                                                                                                          
                                                                                                                                                              def set_filter_case_sensitive(self, value: bool):
                                                                                                                                                                  self._proxy.set_filter_case_sensitive(value)
                                                                                                                                                          
                                                                                                                                                              def clear_filters(self):
                                                                                                                                                                  for editor in self._editors:
                                                                                                                                                                      editor.clear()
                                                                                                                                                          
                                                                                                                                                              editors_visible = core.Property(
                                                                                                                                                                  bool,
                                                                                                                                                                  are_editors_visible,
                                                                                                                                                                  set_editors_visible,
                                                                                                                                                                  doc="Whether the filter widgets are visible",
                                                                                                                                                              )
                                                                                                                                                          

                                                                                                                                                          FlowLayout

                                                                                                                                                          Bases: Layout

                                                                                                                                                          Layout which adjusts its children based on space available.

                                                                                                                                                          Source code in prettyqt/custom_widgets/layouts/flowlayout.py
                                                                                                                                                          class FlowLayout(widgets.Layout):
                                                                                                                                                              """Layout which adjusts its children based on space available."""
                                                                                                                                                          
                                                                                                                                                              ID = "flow"
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args, **kwargs):
                                                                                                                                                                  super().__init__(*args, **kwargs)
                                                                                                                                                                  self._items = []
                                                                                                                                                          
                                                                                                                                                              def __add__(self, other: widgets.QWidget | widgets.QLayout) -> FlowLayout:
                                                                                                                                                                  if not isinstance(other, widgets.QWidget | widgets.QLayout):
                                                                                                                                                                      raise TypeError
                                                                                                                                                                  self.add(other)
                                                                                                                                                                  return self
                                                                                                                                                          
                                                                                                                                                              def __del__(self):
                                                                                                                                                                  item = self.takeAt(0)
                                                                                                                                                                  while item:
                                                                                                                                                                      item = self.takeAt(0)
                                                                                                                                                          
                                                                                                                                                              def addLayout(self, layout: widgets.QLayout):
                                                                                                                                                                  widget = widgets.Widget()
                                                                                                                                                                  widget.setLayout(layout)
                                                                                                                                                                  self.addWidget(widget)
                                                                                                                                                          
                                                                                                                                                              def addItem(self, item):
                                                                                                                                                                  self._items.append(item)
                                                                                                                                                          
                                                                                                                                                              def itemAt(self, idx: int):
                                                                                                                                                                  if 0 <= idx < len(self._items):
                                                                                                                                                                      return self._items[idx]
                                                                                                                                                                  return None
                                                                                                                                                          
                                                                                                                                                              def takeAt(self, idx: int):
                                                                                                                                                                  if 0 <= idx < len(self._items):
                                                                                                                                                                      return self._items.pop(idx)
                                                                                                                                                                  return None
                                                                                                                                                          
                                                                                                                                                              def count(self):
                                                                                                                                                                  return len(self._items)
                                                                                                                                                          
                                                                                                                                                              def hasHeightForWidth(self):
                                                                                                                                                                  return True
                                                                                                                                                          
                                                                                                                                                              def heightForWidth(self, width):
                                                                                                                                                                  return self._do_layout(core.Rect(0, 0, width, 0), apply_geometry=False)
                                                                                                                                                          
                                                                                                                                                              def setGeometry(self, rect):
                                                                                                                                                                  super().setGeometry(rect)
                                                                                                                                                                  self._do_layout(rect, apply_geometry=True)
                                                                                                                                                          
                                                                                                                                                              def expandingDirections(self):
                                                                                                                                                                  return constants.Orientation(0)
                                                                                                                                                          
                                                                                                                                                              def minimumSize(self):
                                                                                                                                                                  size = core.QSize()
                                                                                                                                                                  for item in self._items:
                                                                                                                                                                      size = size.expandedTo(item.minimumSize())
                                                                                                                                                                  margins = self.contentsMargins()
                                                                                                                                                                  return size + core.QSize(
                                                                                                                                                                      margins.left() + margins.right(), margins.top() + margins.bottom()
                                                                                                                                                                  )
                                                                                                                                                          
                                                                                                                                                              sizeHint = minimumSize  # noqa: N815
                                                                                                                                                          
                                                                                                                                                              def smart_spacing(self, horizontal: bool = True) -> int:
                                                                                                                                                                  p = self.parent()
                                                                                                                                                                  if p is None:
                                                                                                                                                                      return -1
                                                                                                                                                                  if p.isWidgetType():
                                                                                                                                                                      assert isinstance(p, widgets.QWidget)
                                                                                                                                                                      which = (
                                                                                                                                                                          widgets.Style.PixelMetric.PM_LayoutHorizontalSpacing
                                                                                                                                                                          if horizontal
                                                                                                                                                                          else widgets.Style.PixelMetric.PM_LayoutVerticalSpacing
                                                                                                                                                                      )
                                                                                                                                                                      return p.style().pixelMetric(which, None, p)
                                                                                                                                                                  if isinstance(p, widgets.QLayout):
                                                                                                                                                                      return p.spacing()
                                                                                                                                                                  return -1
                                                                                                                                                          
                                                                                                                                                              def _do_layout(self, rect: core.QRect, apply_geometry: bool = False) -> int:
                                                                                                                                                                  erect = rect.marginsRemoved(self.contentsMargins())
                                                                                                                                                                  x, y = erect.x(), erect.y()
                                                                                                                                                          
                                                                                                                                                                  line_height = 0
                                                                                                                                                          
                                                                                                                                                                  def layout_spacing(wid, horizontal: bool = True):
                                                                                                                                                                      if (ans := self.smart_spacing(horizontal)) != -1:
                                                                                                                                                                          return ans
                                                                                                                                                                      if wid is None:
                                                                                                                                                                          return 0
                                                                                                                                                                      return wid.style().layoutSpacing(
                                                                                                                                                                          widgets.SizePolicy.ControlType.PushButton,
                                                                                                                                                                          widgets.SizePolicy.ControlType.PushButton,
                                                                                                                                                                          constants.HORIZONTAL if horizontal else constants.VERTICAL,
                                                                                                                                                                      )
                                                                                                                                                          
                                                                                                                                                                  lines = []
                                                                                                                                                                  current_line = []
                                                                                                                                                                  gmap = {}
                                                                                                                                                                  for item in self._items:
                                                                                                                                                                      isz, wid = item.sizeHint(), item.widget()
                                                                                                                                                                      hs, vs = layout_spacing(wid), layout_spacing(wid, False)
                                                                                                                                                          
                                                                                                                                                                      next_x = x + isz.width() + hs
                                                                                                                                                                      if next_x - hs > erect.right() and line_height > 0:
                                                                                                                                                                          x = erect.x()
                                                                                                                                                                          y = y + line_height + vs
                                                                                                                                                                          next_x = x + isz.width() + hs
                                                                                                                                                                          lines.append((line_height, current_line))
                                                                                                                                                                          current_line = []
                                                                                                                                                                          line_height = 0
                                                                                                                                                                      if apply_geometry:
                                                                                                                                                                          gmap[item] = x, y, isz
                                                                                                                                                                      x = next_x
                                                                                                                                                                      line_height = max(line_height, isz.height())
                                                                                                                                                                      current_line.append((item, isz.height()))
                                                                                                                                                          
                                                                                                                                                                  lines.append((line_height, current_line))
                                                                                                                                                          
                                                                                                                                                                  if apply_geometry:
                                                                                                                                                                      for line_height, items in lines:
                                                                                                                                                                          for item, item_height in items:
                                                                                                                                                                              x, wy, isz = gmap[item]
                                                                                                                                                                              if item_height < line_height:
                                                                                                                                                                                  wy += (line_height - item_height) // 2
                                                                                                                                                                              item.setGeometry(core.Rect(core.Point(x, wy), isz))
                                                                                                                                                          
                                                                                                                                                                  return y + line_height - rect.y() + self.contentsMargins().bottom()
                                                                                                                                                          

                                                                                                                                                          IconBrowser

                                                                                                                                                          Bases: MainWindow

                                                                                                                                                          A small browser window that allows the user to search through all icons.

                                                                                                                                                          You can also copy the name and python code for the currently selected icon.

                                                                                                                                                          Source code in prettyqt/custom_widgets/iconbrowser.py
                                                                                                                                                          class IconBrowser(widgets.MainWindow):
                                                                                                                                                              """A small browser window that allows the user to search through all icons.
                                                                                                                                                          
                                                                                                                                                              You can also copy the name and python code for the currently selected icon.
                                                                                                                                                              """
                                                                                                                                                          
                                                                                                                                                              def __init__(self):
                                                                                                                                                                  super().__init__()
                                                                                                                                                                  self.setMinimumSize(500, 500)
                                                                                                                                                                  self.set_title("Icon Browser")
                                                                                                                                                                  font_maps = {k: v.charmap for k, v in iconprovider._instance().fonts.items()}
                                                                                                                                                                  icon_names = [
                                                                                                                                                                      f"{font_collection}.{icon_name}"
                                                                                                                                                                      for font_collection, font_data in font_maps.items()
                                                                                                                                                                      for icon_name in font_data
                                                                                                                                                                  ]
                                                                                                                                                                  model = IconModel(icon_color="text_role")
                                                                                                                                                                  model.setStringList(sorted(icon_names))
                                                                                                                                                          
                                                                                                                                                                  self._proxy_model = itemmodels.FuzzyFilterProxyModel()
                                                                                                                                                                  self._proxy_model.setSourceModel(model)
                                                                                                                                                                  self._proxy_model.set_filter_case_sensitive(True)
                                                                                                                                                                  self._proxy_model.set_match_color(None)
                                                                                                                                                          
                                                                                                                                                                  self._listview = widgets.ListView(
                                                                                                                                                                      self,
                                                                                                                                                                      uniform_item_sizes=True,
                                                                                                                                                                      view_mode="icon",
                                                                                                                                                                      context_menu_policy="custom",
                                                                                                                                                                      double_clicked=self._copy_icon_text,
                                                                                                                                                                      vertical_scroll_bar_policy="always_on",
                                                                                                                                                                  )
                                                                                                                                                                  eventfilter = listviewgridresizeeventfilter.ListViewGridResizeEventFilter(
                                                                                                                                                                      parent=self._listview
                                                                                                                                                                  )
                                                                                                                                                                  self._listview.installEventFilter(eventfilter)
                                                                                                                                                                  self._listview.set_model(self._proxy_model)
                                                                                                                                                          
                                                                                                                                                                  self._lineedit = widgets.LineEdit(
                                                                                                                                                                      parent=self, text_changed=self._trigger_instant_update
                                                                                                                                                                  )
                                                                                                                                                          
                                                                                                                                                                  self._combobox = widgets.ComboBox(
                                                                                                                                                                      parent=self,
                                                                                                                                                                      minimum_width=75,
                                                                                                                                                                      current_index_changed=self._trigger_instant_update,
                                                                                                                                                                  )
                                                                                                                                                                  self._combobox.addItems([ALL_COLLECTIONS, *sorted(font_maps.keys())])
                                                                                                                                                          
                                                                                                                                                                  search_bar_frame = widgets.Frame(self)
                                                                                                                                                                  layout = search_bar_frame.set_layout("horizontal", margin=0)
                                                                                                                                                                  layout.add(self._combobox)
                                                                                                                                                                  layout.add(self._lineedit)
                                                                                                                                                          
                                                                                                                                                                  self._copy_button = widgets.PushButton("Copy Name", clicked=self._copy_icon_text)
                                                                                                                                                                  frame = widgets.Frame(self)
                                                                                                                                                                  layout = frame.set_layout("vertical")
                                                                                                                                                                  layout.add(search_bar_frame)
                                                                                                                                                                  layout.add(self._listview)
                                                                                                                                                                  layout.add(self._copy_button)
                                                                                                                                                                  self.setCentralWidget(frame)
                                                                                                                                                                  self.add_shortcut("return", callback=self._copy_icon_text)
                                                                                                                                                                  self._lineedit.setFocus()
                                                                                                                                                                  self.position_on("screen")
                                                                                                                                                          
                                                                                                                                                              def _trigger_instant_update(self):
                                                                                                                                                                  """Stop timer used for committing search term and update proxy model instantly."""
                                                                                                                                                                  self._proxy_model.set_search_term(self._lineedit.text())
                                                                                                                                                          
                                                                                                                                                              def _copy_icon_text(self):
                                                                                                                                                                  """Copy the name of the currently selected icon to the clipboard."""
                                                                                                                                                                  if indexes := self._listview.selectedIndexes():
                                                                                                                                                                      widgets.Application.copy_to_clipboard(indexes[0].data())
                                                                                                                                                          

                                                                                                                                                          IconWidget

                                                                                                                                                          Bases: Label

                                                                                                                                                          Source code in prettyqt/custom_widgets/labels/iconwidget.py
                                                                                                                                                          class IconWidget(widgets.Label):
                                                                                                                                                              def __init__(self, *names, parent: widgets.QWidget | None = None, **kwargs):
                                                                                                                                                                  super().__init__(parent=parent)
                                                                                                                                                                  self._icon: gui.QIcon | None = None
                                                                                                                                                                  self._size = core.Size(16, 16)
                                                                                                                                                                  self.set_icon(iconprovider._icon(*names, **kwargs))
                                                                                                                                                          
                                                                                                                                                              def set_icon(self, _icon: datatypes.IconType):
                                                                                                                                                                  """Set a new icon().
                                                                                                                                                          
                                                                                                                                                                  Parameters
                                                                                                                                                                  ----------
                                                                                                                                                                  _icon: qtawesome.icon
                                                                                                                                                                      icon to set
                                                                                                                                                                  """
                                                                                                                                                                  self._icon = iconprovider.get_icon(_icon)
                                                                                                                                                                  self.setPixmap(self._icon.pixmap(self._size))
                                                                                                                                                          
                                                                                                                                                              def set_icon_size(self, size: datatypes.SizeType):
                                                                                                                                                                  self._size = datatypes.to_size(size)
                                                                                                                                                                  self.update()
                                                                                                                                                          
                                                                                                                                                              def update(self, *args, **kwargs):
                                                                                                                                                                  if self._icon:
                                                                                                                                                                      self.setPixmap(self._icon.pixmap(self._size))
                                                                                                                                                                  return super().update(*args, **kwargs)
                                                                                                                                                          

                                                                                                                                                          set_icon(_icon: datatypes.IconType)

                                                                                                                                                          Set a new icon().

                                                                                                                                                          Parameters

                                                                                                                                                          _icon: qtawesome.icon icon to set

                                                                                                                                                          Source code in prettyqt/custom_widgets/labels/iconwidget.py
                                                                                                                                                          def set_icon(self, _icon: datatypes.IconType):
                                                                                                                                                              """Set a new icon().
                                                                                                                                                          
                                                                                                                                                              Parameters
                                                                                                                                                              ----------
                                                                                                                                                              _icon: qtawesome.icon
                                                                                                                                                                  icon to set
                                                                                                                                                              """
                                                                                                                                                              self._icon = iconprovider.get_icon(_icon)
                                                                                                                                                              self.setPixmap(self._icon.pixmap(self._size))
                                                                                                                                                          

                                                                                                                                                          LogRecordTableView

                                                                                                                                                          Bases: TableView

                                                                                                                                                          Table view showing a log table.

                                                                                                                                                          Source code in prettyqt/custom_widgets/logrecordtableview.py
                                                                                                                                                          class LogRecordTableView(widgets.TableView):
                                                                                                                                                              """Table view showing a log table."""
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args, **kwargs):
                                                                                                                                                                  super().__init__(*args, **kwargs)
                                                                                                                                                                  self.set_selection_behavior("rows")
                                                                                                                                                                  self.handler = signallogger.SignalLogger()
                                                                                                                                                                  core.CoreApplication.call_on_exit(lambda: logger.removeHandler(self.handler))
                                                                                                                                                                  self.setWordWrap(True)
                                                                                                                                                          
                                                                                                                                                              def set_logger(self, logger, level=logging.DEBUG):
                                                                                                                                                                  model = itemmodels.LogRecordModel(parent=self)
                                                                                                                                                                  logger.addHandler(self.handler)
                                                                                                                                                                  self.handler.signals.log_record.connect(model.add)
                                                                                                                                                                  self.handler.setLevel(level)
                                                                                                                                                                  self.set_model(model)
                                                                                                                                                                  self.proxifier[0].modify(color_log, role=constants.BACKGROUND_ROLE)
                                                                                                                                                                  self.h_header = custom_widgets.FilterHeader(self)
                                                                                                                                                          

                                                                                                                                                          MultiComboBox

                                                                                                                                                          Bases: ComboBox

                                                                                                                                                          ComboBox allowing multiple-choice selection.

                                                                                                                                                          Source code in prettyqt/custom_widgets/multicombobox.py
                                                                                                                                                          class MultiComboBox(widgets.ComboBox):
                                                                                                                                                              """ComboBox allowing multiple-choice selection."""
                                                                                                                                                          
                                                                                                                                                              selectionChanged = core.Signal(list)  # noqa: N815
                                                                                                                                                          
                                                                                                                                                              def __init__(self, parent: widgets.QWidget | None = None, **kwargs):
                                                                                                                                                                  super().__init__(parent=parent, **kwargs)
                                                                                                                                                                  self._model = gui.StandardItemModel(self)
                                                                                                                                                                  self.setModel(self._model)
                                                                                                                                                                  self.setEditable(True)
                                                                                                                                                                  line_edit = self.lineEdit()
                                                                                                                                                                  assert line_edit is not None
                                                                                                                                                                  line_edit.setReadOnly(True)
                                                                                                                                                                  self.setItemDelegate(SizeHintDelegate())
                                                                                                                                                          
                                                                                                                                                                  # Hide and show popup when clicking the line edit
                                                                                                                                                                  line_edit.installEventFilter(self)
                                                                                                                                                                  self._close_on_lineedit_click = False
                                                                                                                                                          
                                                                                                                                                                  # Prevent popup from closing when clicking on an item
                                                                                                                                                                  self.view().viewport().installEventFilter(self)
                                                                                                                                                          
                                                                                                                                                                  self.addItem("Show/Hide All", checked=True)
                                                                                                                                                          
                                                                                                                                                                  self._model.itemChanged.connect(self._update_selection)
                                                                                                                                                                  self._model.dataChanged.connect(self._update_text)
                                                                                                                                                                  self._model.dataChanged.connect(self._emit_current_data)
                                                                                                                                                          
                                                                                                                                                              def _emit_current_data(self):
                                                                                                                                                                  self.selectionChanged.emit(self.currentData())
                                                                                                                                                          
                                                                                                                                                              def _update_selection(self, item: gui.QStandardItem):
                                                                                                                                                                  if item.index().row() == 0:
                                                                                                                                                                      state = item.checkState()
                                                                                                                                                                      with self._model.change_layout():
                                                                                                                                                                          for _item in self.get_model_items():
                                                                                                                                                                              _item.setCheckState(state)
                                                                                                                                                          
                                                                                                                                                              def resizeEvent(self, event):
                                                                                                                                                                  # Recompute text to elide as needed
                                                                                                                                                                  self._update_text()
                                                                                                                                                                  super().resizeEvent(event)
                                                                                                                                                          
                                                                                                                                                              def eventFilter(self, source, event):
                                                                                                                                                                  if source == self.lineEdit():
                                                                                                                                                                      if event.type() == core.QEvent.Type.MouseButtonRelease:
                                                                                                                                                                          if self._close_on_lineedit_click:
                                                                                                                                                                              self.hidePopup()
                                                                                                                                                                          else:
                                                                                                                                                                              self.showPopup()
                                                                                                                                                                          return True
                                                                                                                                                                      return False
                                                                                                                                                          
                                                                                                                                                                  if (
                                                                                                                                                                      source == self.view().viewport()
                                                                                                                                                                      and event.type() == core.QEvent.Type.MouseButtonRelease
                                                                                                                                                                  ):
                                                                                                                                                                      index = self.view().indexAt(event.position().toPoint())
                                                                                                                                                                      item = self._model.itemFromIndex(index)
                                                                                                                                                                      if isinstance(item, gui.StandardItem):
                                                                                                                                                                          item.toggle_checkstate()
                                                                                                                                                                      return True
                                                                                                                                                                  return False
                                                                                                                                                          
                                                                                                                                                              def showPopup(self):
                                                                                                                                                                  super().showPopup()
                                                                                                                                                                  # When the popup is displayed, a click on the lineedit should close it
                                                                                                                                                                  self._close_on_lineedit_click = True
                                                                                                                                                          
                                                                                                                                                              def hidePopup(self):
                                                                                                                                                                  super().hidePopup()
                                                                                                                                                                  # Used to prevent immediate reopening when clicking on the lineEdit
                                                                                                                                                                  self.startTimer(100)
                                                                                                                                                                  # Refresh the display text when closing
                                                                                                                                                                  self._update_text()
                                                                                                                                                          
                                                                                                                                                              def timerEvent(self, event):
                                                                                                                                                                  # After timeout, kill timer, and re-enable click on line edit
                                                                                                                                                                  self.killTimer(event.timerId())
                                                                                                                                                                  self._close_on_lineedit_click = False
                                                                                                                                                          
                                                                                                                                                              def _update_text(self):
                                                                                                                                                                  line_edit = self.lineEdit()
                                                                                                                                                                  if line_edit is None:
                                                                                                                                                                      return
                                                                                                                                                                  texts = [item.text() for item in self.get_model_items() if item.is_checked()]
                                                                                                                                                                  text = ", ".join(texts)
                                                                                                                                                                  # Compute elided text (with "...")
                                                                                                                                                                  metrics = gui.FontMetrics(line_edit.font())
                                                                                                                                                                  text = metrics.elided_text(text, "right", line_edit.width())
                                                                                                                                                                  line_edit.setText(text)
                                                                                                                                                          
                                                                                                                                                              def addItem(self, text: str, data: Any = None, checked: bool = False, **kwargs):
                                                                                                                                                                  item = gui.StandardItem()
                                                                                                                                                                  item.setText(text)
                                                                                                                                                                  item.setData(text if data is None else data, constants.USER_ROLE)
                                                                                                                                                                  item.setFlags(constants.IS_ENABLED | constants.IS_CHECKABLE)
                                                                                                                                                                  item.set_checkstate(checked)
                                                                                                                                                                  self._model.appendRow([item])
                                                                                                                                                          
                                                                                                                                                              def addItems(
                                                                                                                                                                  self,
                                                                                                                                                                  items: Sequence[str | tuple[str, Any]],
                                                                                                                                                                  all_checked: bool = False,
                                                                                                                                                              ):
                                                                                                                                                                  for item in items:
                                                                                                                                                                      text, data = item if isinstance(item, tuple) else (item, item)
                                                                                                                                                                      self.addItem(text, data, checked=all_checked)
                                                                                                                                                          
                                                                                                                                                              def currentData(
                                                                                                                                                                  self, role: constants.ItemDataRole = constants.USER_ROLE
                                                                                                                                                              ) -> list[Any]:
                                                                                                                                                                  return [item.data(role) for item in self.get_model_items() if item.is_checked()]
                                                                                                                                                          
                                                                                                                                                              def get_current_options(self) -> list[tuple[str, Any]]:
                                                                                                                                                                  return [
                                                                                                                                                                      (item.text(), item.data(constants.USER_ROLE))
                                                                                                                                                                      for item in self.get_model_items()
                                                                                                                                                                      if item.is_checked()
                                                                                                                                                                  ]
                                                                                                                                                          
                                                                                                                                                              def get_model_items(self) -> Generator[gui.StandardItem]:
                                                                                                                                                                  for i in range(1, self._model.rowCount()):
                                                                                                                                                                      if (item := self._model.item(i)) is not None:
                                                                                                                                                                          yield cast("gui.StandardItem", item)
                                                                                                                                                          
                                                                                                                                                              def set_value(self, items: list[Any]):
                                                                                                                                                                  for item in self.get_model_items():
                                                                                                                                                                      item.set_checkstate(item.data(constants.USER_ROLE) in items)
                                                                                                                                                          
                                                                                                                                                              def get_value(self) -> list[Any]:
                                                                                                                                                                  return self.currentData()
                                                                                                                                                          

                                                                                                                                                          MultiLineLayout

                                                                                                                                                          Bases: BoxLayout

                                                                                                                                                          Nested Boxlayout.

                                                                                                                                                          Source code in prettyqt/custom_widgets/layouts/multilinelayout.py
                                                                                                                                                          class MultiLineLayout(widgets.BoxLayout):
                                                                                                                                                              """Nested Boxlayout."""
                                                                                                                                                          
                                                                                                                                                              def __init__(self, vertical: bool = True, row_number: int = 3, **kwargs):
                                                                                                                                                                  self.row_nb = row_number
                                                                                                                                                                  self.layouts: list[
                                                                                                                                                                      widgets.BoxLayout
                                                                                                                                                                      | MultiLineLayout
                                                                                                                                                                      | widgets.GridLayout
                                                                                                                                                                      | custom_widgets.FlowLayout
                                                                                                                                                                      | widgets.StackedLayout
                                                                                                                                                                  ] = []
                                                                                                                                                                  self._sub_layout_type = "box"
                                                                                                                                                                  direction = self.Direction.TopToBottom if vertical else self.Direction.LeftToRight
                                                                                                                                                                  super().__init__(direction, **kwargs)
                                                                                                                                                          
                                                                                                                                                              def set_direction(
                                                                                                                                                                  self, direction: widgets.BoxLayout.Direction | widgets.boxlayout.DirectionStr
                                                                                                                                                              ):
                                                                                                                                                                  super().set_direction(direction)
                                                                                                                                                                  direction = self.get_sub_direction()
                                                                                                                                                                  for layout in self.layouts:
                                                                                                                                                                      if isinstance(layout, widgets.BoxLayout):
                                                                                                                                                                          layout.set_direction(direction)
                                                                                                                                                          
                                                                                                                                                              def get_sub_direction(self) -> widgets.BoxLayout.Direction:
                                                                                                                                                                  return (
                                                                                                                                                                      self.Direction.LeftToRight
                                                                                                                                                                      if self.get_direction() == "top_to_bottom"
                                                                                                                                                                      else self.Direction.TopToBottom
                                                                                                                                                                  )
                                                                                                                                                          
                                                                                                                                                              def _add_sub_layout(self):
                                                                                                                                                                  match self._sub_layout_type:
                                                                                                                                                                      case "box":
                                                                                                                                                                          direction = self.get_sub_direction()
                                                                                                                                                                          layout = widgets.BoxLayout(direction)
                                                                                                                                                                      case "grid":
                                                                                                                                                                          layout = widgets.GridLayout()
                                                                                                                                                                      case "flow":
                                                                                                                                                                          layout = custom_widgets.FlowLayout()
                                                                                                                                                                      case "stacked":
                                                                                                                                                                          layout = widgets.StackedLayout()
                                                                                                                                                                      case "nested":
                                                                                                                                                                          direction = self.get_sub_direction()
                                                                                                                                                                          layout = MultiLineLayout(direction == self.Direction.TopToBottom)
                                                                                                                                                                  super().addLayout(layout)
                                                                                                                                                                  self.layouts.append(layout)
                                                                                                                                                          
                                                                                                                                                              def _add_to_sub_layout(self, item, **kwargs):
                                                                                                                                                                  if not self.layouts or self.layouts[-1].count() == self.row_nb:
                                                                                                                                                                      self._add_sub_layout()
                                                                                                                                                                  sub = self.layouts[-1]
                                                                                                                                                                  if isinstance(sub, widgets.GridLayout):
                                                                                                                                                                      idx = sub.count()
                                                                                                                                                                      row, col = (
                                                                                                                                                                          (0, idx)
                                                                                                                                                                          if self.get_sub_direction() == self.Direction.LeftToRight
                                                                                                                                                                          else (idx, 0)
                                                                                                                                                                      )
                                                                                                                                                                      sub.add(item, row, col, **kwargs)
                                                                                                                                                                  else:
                                                                                                                                                                      sub.add(item, **kwargs)
                                                                                                                                                          
                                                                                                                                                              def addWidget(self, widget: widgets.QWidget, **kwargs):
                                                                                                                                                                  self._add_to_sub_layout(widget, **kwargs)
                                                                                                                                                          
                                                                                                                                                              def addLayout(self, layout: widgets.QLayout):
                                                                                                                                                                  self._add_to_sub_layout(layout)
                                                                                                                                                          
                                                                                                                                                              def addItem(self, item):
                                                                                                                                                                  self._add_to_sub_layout(item)
                                                                                                                                                          
                                                                                                                                                              def get_items(self) -> listdelegators.ListDelegator[widgets.QLayoutItem]:
                                                                                                                                                                  items = [i.get_items() for i in self.layouts]
                                                                                                                                                                  return listdelegators.ListDelegator(itertools.chain(*items))
                                                                                                                                                          
                                                                                                                                                              def itemAt(self, idx: int) -> widgets.QLayoutItem | None:
                                                                                                                                                                  if len(self.layouts) == 0 or len(self.get_items()) == 0:
                                                                                                                                                                      raise IndexError(idx)
                                                                                                                                                                  # doesnt seem right?
                                                                                                                                                                  return None if idx == len(self.get_items()) else self.get_items()[idx]
                                                                                                                                                          
                                                                                                                                                              def takeAt(self, idx: int) -> widgets.QLayoutItem | None:  # or 0 according to docs?
                                                                                                                                                                  if idx < 0 or not self.layouts:
                                                                                                                                                                      return None
                                                                                                                                                                  layout_idx, item_idx = divmod(idx, self.row_nb)
                                                                                                                                                                  if layout_idx >= len(self.layouts):
                                                                                                                                                                      return None
                                                                                                                                                                  layout = self.layouts[layout_idx]
                                                                                                                                                                  item = layout.takeAt(item_idx)
                                                                                                                                                                  for i, sub_layout in enumerate(self.layouts[layout_idx:-1], start=layout_idx):
                                                                                                                                                                      next_item = self.layouts[i + 1].takeAt(0)
                                                                                                                                                                      if next_item is not None:
                                                                                                                                                                          sub_layout.addItem(next_item)
                                                                                                                                                                  if len(self.layouts[-1]) == 0:
                                                                                                                                                                      self.layouts.pop()
                                                                                                                                                                      super().takeAt(super().count() - 1)
                                                                                                                                                                  return item
                                                                                                                                                          
                                                                                                                                                              def count(self) -> int:
                                                                                                                                                                  return len(self.get_items())
                                                                                                                                                          
                                                                                                                                                              def indexOf(self, item: widgets.QLayoutItem) -> int:
                                                                                                                                                                  return self.get_items().index(item)
                                                                                                                                                          
                                                                                                                                                              def set_sub_layout_type(self, layout_type: str):
                                                                                                                                                                  self._sub_layout_type = layout_type
                                                                                                                                                          
                                                                                                                                                              def get_sub_layout_type(self) -> str:
                                                                                                                                                                  return self._sub_layout_type
                                                                                                                                                          
                                                                                                                                                              sub_layout_type = core.Property(
                                                                                                                                                                  str,
                                                                                                                                                                  get_sub_layout_type,
                                                                                                                                                                  set_sub_layout_type,
                                                                                                                                                                  doc="Layout for the sub layouts",
                                                                                                                                                              )
                                                                                                                                                          

                                                                                                                                                          NumFilterWidget

                                                                                                                                                          Bases: Widget

                                                                                                                                                          Widget with a button to choose from a comparison op (>=, >, etc) + a lineedit.

                                                                                                                                                          Source code in prettyqt/custom_widgets/numfilterwidget.py
                                                                                                                                                          class NumFilterWidget(widgets.Widget):
                                                                                                                                                              """Widget with a button to choose from a comparison op (>=, >, etc) + a lineedit."""
                                                                                                                                                          
                                                                                                                                                              filter_changed = core.Signal(object)
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args, **kwargs):
                                                                                                                                                                  super().__init__(*args, **kwargs)
                                                                                                                                                                  self.set_layout("horizontal", margin=0)
                                                                                                                                                                  self.lineedit = widgets.LineEdit()
                                                                                                                                                                  self.lineedit.set_validator("double", empty_allowed=True)
                                                                                                                                                                  self.op_button = widgets.ToolButton()
                                                                                                                                                                  self.op_button.setStyleSheet("QToolButton::menu-indicator{width:0px;}")
                                                                                                                                                                  self.box.add(self.op_button)
                                                                                                                                                                  self.box.add(self.lineedit)
                                                                                                                                                                  self.menu = widgets.Menu(triggered=self._on_menu_click)
                                                                                                                                                                  for comp in ["=", "<=", "<", ">=", ">"]:
                                                                                                                                                                      self.menu.add_action(comp)
                                                                                                                                                                  self.op_button.setMenu(self.menu)
                                                                                                                                                                  self.op_button.set_popup_mode("instant")
                                                                                                                                                                  self.op_button.setText("=")
                                                                                                                                                                  self.lineedit.value_changed.connect(self._on_filter_change)
                                                                                                                                                          
                                                                                                                                                              def _on_filter_change(self):
                                                                                                                                                                  self.filter_changed.emit(self.get_filter_fn())
                                                                                                                                                          
                                                                                                                                                              def _on_menu_click(self, action: gui.QAction):
                                                                                                                                                                  self.op_button.setText(action.text())
                                                                                                                                                                  self._on_filter_change()
                                                                                                                                                          
                                                                                                                                                              def get_filter_fn(self) -> Callable | None:
                                                                                                                                                                  val = self.lineedit.get_value()
                                                                                                                                                                  if not val:
                                                                                                                                                                      return lambda x: True
                                                                                                                                                                  try:
                                                                                                                                                                      num = float(val)
                                                                                                                                                                  except ValueError:
                                                                                                                                                                      return None
                                                                                                                                                                  match self.op_button.text():
                                                                                                                                                                      case "=":
                                                                                                                                                                          op = operator.eq
                                                                                                                                                                      case "<=":
                                                                                                                                                                          op = operator.ge
                                                                                                                                                                      case "<":
                                                                                                                                                                          op = operator.gt
                                                                                                                                                                      case ">=":
                                                                                                                                                                          op = operator.le
                                                                                                                                                                      case ">":
                                                                                                                                                                          op = operator.lt
                                                                                                                                                                      case _:
                                                                                                                                                                          raise ValueError
                                                                                                                                                                  return functools.partial(op, num)
                                                                                                                                                          

                                                                                                                                                          ObjectBrowser

                                                                                                                                                          Bases: MainWindow

                                                                                                                                                          Info window for python objects.

                                                                                                                                                          Source code in prettyqt/custom_widgets/objectbrowser.py
                                                                                                                                                          class ObjectBrowser(widgets.MainWindow):
                                                                                                                                                              """Info window for python objects."""
                                                                                                                                                          
                                                                                                                                                              def __init__(self, obj, stack=None, name: str = ""):
                                                                                                                                                                  super().__init__()
                                                                                                                                                                  self.set_title("Object browser")
                                                                                                                                                                  self.set_icon("mdi.language-python")
                                                                                                                                                                  self._auto_refresh = False
                                                                                                                                                                  self._refresh_rate = 2
                                                                                                                                                                  self._tree_model = itemmodels.PythonObjectTreeModel(obj)
                                                                                                                                                                  self._attr_details = [
                                                                                                                                                                      Klass(model=self._tree_model) for Klass in DEFAULT_ATTR_DETAILS
                                                                                                                                                                  ]
                                                                                                                                                          
                                                                                                                                                                  # Toggle auto-refresh on/off
                                                                                                                                                                  self.toggle_auto_refresh_action = gui.Action(
                                                                                                                                                                      text="Auto-refresh",
                                                                                                                                                                      parent=self,
                                                                                                                                                                      checkable=True,
                                                                                                                                                                      status_tip=f"Auto refresh every {self._refresh_rate} seconds",
                                                                                                                                                                  )
                                                                                                                                                                  self.toggle_auto_refresh_action.toggled.connect(self.toggle_auto_refresh)
                                                                                                                                                          
                                                                                                                                                                  # Add another refresh action with a different shortcut. An action must be added to
                                                                                                                                                                  # a visible widget for it to receive events. It is added to the main windows to
                                                                                                                                                                  # prevent it from being displayed again in the menu
                                                                                                                                                          
                                                                                                                                                                  self.refresh_action_f5 = self.add_action(
                                                                                                                                                                      text="&Refresh2", shortcut="F5", triggered=self._tree_model.refresh_tree
                                                                                                                                                                  )
                                                                                                                                                                  self.central_splitter = widgets.Splitter(
                                                                                                                                                                      parent=self, orientation=constants.VERTICAL
                                                                                                                                                                  )
                                                                                                                                                                  self.setCentralWidget(self.central_splitter)
                                                                                                                                                          
                                                                                                                                                                  # Tree widget
                                                                                                                                                                  self.obj_tree = widgets.TreeView(
                                                                                                                                                                      root_is_decorated=True, selection_behavior="rows"
                                                                                                                                                                  )
                                                                                                                                                                  self.obj_tree.set_model(self._tree_model)
                                                                                                                                                                  self.obj_tree.h_header = custom_widgets.FilterHeader(self.obj_tree)
                                                                                                                                                          
                                                                                                                                                                  # Stretch last column?
                                                                                                                                                                  # It doesn't play nice when columns are hidden and then shown again.
                                                                                                                                                                  self.obj_tree.h_header.setObjectName("table_header")
                                                                                                                                                                  self.obj_tree.h_header.setSectionsMovable(True)
                                                                                                                                                                  self.obj_tree.h_header.setStretchLastSection(False)
                                                                                                                                                                  self.central_splitter.addWidget(self.obj_tree)
                                                                                                                                                          
                                                                                                                                                                  # Bottom pane
                                                                                                                                                                  bottom_pane_widget = widgets.Widget()
                                                                                                                                                                  bottom_pane_widget.set_layout("horizontal", spacing=0, margin=5)
                                                                                                                                                                  self.central_splitter.addWidget(bottom_pane_widget)
                                                                                                                                                          
                                                                                                                                                                  group_box = widgets.GroupBox("Details")
                                                                                                                                                                  bottom_pane_widget.box.addWidget(group_box)
                                                                                                                                                          
                                                                                                                                                                  group_box.set_layout("horizontal", margin=2)
                                                                                                                                                          
                                                                                                                                                                  # Radio buttons
                                                                                                                                                                  radio_widget = widgets.Widget()
                                                                                                                                                                  radio_layout = radio_widget.set_layout("vertical", margin=0)
                                                                                                                                                          
                                                                                                                                                                  self.button_group = widgets.ButtonGroup(
                                                                                                                                                                      self, button_clicked=self._change_details_field
                                                                                                                                                                  )
                                                                                                                                                                  for button_id, attr_detail in enumerate(self._attr_details):
                                                                                                                                                                      radio_button = widgets.RadioButton(attr_detail.name)
                                                                                                                                                                      radio_layout.addWidget(radio_button)
                                                                                                                                                                      self.button_group.addButton(radio_button, button_id)
                                                                                                                                                          
                                                                                                                                                                  self.button_group.button(0).setChecked(True)
                                                                                                                                                          
                                                                                                                                                                  radio_layout.addStretch(1)
                                                                                                                                                                  group_box.box.addWidget(radio_widget)
                                                                                                                                                          
                                                                                                                                                                  self.editor = widgets.PlainTextEdit(read_only=True, font=gui.Font.mono())
                                                                                                                                                                  group_box.box.addWidget(self.editor)
                                                                                                                                                          
                                                                                                                                                                  # Splitter parameters
                                                                                                                                                                  self.central_splitter.setCollapsible(0, False)
                                                                                                                                                                  self.central_splitter.setCollapsible(1, True)
                                                                                                                                                                  self.central_splitter.setSizes([400, 200])
                                                                                                                                                                  self.central_splitter.setStretchFactor(0, 10)
                                                                                                                                                                  self.central_splitter.setStretchFactor(1, 0)
                                                                                                                                                          
                                                                                                                                                                  selection_model = self.obj_tree.selectionModel()
                                                                                                                                                                  selection_model.currentRowChanged.connect(self._update_details)
                                                                                                                                                                  menubar = cast("widgets.MenuBar", self.menuBar())
                                                                                                                                                                  file_menu = menubar.add_menu("&File")
                                                                                                                                                                  file_menu.add_action(text="C&lose", triggered=self.close, shortcut="Ctrl+W")
                                                                                                                                                                  file_menu.add_action(
                                                                                                                                                                      text="E&xit",
                                                                                                                                                                      triggered=lambda: widgets.app().closeAllWindows(),
                                                                                                                                                                      shortcut="Ctrl+Q",
                                                                                                                                                                  )
                                                                                                                                                          
                                                                                                                                                                  view_menu = menubar.add_menu("&View")
                                                                                                                                                                  view_menu.add_action(
                                                                                                                                                                      text="&Refresh", triggered=self._tree_model.refresh_tree, shortcut="Ctrl+R"
                                                                                                                                                                  )
                                                                                                                                                                  view_menu.addAction(self.toggle_auto_refresh_action)
                                                                                                                                                          
                                                                                                                                                                  view_menu.addSeparator()
                                                                                                                                                                  self.show_cols_submenu = self.obj_tree.h_header.createPopupMenu()
                                                                                                                                                                  self.show_cols_submenu.setTitle("Table columns")
                                                                                                                                                                  view_menu.add_menu(self.show_cols_submenu)
                                                                                                                                                                  view_menu.addSeparator()
                                                                                                                                                          
                                                                                                                                                                  assert self._refresh_rate > 0
                                                                                                                                                                  self._refresh_timer = core.Timer(self)
                                                                                                                                                                  self._refresh_timer.setInterval(self._refresh_rate * 1000)
                                                                                                                                                                  self._refresh_timer.timeout.connect(self._tree_model.refresh_tree)
                                                                                                                                                                  self.toggle_auto_refresh_action.setChecked(self._auto_refresh)
                                                                                                                                                          
                                                                                                                                                              # @classmethod
                                                                                                                                                              # def setup_example(cls):
                                                                                                                                                              #     return cls(obj=["a", "b", "c"])
                                                                                                                                                          
                                                                                                                                                              @core.Slot(core.ModelIndex, core.ModelIndex)
                                                                                                                                                              def _update_details(
                                                                                                                                                                  self, current_index: core.ModelIndex, _previous_index: core.ModelIndex
                                                                                                                                                              ):
                                                                                                                                                                  """Show the object details in the editor given an index."""
                                                                                                                                                                  if self.obj_tree.model() is None or not current_index.isValid():
                                                                                                                                                                      return
                                                                                                                                                                  role = self._tree_model.ExtraRoles.TreeItemRole
                                                                                                                                                                  tree_item = current_index.data(role)
                                                                                                                                                                  self._update_details_for_item(tree_item)
                                                                                                                                                          
                                                                                                                                                              def _change_details_field(self, _button_id=None):
                                                                                                                                                                  """Change the field that is displayed in the details pane."""
                                                                                                                                                                  # logger.debug("_change_details_field: {}".format(_button_id))
                                                                                                                                                                  if self.obj_tree.model() is None:
                                                                                                                                                                      return
                                                                                                                                                                  current_index = self.obj_tree.selectionModel().currentIndex()
                                                                                                                                                                  if not current_index.isValid():
                                                                                                                                                                      return
                                                                                                                                                                  role = self._tree_model.ExtraRoles.TreeItemRole
                                                                                                                                                                  tree_item = current_index.data(role)
                                                                                                                                                                  self._update_details_for_item(tree_item)
                                                                                                                                                          
                                                                                                                                                              def _update_details_for_item(self, tree_item):
                                                                                                                                                                  """Show the object details in the editor given an tree_item."""
                                                                                                                                                                  button_id = self.button_group.checkedId()
                                                                                                                                                                  attr_details = self._attr_details[button_id]
                                                                                                                                                                  data = attr_details.get_data(tree_item)
                                                                                                                                                                  self.editor.set_text(data)
                                                                                                                                                                  self.editor.set_word_wrap_mode(attr_details.line_wrap)
                                                                                                                                                          
                                                                                                                                                              def toggle_auto_refresh(self, checked):
                                                                                                                                                                  """Toggle auto-refresh on/off."""
                                                                                                                                                                  if checked:
                                                                                                                                                                      logger.info("Auto-refresh on. Rate %g seconds", self._refresh_rate)
                                                                                                                                                                      self._refresh_timer.start()
                                                                                                                                                                  else:
                                                                                                                                                                      logger.info("Auto-refresh off")
                                                                                                                                                                      self._refresh_timer.stop()
                                                                                                                                                                  self._auto_refresh = checked
                                                                                                                                                          
                                                                                                                                                              def closeEvent(self, event):
                                                                                                                                                                  """Called when the window is closed."""
                                                                                                                                                                  self._refresh_timer.stop()
                                                                                                                                                                  self._refresh_timer.timeout.disconnect(self._tree_model.refresh_tree)
                                                                                                                                                                  self.toggle_auto_refresh_action.toggled.disconnect(self.toggle_auto_refresh)
                                                                                                                                                                  self.refresh_action_f5.triggered.disconnect(self._tree_model.refresh_tree)
                                                                                                                                                                  self.button_group.buttonClicked.disconnect(self._change_details_field)
                                                                                                                                                                  selection_model = self.obj_tree.selectionModel()
                                                                                                                                                                  selection_model.currentRowChanged.disconnect(self._update_details)
                                                                                                                                                                  self.close()
                                                                                                                                                                  event.accept()
                                                                                                                                                          

                                                                                                                                                          closeEvent(event)

                                                                                                                                                          Called when the window is closed.

                                                                                                                                                          Source code in prettyqt/custom_widgets/objectbrowser.py
                                                                                                                                                          def closeEvent(self, event):
                                                                                                                                                              """Called when the window is closed."""
                                                                                                                                                              self._refresh_timer.stop()
                                                                                                                                                              self._refresh_timer.timeout.disconnect(self._tree_model.refresh_tree)
                                                                                                                                                              self.toggle_auto_refresh_action.toggled.disconnect(self.toggle_auto_refresh)
                                                                                                                                                              self.refresh_action_f5.triggered.disconnect(self._tree_model.refresh_tree)
                                                                                                                                                              self.button_group.buttonClicked.disconnect(self._change_details_field)
                                                                                                                                                              selection_model = self.obj_tree.selectionModel()
                                                                                                                                                              selection_model.currentRowChanged.disconnect(self._update_details)
                                                                                                                                                              self.close()
                                                                                                                                                              event.accept()
                                                                                                                                                          

                                                                                                                                                          toggle_auto_refresh(checked)

                                                                                                                                                          Toggle auto-refresh on/off.

                                                                                                                                                          Source code in prettyqt/custom_widgets/objectbrowser.py
                                                                                                                                                          def toggle_auto_refresh(self, checked):
                                                                                                                                                              """Toggle auto-refresh on/off."""
                                                                                                                                                              if checked:
                                                                                                                                                                  logger.info("Auto-refresh on. Rate %g seconds", self._refresh_rate)
                                                                                                                                                                  self._refresh_timer.start()
                                                                                                                                                              else:
                                                                                                                                                                  logger.info("Auto-refresh off")
                                                                                                                                                                  self._refresh_timer.stop()
                                                                                                                                                              self._auto_refresh = checked
                                                                                                                                                          

                                                                                                                                                          OptionalWidget

                                                                                                                                                          Bases: GroupBox

                                                                                                                                                          Wraps another widget in a GroupBox with and CheckBock and makes it optional.

                                                                                                                                                          Source code in prettyqt/custom_widgets/optionalwidget.py
                                                                                                                                                          class OptionalWidget(widgets.GroupBox):
                                                                                                                                                              """Wraps another widget in a GroupBox with and CheckBock and makes it optional."""
                                                                                                                                                          
                                                                                                                                                              value_changed = core.Signal(object)
                                                                                                                                                          
                                                                                                                                                              def __init__(
                                                                                                                                                                  self,
                                                                                                                                                                  widget: ValueWidget,
                                                                                                                                                                  title: str = "",
                                                                                                                                                                  parent: widgets.QWidget | None = None,
                                                                                                                                                              ):
                                                                                                                                                                  super().__init__(checkable=True, title=title)
                                                                                                                                                                  self.set_layout("vertical")
                                                                                                                                                                  self.box.add(widget)
                                                                                                                                                                  self.widget = widget
                                                                                                                                                                  self.toggled.connect(self.widget.setEnabled)
                                                                                                                                                                  self.widget.value_changed.connect(self._on_value_change)
                                                                                                                                                                  self.toggled.connect(self._on_enable_change)
                                                                                                                                                          
                                                                                                                                                              def _on_value_change(self, val):
                                                                                                                                                                  self.value_changed.emit(val)
                                                                                                                                                          
                                                                                                                                                              def _on_enable_change(self, val):
                                                                                                                                                                  self.widget.setEnabled(val)
                                                                                                                                                                  if val:
                                                                                                                                                                      self.value_changed.emit(self.widget.get_value())
                                                                                                                                                                  else:
                                                                                                                                                                      self.value_changed.emit(None)
                                                                                                                                                          
                                                                                                                                                              def __getattr__(self, value: str):
                                                                                                                                                                  return getattr(self.widget, value)
                                                                                                                                                          
                                                                                                                                                              @classmethod
                                                                                                                                                              def setup_example(cls):
                                                                                                                                                                  w = widgets.CheckBox("Example")
                                                                                                                                                                  return cls(widget=w)
                                                                                                                                                          
                                                                                                                                                              @property
                                                                                                                                                              def enabled(self) -> bool:
                                                                                                                                                                  return self.isChecked()
                                                                                                                                                          
                                                                                                                                                              @enabled.setter
                                                                                                                                                              def enabled(self, state: bool):
                                                                                                                                                                  self.setChecked(state)
                                                                                                                                                          
                                                                                                                                                              def get_value(self):
                                                                                                                                                                  return self.widget.get_value() if self.isChecked() else None
                                                                                                                                                          

                                                                                                                                                          OrientedTableView

                                                                                                                                                          Bases: TableView

                                                                                                                                                          TableView class with some convenience methods for oriented tables.

                                                                                                                                                          Source code in prettyqt/custom_widgets/orientedtableview.py
                                                                                                                                                          class OrientedTableView(widgets.TableView):
                                                                                                                                                              """TableView class with some convenience methods for oriented tables."""
                                                                                                                                                          
                                                                                                                                                              def __init__(
                                                                                                                                                                  self, orientation: constants.Orientation | constants.OrientationStr, **kwargs
                                                                                                                                                              ):
                                                                                                                                                                  super().__init__(**kwargs)
                                                                                                                                                                  self.orientation = constants.ORIENTATION.get_enum_value(orientation)
                                                                                                                                                          
                                                                                                                                                              @classmethod
                                                                                                                                                              def setup_example(cls):
                                                                                                                                                                  return cls(orientation="vertical")
                                                                                                                                                          
                                                                                                                                                              def get_higher_levels(self, levels: int) -> core.ItemSelection:
                                                                                                                                                                  model = self.model()
                                                                                                                                                                  if self.is_horizontal():
                                                                                                                                                                      # Get the header's selected columns
                                                                                                                                                                      # Removes the higher levels so that only the lowest level of the header
                                                                                                                                                                      # affects the data table selection
                                                                                                                                                                      return core.ItemSelection(
                                                                                                                                                                          model.index(0, 0), model.index(levels - 2, model.columnCount() - 1)
                                                                                                                                                                      )
                                                                                                                                                                  return core.ItemSelection(
                                                                                                                                                                      model.index(0, 0), model.index(model.rowCount() - 1, levels - 2)
                                                                                                                                                                  )
                                                                                                                                                          
                                                                                                                                                              def set_section_span(self, row: int, column: int, count: int):
                                                                                                                                                                  if self.is_horizontal():
                                                                                                                                                                      self.setSpan(row, column, 1, count)
                                                                                                                                                                  else:
                                                                                                                                                                      self.setSpan(column, row, count, 1)
                                                                                                                                                          
                                                                                                                                                              def sectionAt(self, val: int):
                                                                                                                                                                  return self.columnAt(val) if self.is_horizontal() else self.rowAt(val)
                                                                                                                                                          
                                                                                                                                                              def over_header_edge(self, position: int, margin: int = 3) -> int | None:
                                                                                                                                                                  # Return the index of the column this x position is on the right edge of
                                                                                                                                                                  left = self.sectionAt(position - margin)
                                                                                                                                                                  right = self.sectionAt(position + margin)
                                                                                                                                                                  if left != right != 0:
                                                                                                                                                                      # We're at the left edge of the first column
                                                                                                                                                                      return left
                                                                                                                                                                  return None
                                                                                                                                                          
                                                                                                                                                              def is_horizontal(self) -> bool:
                                                                                                                                                                  return self.orientation == constants.HORIZONTAL
                                                                                                                                                          
                                                                                                                                                              def sectionWidth(self, val: int):
                                                                                                                                                                  return self.columnWidth(val) if self.is_horizontal() else self.rowHeight(val)
                                                                                                                                                          
                                                                                                                                                              def setSectionWidth(self, section: int, width: int):
                                                                                                                                                                  if self.is_horizontal():
                                                                                                                                                                      self.setColumnWidth(section, width)
                                                                                                                                                                  else:
                                                                                                                                                                      self.setRowHeight(section, width)
                                                                                                                                                          
                                                                                                                                                              def get_split_cursor(self) -> gui.Cursor:
                                                                                                                                                                  if self.is_horizontal():
                                                                                                                                                                      return gui.Cursor(constants.CursorShape.SplitHCursor)
                                                                                                                                                                  return gui.Cursor(constants.CursorShape.SplitVCursor)
                                                                                                                                                          

                                                                                                                                                          PaletteEdit

                                                                                                                                                          Bases: Widget

                                                                                                                                                          Simple editor to edit QPalettes.

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/paletteedit.py
                                                                                                                                                          class PaletteEdit(widgets.Widget):
                                                                                                                                                              """Simple editor to edit QPalettes."""
                                                                                                                                                          
                                                                                                                                                              value_changed = core.Signal(gui.Palette)
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args, object_name: str = "palette_edit", **kwargs):
                                                                                                                                                                  super().__init__(*args, object_name=object_name, **kwargs)
                                                                                                                                                                  self._value: gui.Palette = gui.Palette()
                                                                                                                                                          
                                                                                                                                                              def _on_value_change(self):
                                                                                                                                                                  self._value = self.get_value()
                                                                                                                                                                  self.value_changed.emit(self._value)
                                                                                                                                                          
                                                                                                                                                              def get_value(self) -> gui.Palette:
                                                                                                                                                                  return self._value
                                                                                                                                                          
                                                                                                                                                              def set_value(self, value: gui.Palette):
                                                                                                                                                                  self._value = value
                                                                                                                                                          
                                                                                                                                                              value = core.Property(
                                                                                                                                                                  gui.Palette,
                                                                                                                                                                  get_value,
                                                                                                                                                                  set_value,
                                                                                                                                                                  user=True,
                                                                                                                                                                  doc="Currently chosen palette",
                                                                                                                                                              )
                                                                                                                                                          

                                                                                                                                                          PointEdit

                                                                                                                                                          Bases: Widget

                                                                                                                                                          Simple Editor for QPoints.

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/pointedit.py
                                                                                                                                                          class PointEdit(widgets.Widget):
                                                                                                                                                              """Simple Editor for QPoints."""
                                                                                                                                                          
                                                                                                                                                              value_changed = core.Signal(core.Point)
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args, object_name: str = "point_edit", **kwargs):
                                                                                                                                                                  super().__init__(*args, object_name=object_name, **kwargs)
                                                                                                                                                                  self.set_margin(0)
                                                                                                                                                                  self.spinbox_x = widgets.SpinBox(maximum=999999)
                                                                                                                                                                  self.spinbox_y = widgets.SpinBox(maximum=999999)
                                                                                                                                                                  layout = self.set_layout("horizontal", margin=0)
                                                                                                                                                                  layout.add(widgets.Label("x", alignment="center_right"))
                                                                                                                                                                  layout.add(self.spinbox_x)
                                                                                                                                                                  layout.add(widgets.Label("y", alignment="center_right"))
                                                                                                                                                                  layout.add(self.spinbox_y)
                                                                                                                                                                  self.spinbox_x.value_changed.connect(self._on_value_change)
                                                                                                                                                                  self.spinbox_y.value_changed.connect(self._on_value_change)
                                                                                                                                                          
                                                                                                                                                              def _on_value_change(self):
                                                                                                                                                                  self._value = self.get_value()
                                                                                                                                                                  self.value_changed.emit(self._value)
                                                                                                                                                          
                                                                                                                                                              def get_value(self) -> core.Point:
                                                                                                                                                                  return core.Point(
                                                                                                                                                                      self.spinbox_x.value(),
                                                                                                                                                                      self.spinbox_y.value(),
                                                                                                                                                                  )
                                                                                                                                                          
                                                                                                                                                              def set_value(self, value: datatypes.PointType):
                                                                                                                                                                  point = datatypes.to_point(value)
                                                                                                                                                                  self._value = point
                                                                                                                                                                  self.spinbox_x.set_value(point.x())
                                                                                                                                                                  self.spinbox_y.set_value(point.y())
                                                                                                                                                          
                                                                                                                                                              value = core.Property(
                                                                                                                                                                  core.Point,
                                                                                                                                                                  get_value,
                                                                                                                                                                  set_value,
                                                                                                                                                                  user=True,
                                                                                                                                                                  doc="Current value",
                                                                                                                                                              )
                                                                                                                                                          

                                                                                                                                                          PopupInfo

                                                                                                                                                          Bases: Dialog

                                                                                                                                                          Dialog overlay to show some info to user.

                                                                                                                                                          Source code in prettyqt/custom_widgets/popupinfo.py
                                                                                                                                                          class PopupInfo(widgets.Dialog):
                                                                                                                                                              """Dialog overlay to show some info to user."""
                                                                                                                                                          
                                                                                                                                                              _singleton: PopupInfo | None = None
                                                                                                                                                          
                                                                                                                                                              def __init__(self, parent: widgets.QWidget | None = None, text: str | None = None):
                                                                                                                                                                  super().__init__(parent=parent)
                                                                                                                                                                  self.timer = core.Timer(single_shot=True, timeout=self.close)
                                                                                                                                                                  self.label = widgets.Label(text or "", alignment="center")
                                                                                                                                                                  self.iconlabel = widgets.Label()
                                                                                                                                                                  self.set_icon("mdi.information")
                                                                                                                                                                  self.set_flags(stay_on_top=True, frameless=True, tooltip=True)
                                                                                                                                                                  layout = self.set_layout("horizontal", margin=20, size_constraint="minimum")
                                                                                                                                                                  self.set_background_color("black")
                                                                                                                                                                  self.label.set_color("white")
                                                                                                                                                                  layout.add(self.iconlabel)
                                                                                                                                                                  layout.add(self.label)
                                                                                                                                                                  self.hide()
                                                                                                                                                          
                                                                                                                                                              def set_text_color(self, color: datatypes.ColorType):
                                                                                                                                                                  self.label.set_color(color)
                                                                                                                                                          
                                                                                                                                                              def set_icon(self, icon: datatypes.IconType):
                                                                                                                                                                  pixmap = iconprovider.get_icon(icon, color="white").pixmap(32)
                                                                                                                                                                  self.iconlabel.setPixmap(pixmap)
                                                                                                                                                          
                                                                                                                                                              def show_popup(
                                                                                                                                                                  self,
                                                                                                                                                                  text: str,
                                                                                                                                                                  icon: datatypes.IconType = "mdi.information",
                                                                                                                                                                  text_color: datatypes.ColorType = "white",
                                                                                                                                                                  background_color: datatypes.ColorType = "black",
                                                                                                                                                                  position="screen",
                                                                                                                                                                  timeout: int = 2500,
                                                                                                                                                              ):
                                                                                                                                                                  self.set_background_color(background_color)
                                                                                                                                                                  self.label.set_color(text_color)
                                                                                                                                                                  self.label.setText(text)
                                                                                                                                                                  self.set_icon(icon)
                                                                                                                                                                  self.adjustSize()
                                                                                                                                                                  self.position_on(position, y_offset=-200)
                                                                                                                                                                  self.timer.start(timeout)
                                                                                                                                                                  self.show()
                                                                                                                                                          
                                                                                                                                                              @classmethod
                                                                                                                                                              def popup(
                                                                                                                                                                  cls,
                                                                                                                                                                  text: str,
                                                                                                                                                                  icon: datatypes.IconType = "mdi.information",
                                                                                                                                                                  text_color: datatypes.ColorType = "white",
                                                                                                                                                                  background_color: datatypes.ColorType = "black",
                                                                                                                                                                  position="screen",
                                                                                                                                                                  timeout: int = 2500,
                                                                                                                                                              ):
                                                                                                                                                                  if cls._singleton is None:
                                                                                                                                                                      cls._singleton = cls()
                                                                                                                                                                  popup = cls._singleton
                                                                                                                                                                  popup.set_background_color(background_color)
                                                                                                                                                                  popup.label.set_color(text_color)
                                                                                                                                                                  popup.label.setText(text)
                                                                                                                                                                  popup.set_icon(icon)
                                                                                                                                                                  popup.adjustSize()
                                                                                                                                                                  popup.position_on(position, y_offset=-200)
                                                                                                                                                                  popup.timer.start(timeout)
                                                                                                                                                                  popup.show()
                                                                                                                                                          

                                                                                                                                                          PreviewScrollBar

                                                                                                                                                          Bases: ScrollBar

                                                                                                                                                          Scrollbar showing a small preview of a (Plain)TextEdit.

                                                                                                                                                          Source code in prettyqt/custom_widgets/scrollbars/previewscrollbar.py
                                                                                                                                                          class PreviewScrollBar(widgets.ScrollBar):
                                                                                                                                                              """Scrollbar showing a small preview of a (Plain)TextEdit."""
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args, parent: widgets.PlainTextEdit | None = None, **kwargs):
                                                                                                                                                                  super().__init__(*args, **kwargs)
                                                                                                                                                                  self._scrollarea = parent
                                                                                                                                                                  self._width = 150
                                                                                                                                                                  # self._line_margin = 152
                                                                                                                                                                  self._scale = 0.3
                                                                                                                                                                  # self.installEventFilter("slider_move_to_mouse_click")
                                                                                                                                                          
                                                                                                                                                              @classmethod
                                                                                                                                                              def setup_example(cls):
                                                                                                                                                                  w = widgets.PlainTextEdit()
                                                                                                                                                                  return cls(parent=w)
                                                                                                                                                          
                                                                                                                                                              def sizeHint(self):
                                                                                                                                                                  expand = (
                                                                                                                                                                      core.QSize(self._width, 1)
                                                                                                                                                                      if self.is_vertical()
                                                                                                                                                                      else core.QSize(1, self._width)
                                                                                                                                                                  )
                                                                                                                                                                  return super().sizeHint().expandedTo(expand)
                                                                                                                                                          
                                                                                                                                                              def paintEvent(self, event):
                                                                                                                                                                  super().paintEvent(event)
                                                                                                                                                                  if self._scrollarea is None:
                                                                                                                                                                      return
                                                                                                                                                                  # viewport = self._scrollarea.viewport()
                                                                                                                                                                  doc = self._scrollarea.document()
                                                                                                                                                                  v_scroll = self._scrollarea.v_scrollbar
                                                                                                                                                                  with gui.Painter(self) as painter:
                                                                                                                                                                      painter.setRenderHint(painter.RenderHint.TextAntialiasing, True)
                                                                                                                                                          
                                                                                                                                                                      # draw background
                                                                                                                                                                      painter.save()
                                                                                                                                                                      bg_color = gui.Palette().get_color("window")
                                                                                                                                                                      painter.setBrush(bg_color)
                                                                                                                                                                      painter.drawRect(self.geometry())
                                                                                                                                                                      painter.restore()
                                                                                                                                                          
                                                                                                                                                                      # figure out positions
                                                                                                                                                                      painter.save()
                                                                                                                                                                      first_vis_line, last_vis_line = self._scrollarea.get_visible_line_span()
                                                                                                                                                                      # start_line = max(0, first_vis_line - self._line_margin)
                                                                                                                                                                      # end_line = min(last_vis_line + self._line_margin, doc.blockCount())
                                                                                                                                                                      # start_block = doc.findBlockByLineNumber(start_line)
                                                                                                                                                                      # end_block = doc.findBlockByLineNumber(end_line)
                                                                                                                                                                      opt = widgets.QStyleOptionSlider()
                                                                                                                                                                      opt.initFrom(self)
                                                                                                                                                                      opt.subControls = widgets.QStyle.SubControl.SC_None
                                                                                                                                                                      opt.activeSubControls = widgets.QStyle.SubControl.SC_None
                                                                                                                                                                      opt.orientation = self.orientation()
                                                                                                                                                                      opt.minimum = self.minimum()
                                                                                                                                                                      opt.maximum = self.maximum()
                                                                                                                                                                      opt.sliderPosition = self.sliderPosition()
                                                                                                                                                                      opt.sliderValue = self.value()
                                                                                                                                                                      opt.singleStep = self.singleStep()
                                                                                                                                                                      opt.pageStep = self.pageStep()
                                                                                                                                                                      gr = self.style().subControlRect(
                                                                                                                                                                          widgets.QStyle.ComplexControl.CC_ScrollBar,
                                                                                                                                                                          opt,
                                                                                                                                                                          widgets.QStyle.SubControl.SC_ScrollBarGroove,
                                                                                                                                                                          self,
                                                                                                                                                                      )
                                                                                                                                                                      textarea_height = 0
                                                                                                                                                                      b = doc.begin()
                                                                                                                                                                      while b != doc.end():
                                                                                                                                                                          r = self._scrollarea.blockBoundingRect(b)
                                                                                                                                                                          textarea_height += r.height()
                                                                                                                                                                          b = b.next()
                                                                                                                                                                      minimap_height = textarea_height * self._scale
                                                                                                                                                                      minimap_visible_height = min(minimap_height, v_scroll.height())
                                                                                                                                                                      # minimap_fully_visible = minimap_visible_height == minimap_height
                                                                                                                                                                      if v_scroll.height() == 0:
                                                                                                                                                                          painter.restore()
                                                                                                                                                                          return
                                                                                                                                                                      height_ratio = minimap_height / v_scroll.height()
                                                                                                                                                                      map_scroll_distance = minimap_height - minimap_visible_height
                                                                                                                                                                      if v_scroll.maximum():
                                                                                                                                                                          scroll_per_value = map_scroll_distance / v_scroll.maximum()
                                                                                                                                                                      else:
                                                                                                                                                                          scroll_per_value = 1
                                                                                                                                                                      # doc_x_margin = 1
                                                                                                                                                                      # doc_height = min(gr.height(), textarea_height)
                                                                                                                                                                      # yoffset = 1  # top instead of center-aligned (gr.height() - doc_height) / 2
                                                                                                                                                                      # doc_rect = core.QRect(
                                                                                                                                                                      #     core.QPoint(gr.left() + doc_x_margin, yoffset + gr.top()),
                                                                                                                                                                      #     QSize(gr.width() - doc_x_margin, doc_height),
                                                                                                                                                                      # )
                                                                                                                                                                      # self.map_grove_rect = doc_rect
                                                                                                                                                          
                                                                                                                                                                      # max_ = max(self.maximum() + 1, 1)
                                                                                                                                                                      # visible_start = (
                                                                                                                                                                      #     self.value() * doc_height / (max_ + self.pageStep())
                                                                                                                                                                      #     + doc_rect.top()
                                                                                                                                                                      #     + 0.5
                                                                                                                                                                      # )
                                                                                                                                                                      # visible_end = (self.value() + self.pageStep()) * doc_height / (
                                                                                                                                                                      #     max_ + self.pageStep()
                                                                                                                                                                      # ) + doc_rect.top()
                                                                                                                                                                      # visible_rect = core.QRect(doc_rect)
                                                                                                                                                                      # visible_rect.moveTop(visible_start)
                                                                                                                                                                      # visible_rect.setHeight(visible_end - visible_start)
                                                                                                                                                                      # #  adjust the rectangles
                                                                                                                                                                      # slider_rect = self.style().subControlRect(QStyle.CC_ScrollBar, opt,
                                                                                                                                                                      # QStyle.SC_ScrollBarSlider, self)
                                                                                                                                                                      # slider_rect.setX(doc_x_margin)
                                                                                                                                                                      # slider_rect.setWidth(self.width() - doc_x_margin * 2)
                                                                                                                                                          
                                                                                                                                                                      # if ((doc_height + 2 * doc_x_margin >= gr.height()) and
                                                                                                                                                                      # (slider_rect.height() > visible_rect.height() + 2))
                                                                                                                                                                      #     visible_rect.adjust(2, 0, -3, 0)
                                                                                                                                                                      #  else:
                                                                                                                                                                      #     visible_rect.adjust(1, 0, -1, 2)
                                                                                                                                                                      #     slider_rect.setTop(visible_rect.top() - 1)
                                                                                                                                                                      #     slider_rect.setBottom(visible_rect.bottom() + 1)
                                                                                                                                                          
                                                                                                                                                                      painter.scale(self._scale, self._scale)
                                                                                                                                                                      offset = -(
                                                                                                                                                                          v_scroll.value() * scroll_per_value * (1 / self._scale)
                                                                                                                                                                      )  # height_ratio * (1/self._scale))
                                                                                                                                                                      # scale = self.height() / self._scrollarea.get_pixel_height()
                                                                                                                                                                      b = doc.begin()
                                                                                                                                                                      top = v_scroll.height() * (1 / self._scale)
                                                                                                                                                                      count = 0
                                                                                                                                                                      while b != doc.end():
                                                                                                                                                                          r = self._scrollarea.blockBoundingRect(b)
                                                                                                                                                                          if b.isVisible() and top >= offset >= 0:
                                                                                                                                                                              layout = b.layout()
                                                                                                                                                                              count += 1
                                                                                                                                                                              layout.draw(painter, core.QPointF(0, offset))
                                                                                                                                                                          offset += r.height()
                                                                                                                                                                          b = b.next()
                                                                                                                                                                      painter.restore()
                                                                                                                                                                      # pos = v_scroll.value() / v_scroll.maximum()
                                                                                                                                                                      painter.setBrush(gui.QColor(120, 120, 120, 120))
                                                                                                                                                                      # slider_rect = self.style().subControlRect(
                                                                                                                                                                      #     widgets.QStyle.ComplexControl.CC_ScrollBar,
                                                                                                                                                                      #     opt,
                                                                                                                                                                      #     widgets.QStyle.SubControl.SC_ScrollBarSlider,
                                                                                                                                                                      #     self,
                                                                                                                                                                      # )
                                                                                                                                                                      handle_rect_height = (
                                                                                                                                                                          (last_vis_line - first_vis_line)
                                                                                                                                                                          / doc.blockCount()
                                                                                                                                                                          * gr.height()
                                                                                                                                                                          * height_ratio
                                                                                                                                                                      )
                                                                                                                                                          
                                                                                                                                                                      handle_rect_y_pos = first_vis_line / doc.blockCount() * gr.height()
                                                                                                                                                                      handle_rect_y_pos *= v_scroll.height() / (
                                                                                                                                                                          v_scroll.height() + handle_rect_height
                                                                                                                                                                      )
                                                                                                                                                          
                                                                                                                                                                      painter.drawRoundedRect(
                                                                                                                                                                          0, int(handle_rect_y_pos), self._width, int(handle_rect_height), 5, 5
                                                                                                                                                                      )
                                                                                                                                                          

                                                                                                                                                          RoundProgressBar

                                                                                                                                                          Bases: Widget

                                                                                                                                                          Source code in prettyqt/custom_widgets/roundprogressbar.py
                                                                                                                                                          class RoundProgressBar(widgets.Widget):
                                                                                                                                                              class Position(float, enum.Enum):
                                                                                                                                                                  """Start position of progress bar in degrees."""
                                                                                                                                                          
                                                                                                                                                                  Left = 180.0
                                                                                                                                                                  Top = 90.0
                                                                                                                                                                  Right = 0.0
                                                                                                                                                                  Bottom = -90.0
                                                                                                                                                          
                                                                                                                                                              class BarStyle(enum.IntEnum):
                                                                                                                                                                  """Progress bar style."""
                                                                                                                                                          
                                                                                                                                                                  Donut = 1
                                                                                                                                                                  Pie = 2
                                                                                                                                                                  Line = 3
                                                                                                                                                                  Expand = 4
                                                                                                                                                          
                                                                                                                                                              class ValueType(enum.IntEnum):
                                                                                                                                                                  """Value type."""
                                                                                                                                                          
                                                                                                                                                                  value = 1
                                                                                                                                                                  percent = 2
                                                                                                                                                                  maximum = 3
                                                                                                                                                          
                                                                                                                                                              def __init__(self, parent: widgets.QWidget | None = None):
                                                                                                                                                                  super().__init__(parent)
                                                                                                                                                                  self._min_value = 0.0
                                                                                                                                                                  self._max_value = 100.0
                                                                                                                                                                  self.current_value = 0.0
                                                                                                                                                                  self.null_pos = self.Position.Top
                                                                                                                                                                  self.bar_style: RoundProgressBar.BarStyle = self.BarStyle.Donut
                                                                                                                                                                  self.outline_pen_width = 1.0
                                                                                                                                                                  self.data_pen_width = 1.0
                                                                                                                                                                  self._rebuild_brush = False
                                                                                                                                                                  self.number_format = "%p%"
                                                                                                                                                                  self.decimals = 1
                                                                                                                                                                  self._update_flags: ValueTypeStr = "percent"
                                                                                                                                                                  self.gradient_data: Sequence[tuple[float, datatypes.ColorType]] = []
                                                                                                                                                          
                                                                                                                                                              def minimum(self):
                                                                                                                                                                  return self._min_value
                                                                                                                                                          
                                                                                                                                                              def maximum(self):
                                                                                                                                                                  return self._max_value
                                                                                                                                                          
                                                                                                                                                              # SETTERS -------------------------------------------------------
                                                                                                                                                          
                                                                                                                                                              def set_null_position(self, position: RoundProgressBar.Position):
                                                                                                                                                                  if position != self.null_pos:
                                                                                                                                                                      self.null_pos = position
                                                                                                                                                                      self._rebuild_brush = True
                                                                                                                                                                      self.update()
                                                                                                                                                          
                                                                                                                                                              def get_null_position(self):
                                                                                                                                                                  return self.null_pos
                                                                                                                                                          
                                                                                                                                                              def set_bar_style(self, style: BarStyleStr | RoundProgressBar.BarStyle):
                                                                                                                                                                  if isinstance(style, str):
                                                                                                                                                                      bar_style = dict(
                                                                                                                                                                          donut=RoundProgressBar.BarStyle.Donut,
                                                                                                                                                                          pie=RoundProgressBar.BarStyle.Pie,
                                                                                                                                                                          line=RoundProgressBar.BarStyle.Line,
                                                                                                                                                                          expand=RoundProgressBar.BarStyle.Expand,
                                                                                                                                                                      )
                                                                                                                                                                      style = bar_style[style]
                                                                                                                                                                  if style != self.bar_style:
                                                                                                                                                                      self.bar_style = style
                                                                                                                                                                      self._rebuild_brush = True
                                                                                                                                                                      self.update()
                                                                                                                                                          
                                                                                                                                                              def set_outline_pen_width(self, width: float):
                                                                                                                                                                  if width != self.outline_pen_width:
                                                                                                                                                                      self.outline_pen_width = width
                                                                                                                                                                      self.update()
                                                                                                                                                          
                                                                                                                                                              def set_data_pen_width(self, width: float):
                                                                                                                                                                  if width != self.data_pen_width:
                                                                                                                                                                      self.data_pen_width = width
                                                                                                                                                                      self.update()
                                                                                                                                                          
                                                                                                                                                              def set_data_colors(self, stop_points: Sequence[tuple[float, datatypes.ColorType]]):
                                                                                                                                                                  if stop_points != self.gradient_data:
                                                                                                                                                                      self.gradient_data = stop_points
                                                                                                                                                                      self._rebuild_brush = True
                                                                                                                                                                      self.update()
                                                                                                                                                          
                                                                                                                                                              def set_format(self, val: str):
                                                                                                                                                                  if val != self.number_format:
                                                                                                                                                                      self.number_format = val
                                                                                                                                                                      self._value_format_changed()
                                                                                                                                                          
                                                                                                                                                              def set_decimals(self, count: int):
                                                                                                                                                                  if count >= 0 and count != self.decimals:
                                                                                                                                                                      self.decimals = count
                                                                                                                                                                      self._value_format_changed()
                                                                                                                                                          
                                                                                                                                                              # SLOTS ---------------------------------------------------------
                                                                                                                                                          
                                                                                                                                                              @core.Slot(float, float)
                                                                                                                                                              def set_range(self, minval: float, maxval: float):
                                                                                                                                                                  self._min_value = min(minval, maxval)
                                                                                                                                                                  self._max_value = max(minval, maxval)
                                                                                                                                                                  self.current_value = min(
                                                                                                                                                                      self._max_value, max(self._min_value, self.current_value)
                                                                                                                                                                  )
                                                                                                                                                                  self._rebuild_brush = True
                                                                                                                                                                  self.update()
                                                                                                                                                          
                                                                                                                                                              @core.Slot(float)
                                                                                                                                                              def setMinimum(self, val: float):
                                                                                                                                                                  self.set_range(val, self._max_value)
                                                                                                                                                          
                                                                                                                                                              @core.Slot(float)
                                                                                                                                                              def setMaximum(self, val: float):
                                                                                                                                                                  self.set_range(self._min_value, val)
                                                                                                                                                          
                                                                                                                                                              @core.Slot(float)
                                                                                                                                                              def set_value(self, val: float):
                                                                                                                                                                  if self.current_value != val:
                                                                                                                                                                      self.current_value = min(self._max_value, max(self._min_value, val))
                                                                                                                                                                      self.update()
                                                                                                                                                          
                                                                                                                                                              def get_value(self) -> float:
                                                                                                                                                                  return self.current_value
                                                                                                                                                          
                                                                                                                                                              # PAINTING ------------------------------------------------------
                                                                                                                                                          
                                                                                                                                                              def paintEvent(self, event: gui.QPaintEvent):
                                                                                                                                                                  outer_radius = min(self.width(), self.height())
                                                                                                                                                                  rect = core.RectF(1, 1, outer_radius - 2, outer_radius - 2)
                                                                                                                                                                  with gui.Painter(self) as painter:
                                                                                                                                                                      painter.use_antialiasing()
                                                                                                                                                                      if self.bar_style != self.BarStyle.Line:
                                                                                                                                                                          self._rebuild_data_brush_if_needed()
                                                                                                                                                                      painter.fillRect(0, 0, outer_radius, outer_radius, self.palette().window())
                                                                                                                                                                      self._draw_base(painter, rect)
                                                                                                                                                                      self._draw_value(painter, rect, self.current_value)
                                                                                                                                                                      inner_rect, inner_radius = self._calculate_inner_rect(outer_radius)
                                                                                                                                                                      self._draw_inner_background(painter, inner_rect)
                                                                                                                                                                      self._draw_text(painter, inner_rect, inner_radius, self.current_value)
                                                                                                                                                          
                                                                                                                                                              def _draw_base(self, painter: gui.Painter, rect: core.RectF):
                                                                                                                                                                  match self.bar_style:
                                                                                                                                                                      case self.BarStyle.Donut:
                                                                                                                                                                          color = self.palette().shadow().color()
                                                                                                                                                                          painter.set_pen(color=color, width=self.outline_pen_width)
                                                                                                                                                                          painter.setBrush(self.palette().base())
                                                                                                                                                                          painter.drawEllipse(rect)
                                                                                                                                                                      case self.BarStyle.Line:
                                                                                                                                                                          base_color = self.palette().base().color()
                                                                                                                                                                          painter.set_pen(color=base_color, width=self.outline_pen_width)
                                                                                                                                                                          painter.setBrush(constants.BrushStyle.NoBrush)
                                                                                                                                                                          width = self.outline_pen_width / 2
                                                                                                                                                                          adjusted = rect.adjusted(width, width, -width, -width)
                                                                                                                                                                          painter.drawEllipse(adjusted)
                                                                                                                                                                      case self.BarStyle.Pie | self.BarStyle.Expand:
                                                                                                                                                                          base_color = self.palette().base().color()
                                                                                                                                                                          painter.set_pen(color=base_color, width=self.outline_pen_width)
                                                                                                                                                                          painter.setBrush(self.palette().base())
                                                                                                                                                                          painter.drawEllipse(rect)
                                                                                                                                                          
                                                                                                                                                              def _draw_value(self, painter: gui.Painter, rect: core.RectF, value: float):
                                                                                                                                                                  if value == self._min_value:
                                                                                                                                                                      return
                                                                                                                                                                  diff = self.current_value - self._min_value
                                                                                                                                                                  value_range = self._max_value - self._min_value
                                                                                                                                                                  delta = max(value_range / diff, 0)
                                                                                                                                                                  match self.bar_style:
                                                                                                                                                                      case self.BarStyle.Expand:
                                                                                                                                                                          painter.setBrush(self.palette().highlight())
                                                                                                                                                                          color = self.palette().shadow().color()
                                                                                                                                                                          painter.set_pen(color=color, width=self.data_pen_width)
                                                                                                                                                                          radius = (rect.height() / 2) / delta
                                                                                                                                                                          painter.drawEllipse(rect.center(), radius, radius)
                                                                                                                                                                      case self.BarStyle.Line:
                                                                                                                                                                          color = self.palette().highlight().color()
                                                                                                                                                                          painter.set_pen(color=color, width=self.data_pen_width)
                                                                                                                                                                          painter.setBrush(constants.BrushStyle.NoBrush)
                                                                                                                                                                          pen_width = self.outline_pen_width / 2
                                                                                                                                                                          adjusted = rect.adjusted(pen_width, pen_width, -pen_width, -pen_width)
                                                                                                                                                                          if value == self._max_value:
                                                                                                                                                                              painter.drawEllipse(adjusted)
                                                                                                                                                                          else:
                                                                                                                                                                              arc_length = 360 / delta
                                                                                                                                                                              arc_length = int(-arc_length * 16)
                                                                                                                                                                              painter.drawArc(adjusted, int(self.null_pos * 16), arc_length)
                                                                                                                                                                      case self.BarStyle.Donut | self.BarStyle.Pie:
                                                                                                                                                                          data_path = gui.PainterPath()
                                                                                                                                                                          data_path.set_fill_rule("winding")
                                                                                                                                                                          if value == self._max_value:
                                                                                                                                                                              data_path.addEllipse(rect)
                                                                                                                                                                          else:
                                                                                                                                                                              arc_length = 360 / delta
                                                                                                                                                                              center_point = rect.center()
                                                                                                                                                                              data_path.moveTo(center_point)
                                                                                                                                                                              data_path.arcTo(rect, self.null_pos, -arc_length)
                                                                                                                                                                              data_path.lineTo(center_point)
                                                                                                                                                                          painter.setBrush(self.palette().highlight())
                                                                                                                                                                          shadow_color = self.palette().shadow().color()
                                                                                                                                                                          painter.set_pen(color=shadow_color, width=self.data_pen_width)
                                                                                                                                                                          painter.drawPath(data_path)
                                                                                                                                                          
                                                                                                                                                              def _calculate_inner_rect(self, outer_radius: float) -> tuple[core.RectF, float]:
                                                                                                                                                                  if self.bar_style in (self.BarStyle.Line, self.BarStyle.Expand):
                                                                                                                                                                      inner_radius = outer_radius - self.outline_pen_width
                                                                                                                                                                  else:
                                                                                                                                                                      inner_radius = outer_radius * 0.75
                                                                                                                                                                  delta = (outer_radius - inner_radius) / 2
                                                                                                                                                                  inner_rect = core.RectF(delta, delta, inner_radius, inner_radius)
                                                                                                                                                                  return inner_rect, inner_radius
                                                                                                                                                          
                                                                                                                                                              def _draw_inner_background(self, painter: gui.Painter, inner_rect: core.RectF):
                                                                                                                                                                  if self.bar_style == self.BarStyle.Donut:
                                                                                                                                                                      painter.setBrush(self.palette().base())
                                                                                                                                                                      painter.drawEllipse(inner_rect)
                                                                                                                                                          
                                                                                                                                                              def _draw_text(
                                                                                                                                                                  self,
                                                                                                                                                                  painter: gui.Painter,
                                                                                                                                                                  inner_rect: core.RectF,
                                                                                                                                                                  inner_radius: float,
                                                                                                                                                                  value: float,
                                                                                                                                                              ):
                                                                                                                                                                  if not self.number_format:
                                                                                                                                                                      return
                                                                                                                                                                  font = self.get_font()
                                                                                                                                                                  font.setPixelSize(10)
                                                                                                                                                                  metrics = gui.FontMetricsF(font)
                                                                                                                                                                  max_width = metrics.horizontalAdvance(self._value_to_text(self._max_value))
                                                                                                                                                                  delta = inner_radius / max_width
                                                                                                                                                                  font_size = int(font.pixelSize() * delta * 0.75)
                                                                                                                                                                  font.setPixelSize(max(font_size, 1))
                                                                                                                                                                  painter.setFont(font)
                                                                                                                                                                  painter.setPen(self.palette().text().color())
                                                                                                                                                                  text = self._value_to_text(value)
                                                                                                                                                                  painter.drawText(inner_rect, constants.ALIGN_CENTER, text)
                                                                                                                                                          
                                                                                                                                                              def _value_to_text(self, value: float) -> str:
                                                                                                                                                                  text_to_draw = self.number_format
                                                                                                                                                                  match self._update_flags:
                                                                                                                                                                      case "value":
                                                                                                                                                                          val = round(value, self.decimals)
                                                                                                                                                                          return text_to_draw.replace(r"%v", str(val))
                                                                                                                                                                      case "percent":
                                                                                                                                                                          diff = self._max_value - self._min_value
                                                                                                                                                                          pct = (value - self._min_value) / diff * 100
                                                                                                                                                                          val = round(pct, self.decimals)
                                                                                                                                                                          return text_to_draw.replace(r"%p", str(val))
                                                                                                                                                                      case "max":
                                                                                                                                                                          val = round(self._max_value - self._min_value + 1, self.decimals)
                                                                                                                                                                          return text_to_draw.replace(r"%m", str(val))
                                                                                                                                                                      case _:
                                                                                                                                                                          raise ValueError(self._update_flags)
                                                                                                                                                          
                                                                                                                                                              def _value_format_changed(self):
                                                                                                                                                                  for k, v in VALUE_MAP.items():
                                                                                                                                                                      if k in self.number_format:
                                                                                                                                                                          self._update_flags = v
                                                                                                                                                                  self.update()
                                                                                                                                                          
                                                                                                                                                              def _rebuild_data_brush_if_needed(self):
                                                                                                                                                                  if not self._rebuild_brush or not self.gradient_data:
                                                                                                                                                                      return
                                                                                                                                                                  self._rebuild_brush = False
                                                                                                                                                                  data_brush: gui.RadialGradient | gui.ConicalGradient
                                                                                                                                                                  if self.bar_style == self.BarStyle.Expand:
                                                                                                                                                                      data_brush = gui.RadialGradient(0.5, 0.5, 0.5, 0.5, 0.5)
                                                                                                                                                                      for pos, color in self.gradient_data:
                                                                                                                                                                          data_brush[pos] = color
                                                                                                                                                                  else:
                                                                                                                                                                      data_brush = gui.ConicalGradient(0.5, 0.5, self.null_pos)
                                                                                                                                                                      for pos, color in self.gradient_data:
                                                                                                                                                                          data_brush[1 - pos] = color
                                                                                                                                                                  data_brush.set_coordinate_mode("stretch_to_device")
                                                                                                                                                                  with self.edit_palette() as palette:
                                                                                                                                                                      palette.set_brush("highlight", gui.Brush(data_brush))
                                                                                                                                                          
                                                                                                                                                              nullPosition = core.Property(  # noqa: N815
                                                                                                                                                                  enum.Enum,
                                                                                                                                                                  get_null_position,
                                                                                                                                                                  set_null_position,
                                                                                                                                                                  doc="Position for value = 0",
                                                                                                                                                              )
                                                                                                                                                          

                                                                                                                                                          BarStyle

                                                                                                                                                          Bases: IntEnum

                                                                                                                                                          Progress bar style.

                                                                                                                                                          Source code in prettyqt/custom_widgets/roundprogressbar.py
                                                                                                                                                          class BarStyle(enum.IntEnum):
                                                                                                                                                              """Progress bar style."""
                                                                                                                                                          
                                                                                                                                                              Donut = 1
                                                                                                                                                              Pie = 2
                                                                                                                                                              Line = 3
                                                                                                                                                              Expand = 4
                                                                                                                                                          

                                                                                                                                                          Position

                                                                                                                                                          Bases: float, Enum

                                                                                                                                                          Start position of progress bar in degrees.

                                                                                                                                                          Source code in prettyqt/custom_widgets/roundprogressbar.py
                                                                                                                                                          class Position(float, enum.Enum):
                                                                                                                                                              """Start position of progress bar in degrees."""
                                                                                                                                                          
                                                                                                                                                              Left = 180.0
                                                                                                                                                              Top = 90.0
                                                                                                                                                              Right = 0.0
                                                                                                                                                              Bottom = -90.0
                                                                                                                                                          

                                                                                                                                                          ValueType

                                                                                                                                                          Bases: IntEnum

                                                                                                                                                          Value type.

                                                                                                                                                          Source code in prettyqt/custom_widgets/roundprogressbar.py
                                                                                                                                                          class ValueType(enum.IntEnum):
                                                                                                                                                              """Value type."""
                                                                                                                                                          
                                                                                                                                                              value = 1
                                                                                                                                                              percent = 2
                                                                                                                                                              maximum = 3
                                                                                                                                                          

                                                                                                                                                          ScrollAreaTocWidget

                                                                                                                                                          Bases: TreeView

                                                                                                                                                          Source code in prettyqt/custom_widgets/scrollareatocwidget.py
                                                                                                                                                          class ScrollAreaTocWidget(widgets.TreeView):
                                                                                                                                                              section_changed = core.Signal()
                                                                                                                                                          
                                                                                                                                                              ScrollMode = ScrollMode
                                                                                                                                                              core.Enum(ScrollMode)
                                                                                                                                                          
                                                                                                                                                              def __init__(
                                                                                                                                                                  self,
                                                                                                                                                                  scrollarea: widgets.ScrollArea,
                                                                                                                                                                  orientation: (
                                                                                                                                                                      constants.Orientation | constants.OrientationStr
                                                                                                                                                                  ) = constants.VERTICAL,
                                                                                                                                                                  widget_class: type[widgets.QWidget] = widgets.QWidget,
                                                                                                                                                                  **kwargs,
                                                                                                                                                              ) -> None:
                                                                                                                                                                  """A TreeView which can show a Table-of-contents list based on a given ScrollArea.
                                                                                                                                                          
                                                                                                                                                                  With default settings, it will scan the widgets contained in the scrollArea for
                                                                                                                                                                   a windowTitle.
                                                                                                                                                                  These widgets will be shown in the TreeView, and the TreeView selection will be
                                                                                                                                                                  synced to what is currently visible in the ScrollArea.
                                                                                                                                                                  This basically emulates the behaviour of many websites
                                                                                                                                                                  (like the [Qt Website][https://doc.qt.io/qt-6/supported-platforms.html])
                                                                                                                                                                  or from VS code settings.
                                                                                                                                                          
                                                                                                                                                                  You can set up the Toc Tree by passing a ScrollArea instance:
                                                                                                                                                          
                                                                                                                                                                  ```py
                                                                                                                                                                  widget = widgets.Widget()
                                                                                                                                                                  layout = widget.set_layout("horizontal")
                                                                                                                                                                  scrollarea = widgets.ScrollArea()
                                                                                                                                                                  # add some widgets to the ScrollArea here
                                                                                                                                                                  # ...
                                                                                                                                                                  toc = ScrollAreaTocWidget(scrollarea)
                                                                                                                                                                  layout.add(toc)
                                                                                                                                                                  layout.add(scrollarea)
                                                                                                                                                                  ```
                                                                                                                                                          
                                                                                                                                                                  The Toc tree can be configured to use other properties for populating
                                                                                                                                                                  than windowTitle.
                                                                                                                                                                  You can also set a widget class filter if you only want a specific widget
                                                                                                                                                                  class to be shown.
                                                                                                                                                          
                                                                                                                                                                  The widget supports 3 different scroll modes:
                                                                                                                                                          
                                                                                                                                                                  1) Single: Only one row in the Tree will be highlighted. (the one which equals
                                                                                                                                                                  the topmost one from the scrollArea)
                                                                                                                                                                  2) Multi: All rows which equal to visible widgets in the ScrollArea will be shown.
                                                                                                                                                                  3) HeadersOnly: like Single, but only highlights top-level widgets from the
                                                                                                                                                                                  ScrollArea.
                                                                                                                                                          
                                                                                                                                                                  There are also two different expand modes to choose from:
                                                                                                                                                          
                                                                                                                                                                  1) ExpandAll: All subsections are always expanded.
                                                                                                                                                                  2) on_focus: Only the section containing the focused item is expanded.
                                                                                                                                                          
                                                                                                                                                                  This widget is used by [ConfigWidget](ConfigWidget.md).
                                                                                                                                                                  """
                                                                                                                                                                  # TODO: not sure if parent should always equal scrollarea..."""
                                                                                                                                                                  self._WidgetClass = widget_class
                                                                                                                                                                  self._scroll_mode = ScrollMode.Single
                                                                                                                                                                  self._always_expanded = False
                                                                                                                                                                  self._last_visible = None
                                                                                                                                                                  self.scrollarea = scrollarea
                                                                                                                                                                  super().__init__(scrollarea, **kwargs)
                                                                                                                                                                  self._orientation = constants.ORIENTATION.get_enum_value(orientation)
                                                                                                                                                                  self.setFixedWidth(200)
                                                                                                                                                                  self.h_header.hide()
                                                                                                                                                                  self.h_header.setStretchLastSection(True)
                                                                                                                                                                  self.setAlternatingRowColors(False)
                                                                                                                                                                  self.setRootIsDecorated(False)
                                                                                                                                                                  # self.setStyleSheet(
                                                                                                                                                                  #     """::item:hover {background: transparent; border-color:transparent}
                                                                                                                                                                  #     ::item:selected { border-color:transparent;
                                                                                                                                                                  #     border-style:outset; border-width:2px; color:black; }"""
                                                                                                                                                                  # )
                                                                                                                                                                  if self._orientation == constants.VERTICAL:
                                                                                                                                                                      scrollarea.v_scrollbar.valueChanged.connect(self._on_scroll)
                                                                                                                                                                  else:
                                                                                                                                                                      scrollarea.h_scrollbar.valueChanged.connect(self._on_scroll)
                                                                                                                                                                  self.set_widget(scrollarea)
                                                                                                                                                          
                                                                                                                                                              def _get_map(self):
                                                                                                                                                                  maps = super()._get_map()
                                                                                                                                                                  maps |= {"scrollMode": SCROLL_MODE}
                                                                                                                                                                  return maps
                                                                                                                                                          
                                                                                                                                                              def showEvent(self, event):
                                                                                                                                                                  super().showEvent(event)
                                                                                                                                                                  self._on_scroll()
                                                                                                                                                          
                                                                                                                                                              # @classmethod
                                                                                                                                                              # def setup_example(cls):
                                                                                                                                                              #     scrollarea = widgets.ScrollArea()
                                                                                                                                                              #     w = widgets.Widget()
                                                                                                                                                              #     scrollarea.set_widget(w)
                                                                                                                                                              #     return cls(scrollarea)
                                                                                                                                                          
                                                                                                                                                              def set_widget(self, widget: widgets.ScrollArea):
                                                                                                                                                                  """Set the ScrollArea widget to follow."""
                                                                                                                                                                  if (inner := widget.widget()) is None:
                                                                                                                                                                      msg = "No widget set on ScrollArea."
                                                                                                                                                                      raise RuntimeError(msg)
                                                                                                                                                                  self.scrollarea = widget
                                                                                                                                                                  model = ScrollAreaTocModel(
                                                                                                                                                                      inner,
                                                                                                                                                                      show_root=True,
                                                                                                                                                                      parent=self.scrollarea,
                                                                                                                                                                      widget_class=self._WidgetClass,
                                                                                                                                                                  )
                                                                                                                                                                  self.set_model(model)
                                                                                                                                                                  self.proxy = self.proxifier.set_sort_filter_proxy(
                                                                                                                                                                      recursive_filtering_enabled=True
                                                                                                                                                                  )
                                                                                                                                                                  self.proxy.set_filter_case_sensitive(False)
                                                                                                                                                                  self.show_root(False)
                                                                                                                                                                  inner.installEventFilter(self)
                                                                                                                                                                  self.selectionModel().currentRowChanged.connect(self._on_current_change)
                                                                                                                                                                  self.selectionModel().selectionChanged.connect(self._on_selection_change)
                                                                                                                                                                  # if self._always_expanded:
                                                                                                                                                                  self.expandAll()
                                                                                                                                                          
                                                                                                                                                              def _on_current_change(self, new, old):
                                                                                                                                                                  if self.model() is None:
                                                                                                                                                                      return
                                                                                                                                                                  is_vertical = self._orientation == constants.VERTICAL
                                                                                                                                                                  area = self.scrollarea
                                                                                                                                                                  scrollbar = area.v_scrollbar if is_vertical else area.h_scrollbar
                                                                                                                                                                  with self.signal_blocked(scrollbar.valueChanged, self._on_scroll):
                                                                                                                                                                      widget = self.model().data(new, role=constants.USER_ROLE)
                                                                                                                                                                      area.scroll_to_bottom()
                                                                                                                                                                      area.ensureWidgetVisible(widget, 10, 10)
                                                                                                                                                          
                                                                                                                                                              def _on_selection_change(self, new, old):
                                                                                                                                                                  if self.model() is None:
                                                                                                                                                                      return
                                                                                                                                                                  selected_widgets = [i.data(constants.USER_ROLE) for i in self.selected_indexes()]
                                                                                                                                                                  source_model = self.get_model(skip_proxies=True)
                                                                                                                                                                  if isinstance(source_model, ScrollAreaTocModel):
                                                                                                                                                                      source_model.set_highlighted_widgets(selected_widgets)
                                                                                                                                                          
                                                                                                                                                              def _on_scroll(self):
                                                                                                                                                                  model = cast("core.AbstractItemModel | None", self.model())
                                                                                                                                                                  if model is None:
                                                                                                                                                                      return
                                                                                                                                                                  visible_widgets = self.scrollarea.get_visible_widgets(typ=self._WidgetClass)
                                                                                                                                                                  if not visible_widgets or visible_widgets == self._last_visible:
                                                                                                                                                                      return
                                                                                                                                                                  self._last_visible = visible_widgets
                                                                                                                                                                  sig = self.selectionModel().currentRowChanged
                                                                                                                                                                  with self.signal_blocked(sig, self._on_current_change):
                                                                                                                                                                      self.select_index(None)
                                                                                                                                                                      if not self._always_expanded:
                                                                                                                                                                          self.collapseAll()
                                                                                                                                                                      match self.get_scroll_mode():
                                                                                                                                                                          case "multi":
                                                                                                                                                                              indexes = model.search_tree(visible_widgets, role=constants.USER_ROLE)
                                                                                                                                                                              for index in indexes:
                                                                                                                                                                                  children = model.get_child_indexes(index)
                                                                                                                                                                                  # only select if all children selected.
                                                                                                                                                                                  # if all(c in indexes for c in children):
                                                                                                                                                          
                                                                                                                                                                                  # highlight when no children or when first child is visible.
                                                                                                                                                                                  if not children or children[0] in indexes:
                                                                                                                                                                                      self.select_index(index, clear=False)
                                                                                                                                                                                  self.set_expanded(indexes)
                                                                                                                                                                                  self.scroll_to(indexes[0])
                                                                                                                                                                                  self.scroll_to(indexes[-1])
                                                                                                                                                                          case "headers_only":
                                                                                                                                                                              if indexes := model.search_tree(
                                                                                                                                                                                  visible_widgets,
                                                                                                                                                                                  role=constants.USER_ROLE,
                                                                                                                                                                                  max_results=1,
                                                                                                                                                                              ):
                                                                                                                                                                                  self.set_current_index(indexes[0])
                                                                                                                                                                                  self.scroll_to(indexes[0])
                                                                                                                                                                          case "single":
                                                                                                                                                                              if indexes := model.search_tree(
                                                                                                                                                                                  visible_widgets, role=constants.USER_ROLE
                                                                                                                                                                              ):
                                                                                                                                                                                  viewport = self.scrollarea.viewport()
                                                                                                                                                                                  # sort indexes by closest distance to top
                                                                                                                                                                                  indexes.sort(
                                                                                                                                                                                      key=lambda x: abs(
                                                                                                                                                                                          x
                                                                                                                                                                                          .data(constants.USER_ROLE)
                                                                                                                                                                                          .map_to(viewport, x.data(constants.USER_ROLE).rect())
                                                                                                                                                                                          .top()
                                                                                                                                                                                      ),
                                                                                                                                                                                  )
                                                                                                                                                                                  self.collapseAll()
                                                                                                                                                                                  self.model().fetchMore(indexes[0])
                                                                                                                                                                                  self.set_current_index(indexes[0])
                                                                                                                                                                                  self.scroll_to(indexes[0])
                                                                                                                                                                          case _:
                                                                                                                                                                              raise ValueError(self._scroll_mode)
                                                                                                                                                                  # model.set_highlighted_indexes(indexes)
                                                                                                                                                          
                                                                                                                                                              def wheelEvent(self, e):
                                                                                                                                                                  self.scrollarea.wheelEvent(e)
                                                                                                                                                          
                                                                                                                                                              def eventFilter(self, source: core.QObject, event: core.QEvent) -> bool:
                                                                                                                                                                  match event.type():
                                                                                                                                                                      case core.Event.Type.ChildAdded:
                                                                                                                                                                          self._on_scroll()
                                                                                                                                                                  return False
                                                                                                                                                          
                                                                                                                                                              def _scrollMode(self) -> ScrollMode:
                                                                                                                                                                  return self._scroll_mode
                                                                                                                                                          
                                                                                                                                                              def get_scroll_mode(self) -> ScrollModeStr:
                                                                                                                                                                  return SCROLL_MODE.inverse[self._scrollMode()]
                                                                                                                                                          
                                                                                                                                                              def set_scroll_mode(self, mode: ScrollMode | ScrollModeStr):
                                                                                                                                                                  self._scroll_mode = SCROLL_MODE.get_enum_value(mode)
                                                                                                                                                          
                                                                                                                                                              def is_always_expanded(self) -> bool:
                                                                                                                                                                  return self._always_expanded
                                                                                                                                                          
                                                                                                                                                              def set_always_expanded(self, always_expanded: bool):
                                                                                                                                                                  self._always_expanded = always_expanded
                                                                                                                                                          
                                                                                                                                                              scrollMode = core.Property(  # noqa: N815
                                                                                                                                                                  enum.Enum,
                                                                                                                                                                  _scrollMode,
                                                                                                                                                                  set_scroll_mode,
                                                                                                                                                                  doc="Scrolling mode",
                                                                                                                                                              )
                                                                                                                                                              always_expanded = core.Property(
                                                                                                                                                                  bool,
                                                                                                                                                                  is_always_expanded,
                                                                                                                                                                  set_always_expanded,
                                                                                                                                                                  doc="Whether the tree is always expanded.",
                                                                                                                                                              )
                                                                                                                                                          

                                                                                                                                                          __init__(scrollarea: widgets.ScrollArea, orientation: constants.Orientation | constants.OrientationStr = constants.VERTICAL, widget_class: type[widgets.QWidget] = widgets.QWidget, **kwargs) -> None

                                                                                                                                                          A TreeView which can show a Table-of-contents list based on a given ScrollArea.

                                                                                                                                                          With default settings, it will scan the widgets contained in the scrollArea for a windowTitle. These widgets will be shown in the TreeView, and the TreeView selection will be synced to what is currently visible in the ScrollArea. This basically emulates the behaviour of many websites (like the [Qt Website][https://doc.qt.io/qt-6/supported-platforms.html]) or from VS code settings.

                                                                                                                                                          You can set up the Toc Tree by passing a ScrollArea instance:

                                                                                                                                                          widget = widgets.Widget()
                                                                                                                                                          layout = widget.set_layout("horizontal")
                                                                                                                                                          scrollarea = widgets.ScrollArea()
                                                                                                                                                          # add some widgets to the ScrollArea here
                                                                                                                                                          # ...
                                                                                                                                                          toc = ScrollAreaTocWidget(scrollarea)
                                                                                                                                                          layout.add(toc)
                                                                                                                                                          layout.add(scrollarea)
                                                                                                                                                          

                                                                                                                                                          The Toc tree can be configured to use other properties for populating than windowTitle. You can also set a widget class filter if you only want a specific widget class to be shown.

                                                                                                                                                          The widget supports 3 different scroll modes:

                                                                                                                                                          1) Single: Only one row in the Tree will be highlighted. (the one which equals the topmost one from the scrollArea) 2) Multi: All rows which equal to visible widgets in the ScrollArea will be shown. 3) HeadersOnly: like Single, but only highlights top-level widgets from the ScrollArea.

                                                                                                                                                          There are also two different expand modes to choose from:

                                                                                                                                                          1) ExpandAll: All subsections are always expanded. 2) on_focus: Only the section containing the focused item is expanded.

                                                                                                                                                          This widget is used by ConfigWidget.

                                                                                                                                                          Source code in prettyqt/custom_widgets/scrollareatocwidget.py
                                                                                                                                                          def __init__(
                                                                                                                                                              self,
                                                                                                                                                              scrollarea: widgets.ScrollArea,
                                                                                                                                                              orientation: (
                                                                                                                                                                  constants.Orientation | constants.OrientationStr
                                                                                                                                                              ) = constants.VERTICAL,
                                                                                                                                                              widget_class: type[widgets.QWidget] = widgets.QWidget,
                                                                                                                                                              **kwargs,
                                                                                                                                                          ) -> None:
                                                                                                                                                              """A TreeView which can show a Table-of-contents list based on a given ScrollArea.
                                                                                                                                                          
                                                                                                                                                              With default settings, it will scan the widgets contained in the scrollArea for
                                                                                                                                                               a windowTitle.
                                                                                                                                                              These widgets will be shown in the TreeView, and the TreeView selection will be
                                                                                                                                                              synced to what is currently visible in the ScrollArea.
                                                                                                                                                              This basically emulates the behaviour of many websites
                                                                                                                                                              (like the [Qt Website][https://doc.qt.io/qt-6/supported-platforms.html])
                                                                                                                                                              or from VS code settings.
                                                                                                                                                          
                                                                                                                                                              You can set up the Toc Tree by passing a ScrollArea instance:
                                                                                                                                                          
                                                                                                                                                              ```py
                                                                                                                                                              widget = widgets.Widget()
                                                                                                                                                              layout = widget.set_layout("horizontal")
                                                                                                                                                              scrollarea = widgets.ScrollArea()
                                                                                                                                                              # add some widgets to the ScrollArea here
                                                                                                                                                              # ...
                                                                                                                                                              toc = ScrollAreaTocWidget(scrollarea)
                                                                                                                                                              layout.add(toc)
                                                                                                                                                              layout.add(scrollarea)
                                                                                                                                                              ```
                                                                                                                                                          
                                                                                                                                                              The Toc tree can be configured to use other properties for populating
                                                                                                                                                              than windowTitle.
                                                                                                                                                              You can also set a widget class filter if you only want a specific widget
                                                                                                                                                              class to be shown.
                                                                                                                                                          
                                                                                                                                                              The widget supports 3 different scroll modes:
                                                                                                                                                          
                                                                                                                                                              1) Single: Only one row in the Tree will be highlighted. (the one which equals
                                                                                                                                                              the topmost one from the scrollArea)
                                                                                                                                                              2) Multi: All rows which equal to visible widgets in the ScrollArea will be shown.
                                                                                                                                                              3) HeadersOnly: like Single, but only highlights top-level widgets from the
                                                                                                                                                                              ScrollArea.
                                                                                                                                                          
                                                                                                                                                              There are also two different expand modes to choose from:
                                                                                                                                                          
                                                                                                                                                              1) ExpandAll: All subsections are always expanded.
                                                                                                                                                              2) on_focus: Only the section containing the focused item is expanded.
                                                                                                                                                          
                                                                                                                                                              This widget is used by [ConfigWidget](ConfigWidget.md).
                                                                                                                                                              """
                                                                                                                                                              # TODO: not sure if parent should always equal scrollarea..."""
                                                                                                                                                              self._WidgetClass = widget_class
                                                                                                                                                              self._scroll_mode = ScrollMode.Single
                                                                                                                                                              self._always_expanded = False
                                                                                                                                                              self._last_visible = None
                                                                                                                                                              self.scrollarea = scrollarea
                                                                                                                                                              super().__init__(scrollarea, **kwargs)
                                                                                                                                                              self._orientation = constants.ORIENTATION.get_enum_value(orientation)
                                                                                                                                                              self.setFixedWidth(200)
                                                                                                                                                              self.h_header.hide()
                                                                                                                                                              self.h_header.setStretchLastSection(True)
                                                                                                                                                              self.setAlternatingRowColors(False)
                                                                                                                                                              self.setRootIsDecorated(False)
                                                                                                                                                              # self.setStyleSheet(
                                                                                                                                                              #     """::item:hover {background: transparent; border-color:transparent}
                                                                                                                                                              #     ::item:selected { border-color:transparent;
                                                                                                                                                              #     border-style:outset; border-width:2px; color:black; }"""
                                                                                                                                                              # )
                                                                                                                                                              if self._orientation == constants.VERTICAL:
                                                                                                                                                                  scrollarea.v_scrollbar.valueChanged.connect(self._on_scroll)
                                                                                                                                                              else:
                                                                                                                                                                  scrollarea.h_scrollbar.valueChanged.connect(self._on_scroll)
                                                                                                                                                              self.set_widget(scrollarea)
                                                                                                                                                          

                                                                                                                                                          set_widget(widget: widgets.ScrollArea)

                                                                                                                                                          Set the ScrollArea widget to follow.

                                                                                                                                                          Source code in prettyqt/custom_widgets/scrollareatocwidget.py
                                                                                                                                                          def set_widget(self, widget: widgets.ScrollArea):
                                                                                                                                                              """Set the ScrollArea widget to follow."""
                                                                                                                                                              if (inner := widget.widget()) is None:
                                                                                                                                                                  msg = "No widget set on ScrollArea."
                                                                                                                                                                  raise RuntimeError(msg)
                                                                                                                                                              self.scrollarea = widget
                                                                                                                                                              model = ScrollAreaTocModel(
                                                                                                                                                                  inner,
                                                                                                                                                                  show_root=True,
                                                                                                                                                                  parent=self.scrollarea,
                                                                                                                                                                  widget_class=self._WidgetClass,
                                                                                                                                                              )
                                                                                                                                                              self.set_model(model)
                                                                                                                                                              self.proxy = self.proxifier.set_sort_filter_proxy(
                                                                                                                                                                  recursive_filtering_enabled=True
                                                                                                                                                              )
                                                                                                                                                              self.proxy.set_filter_case_sensitive(False)
                                                                                                                                                              self.show_root(False)
                                                                                                                                                              inner.installEventFilter(self)
                                                                                                                                                              self.selectionModel().currentRowChanged.connect(self._on_current_change)
                                                                                                                                                              self.selectionModel().selectionChanged.connect(self._on_selection_change)
                                                                                                                                                              # if self._always_expanded:
                                                                                                                                                              self.expandAll()
                                                                                                                                                          

                                                                                                                                                          SidebarWidget

                                                                                                                                                          Bases: MainWindow

                                                                                                                                                          Source code in prettyqt/custom_widgets/sidebarwidget.py
                                                                                                                                                          class SidebarWidget(widgets.MainWindow):
                                                                                                                                                              SETTINGS_BUTTON_HEIGHT = 28
                                                                                                                                                          
                                                                                                                                                              def __init__(
                                                                                                                                                                  self,
                                                                                                                                                                  *args,
                                                                                                                                                                  show_settings: bool = False,
                                                                                                                                                                  main_layout: widgets.widget.LayoutStr | widgets.QLayout = "vertical",
                                                                                                                                                                  **kwargs,
                                                                                                                                                              ):
                                                                                                                                                                  super().__init__(*args, **kwargs)
                                                                                                                                                                  self._button_width = 100
                                                                                                                                                                  self._style: constants.ToolButtonStyleStr = "text_below_icon"
                                                                                                                                                                  self.button_map: dict[widgets.QWidget, widgets.QToolButton] = {}
                                                                                                                                                                  self.icon_map: dict[widgets.QWidget, gui.Icon] = {}
                                                                                                                                                                  self.sidebar = widgets.ToolBar(
                                                                                                                                                                      context_menu_policy="prevent",
                                                                                                                                                                      floatable=True,
                                                                                                                                                                      object_name="SidebarWidget",
                                                                                                                                                                      window_title="Sidebar",
                                                                                                                                                                  )
                                                                                                                                                                  self.sidebar.set_style(self._style)
                                                                                                                                                                  self.sidebar.set_allowed_areas("all")
                                                                                                                                                                  self.settings_menu = widgets.Menu()
                                                                                                                                                                  self.sidebar.set_icon_size(int(self._button_width * 0.7))
                                                                                                                                                                  if show_settings:
                                                                                                                                                                      self.settings_btn = self.sidebar.add_menu_button(
                                                                                                                                                                          "", icon="mdi.wrench", menu=self.settings_menu
                                                                                                                                                                      )
                                                                                                                                                                      self.settings_btn.setFixedSize(
                                                                                                                                                                          self._button_width, self.SETTINGS_BUTTON_HEIGHT
                                                                                                                                                                      )
                                                                                                                                                                      self.settings_btn.set_style("icon")
                                                                                                                                                                      self.sidebar.orientationChanged.connect(self._on_orientation_change)
                                                                                                                                                                      self.sidebar.add_separator()
                                                                                                                                                                  self.spacer_action = self.sidebar.add_spacer()
                                                                                                                                                                  self.add_toolbar(self.sidebar, "left")
                                                                                                                                                                  self.area = widgets.Widget()
                                                                                                                                                                  self._stack_layout = self.area.set_layout("stacked")
                                                                                                                                                                  w = widgets.Widget()
                                                                                                                                                                  w.set_layout(main_layout)
                                                                                                                                                                  self.main_layout = w.box
                                                                                                                                                                  self.main_layout.set_margin(0)
                                                                                                                                                                  self.main_layout += self.area
                                                                                                                                                                  self.setCentralWidget(w)
                                                                                                                                                          
                                                                                                                                                              def _on_orientation_change(self, orientation: constants.Orientation):
                                                                                                                                                                  if orientation == constants.HORIZONTAL:
                                                                                                                                                                      self.settings_btn.setFixedSize(34, 34)
                                                                                                                                                                  else:
                                                                                                                                                                      self.settings_btn.setFixedSize(
                                                                                                                                                                          self._button_width, self.SETTINGS_BUTTON_HEIGHT
                                                                                                                                                                      )
                                                                                                                                                          
                                                                                                                                                              def add_tab(
                                                                                                                                                                  self,
                                                                                                                                                                  item: widgets.QWidget,
                                                                                                                                                                  title: str,
                                                                                                                                                                  icon: datatypes.IconType | None = None,
                                                                                                                                                                  show: bool = False,
                                                                                                                                                                  shortcut: str | None = None,
                                                                                                                                                                  area: AreaStr = "top",
                                                                                                                                                              ):
                                                                                                                                                                  self._stack_layout.add(item)
                                                                                                                                                                  act = gui.Action(
                                                                                                                                                                      text=title,
                                                                                                                                                                      icon=icon,
                                                                                                                                                                      shortcut=shortcut or "",
                                                                                                                                                                      parent=self.sidebar,
                                                                                                                                                                      checkable=True,
                                                                                                                                                                      triggered=lambda: self.set_tab(item),
                                                                                                                                                                  )
                                                                                                                                                                  self.addAction(act)
                                                                                                                                                                  button = widgets.ToolButton(self.sidebar)
                                                                                                                                                                  button.setDefaultAction(act)
                                                                                                                                                                  button.setFixedWidth(self._button_width)
                                                                                                                                                                  button.set_style(self._style)
                                                                                                                                                                  if area == "top":
                                                                                                                                                                      self.sidebar.insertWidget(self.spacer_action, button)
                                                                                                                                                                  else:
                                                                                                                                                                      self.sidebar.addWidget(button)
                                                                                                                                                                  if len(self._stack_layout) == 1:
                                                                                                                                                                      button.setChecked(True)
                                                                                                                                                                  self.button_map[item] = button
                                                                                                                                                                  self.icon_map[item] = iconprovider.get_icon(icon)
                                                                                                                                                                  if show:
                                                                                                                                                                      self.set_tab(item)
                                                                                                                                                          
                                                                                                                                                              def set_marker(
                                                                                                                                                                  self, item: str | int | widgets.QWidget, color: datatypes.ColorType = "red"
                                                                                                                                                              ):
                                                                                                                                                                  widget = item if isinstance(item, widgets.QWidget) else self._get_widget(item)
                                                                                                                                                                  if widget == self._get_current_widget():
                                                                                                                                                                      return
                                                                                                                                                                  template = self.icon_map[widget]
                                                                                                                                                                  px = template.pixmap(100, 100)
                                                                                                                                                                  with gui.Painter(px) as painter:
                                                                                                                                                                      dot = gui.Pixmap.create_dot(color)
                                                                                                                                                                      painter.drawPixmap(0, 0, dot)
                                                                                                                                                                  icon = gui.Icon(px)
                                                                                                                                                                  self.button_map[widget].setIcon(icon)
                                                                                                                                                          
                                                                                                                                                              def _get_widget(self, item: str | int | widgets.QWidget) -> widgets.QWidget:
                                                                                                                                                                  """Returns widget page specified by name, offset or content."""
                                                                                                                                                                  match item:
                                                                                                                                                                      case int():
                                                                                                                                                                          return cast("widgets.QWidget", self._stack_layout[item])
                                                                                                                                                                      case str():
                                                                                                                                                                          w = self.area.find_child(widgets.QWidget, name=item, recursive=False)
                                                                                                                                                                          if w is None or w not in self._stack_layout:
                                                                                                                                                                              msg = "Layout does not contain the chosen widget"
                                                                                                                                                                              raise ValueError(msg)
                                                                                                                                                                          return w
                                                                                                                                                                      case _:
                                                                                                                                                                          raise TypeError(item)
                                                                                                                                                          
                                                                                                                                                              def _get_current_widget(self) -> widgets.QWidget:
                                                                                                                                                                  """Returns the currently selected widget page."""
                                                                                                                                                                  for k, v in self.button_map.items():
                                                                                                                                                                      if v.isChecked():
                                                                                                                                                                          return k
                                                                                                                                                                  msg = "no page activated."
                                                                                                                                                                  raise RuntimeError(msg)
                                                                                                                                                          
                                                                                                                                                              def set_tab(self, item: str | int | widgets.QWidget):
                                                                                                                                                                  widget = item if isinstance(item, widgets.QWidget) else self._get_widget(item)
                                                                                                                                                                  current = self._stack_layout.currentWidget()
                                                                                                                                                                  if current is not None:
                                                                                                                                                                      self.button_map[current].setChecked(False)
                                                                                                                                                                  self._stack_layout.setCurrentWidget(widget)
                                                                                                                                                                  self.button_map[widget].setChecked(True)
                                                                                                                                                          
                                                                                                                                                              def add_spacer(self) -> gui.QAction:
                                                                                                                                                                  return self.sidebar.add_spacer()
                                                                                                                                                          
                                                                                                                                                              def add_separator(self, text: str | None = None, area: AreaStr = "top"):
                                                                                                                                                                  if area == "top":
                                                                                                                                                                      self.sidebar.add_separator(text, before=self.spacer_action)
                                                                                                                                                                  else:
                                                                                                                                                                      self.sidebar.add_separator(text)
                                                                                                                                                          
                                                                                                                                                              def add_action(self, *args, area: AreaStr = "top", **kwargs):
                                                                                                                                                                  act = args[0] if args else gui.Action(**kwargs)
                                                                                                                                                                  self.addAction(act)
                                                                                                                                                                  button = widgets.ToolButton(self.sidebar)
                                                                                                                                                                  button.setDefaultAction(act)
                                                                                                                                                                  button.setFixedWidth(self._button_width)
                                                                                                                                                                  button.set_style(self._style)
                                                                                                                                                                  if area == "top":
                                                                                                                                                                      self.sidebar.insertWidget(self.spacer_action, button)
                                                                                                                                                                  else:
                                                                                                                                                                      self.sidebar.addWidget(button)
                                                                                                                                                                  return act
                                                                                                                                                          

                                                                                                                                                          SliceEdit

                                                                                                                                                          Bases: Widget

                                                                                                                                                          Simple editor to edit slices.

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/sliceedit.py
                                                                                                                                                          class SliceEdit(widgets.Widget):
                                                                                                                                                              """Simple editor to edit slices."""
                                                                                                                                                          
                                                                                                                                                              value_changed = core.Signal(slice)
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args, **kwargs):
                                                                                                                                                                  super().__init__(*args, **kwargs)
                                                                                                                                                                  self.set_margin(0)
                                                                                                                                                                  self.checkbox_start = widgets.CheckBox()
                                                                                                                                                                  self.checkbox_stop = widgets.CheckBox()
                                                                                                                                                                  self.checkbox_step = widgets.CheckBox()
                                                                                                                                                                  self.spinbox_start = widgets.SpinBox(maximum=999999, enabled=False)
                                                                                                                                                                  self.spinbox_stop = widgets.SpinBox(maximum=999999, enabled=False)
                                                                                                                                                                  self.spinbox_step = widgets.SpinBox(minimum=1, maximum=999999, enabled=False)
                                                                                                                                                                  layout = self.set_layout("horizontal", margin=0)
                                                                                                                                                                  layout.add(widgets.Label("Start", alignment="center_right"))
                                                                                                                                                                  layout.add(self.checkbox_start)
                                                                                                                                                                  layout.add(self.spinbox_start)
                                                                                                                                                                  layout.add(widgets.Label("Stop", alignment="center_right"))
                                                                                                                                                                  layout.add(self.checkbox_stop)
                                                                                                                                                                  layout.add(self.spinbox_stop)
                                                                                                                                                                  layout.add(widgets.Label("Step", alignment="center_right"))
                                                                                                                                                                  layout.add(self.checkbox_step)
                                                                                                                                                                  layout.add(self.spinbox_step)
                                                                                                                                                                  self.checkbox_start.value_changed.connect(self.spinbox_start.setEnabled)
                                                                                                                                                                  self.checkbox_stop.value_changed.connect(self.spinbox_stop.setEnabled)
                                                                                                                                                                  self.checkbox_step.value_changed.connect(self.spinbox_step.setEnabled)
                                                                                                                                                                  self.checkbox_start.toggled.connect(self._on_value_change)
                                                                                                                                                                  self.checkbox_stop.toggled.connect(self._on_value_change)
                                                                                                                                                                  self.checkbox_step.toggled.connect(self._on_value_change)
                                                                                                                                                                  self.spinbox_start.value_changed.connect(self._on_value_change)
                                                                                                                                                                  self.spinbox_stop.value_changed.connect(self._on_value_change)
                                                                                                                                                                  self.spinbox_step.value_changed.connect(self._on_value_change)
                                                                                                                                                          
                                                                                                                                                              def _on_value_change(self):
                                                                                                                                                                  self._value = self.get_value()
                                                                                                                                                                  self.value_changed.emit(self._value)
                                                                                                                                                          
                                                                                                                                                              def get_value(self) -> slice:
                                                                                                                                                                  start = (
                                                                                                                                                                      self.spinbox_start.get_value() if self.checkbox_start.isChecked() else None
                                                                                                                                                                  )
                                                                                                                                                                  stop = self.spinbox_stop.get_value() if self.checkbox_stop.isChecked() else None
                                                                                                                                                                  step = self.spinbox_step.get_value() if self.checkbox_step.isChecked() else None
                                                                                                                                                                  if step == 0:
                                                                                                                                                                      step = None
                                                                                                                                                                  return slice(start, stop, step)
                                                                                                                                                          
                                                                                                                                                              def set_value(self, value: slice | tuple[int | None, int | None, int | None]):
                                                                                                                                                                  if isinstance(value, tuple):
                                                                                                                                                                      value = slice(*value)
                                                                                                                                                                  self.checkbox_start.set_value(value.start is not None)
                                                                                                                                                                  self.checkbox_stop.set_value(value.stop is not None)
                                                                                                                                                                  self.checkbox_step.set_value(value.step is not None)
                                                                                                                                                                  self.spinbox_start.setEnabled(value.start is not None)
                                                                                                                                                                  self.spinbox_stop.setEnabled(value.stop is not None)
                                                                                                                                                                  self.spinbox_step.setEnabled(value.step is not None)
                                                                                                                                                                  if value.start is not None:
                                                                                                                                                                      self.spinbox_start.set_value(value.start)
                                                                                                                                                                  if value.stop is not None:
                                                                                                                                                                      self.spinbox_stop.set_value(value.stop)
                                                                                                                                                                  if value.step is not None:
                                                                                                                                                                      self.spinbox_step.set_value(value.step)
                                                                                                                                                          

                                                                                                                                                          SmoothScrollBar

                                                                                                                                                          Bases: ScrollBar

                                                                                                                                                          Source code in prettyqt/custom_widgets/scrollbars/smoothscrollbar.py
                                                                                                                                                          class SmoothScrollBar(widgets.ScrollBar):
                                                                                                                                                              scroll_ended = core.Signal()
                                                                                                                                                          
                                                                                                                                                              def __init__(
                                                                                                                                                                  self,
                                                                                                                                                                  orientation: constants.Orientation | constants.OrientationStr = "horizontal",
                                                                                                                                                                  parent: widgets.QAbstractScrollArea | None = None,
                                                                                                                                                                  animation_duration: int = 500,
                                                                                                                                                                  easing: core.easingcurve.TypeStr | core.QEasingCurve.Type = "out_cubic",
                                                                                                                                                                  trigger: bool = False,
                                                                                                                                                              ):
                                                                                                                                                                  super().__init__(orientation, parent)
                                                                                                                                                                  self._value = self.value()
                                                                                                                                                                  self.widget = parent
                                                                                                                                                                  self._animation = core.PropertyAnimation()
                                                                                                                                                                  self._animation.apply_to(self.value)
                                                                                                                                                                  self._animation.set_easing(easing)
                                                                                                                                                                  self._animation.setDuration(animation_duration)
                                                                                                                                                                  self._animation.finished.connect(self.scroll_ended)
                                                                                                                                                                  if self.widget is not None:
                                                                                                                                                                      self.widget.viewport().installEventFilter(self)
                                                                                                                                                                      if trigger:
                                                                                                                                                                          self.widget.horizontalScrollBar().valueChanged.connect(
                                                                                                                                                                              gui.Cursor.fake_mouse_move
                                                                                                                                                                          )
                                                                                                                                                          
                                                                                                                                                              def mouseMoveEvent(self, e):
                                                                                                                                                                  self._animation.stop()
                                                                                                                                                                  self._value = self.value()
                                                                                                                                                                  super().mouseMoveEvent(e)
                                                                                                                                                          
                                                                                                                                                              def mousePressEvent(self, e):
                                                                                                                                                                  self._animation.stop()
                                                                                                                                                                  self._value = self.value()
                                                                                                                                                                  super().mousePressEvent(e)
                                                                                                                                                          
                                                                                                                                                              def mouseReleaseEvent(self, e):
                                                                                                                                                                  self._animation.stop()
                                                                                                                                                                  self._value = self.value()
                                                                                                                                                                  super().mouseReleaseEvent(e)
                                                                                                                                                          
                                                                                                                                                              def setValue(self, value: int):
                                                                                                                                                                  if value == self.value():
                                                                                                                                                                      return
                                                                                                                                                                  self._animation.stop()
                                                                                                                                                                  self.scroll_ended.emit()
                                                                                                                                                                  self._animation.set_range(self.value(), value)
                                                                                                                                                                  self._animation.start()
                                                                                                                                                          
                                                                                                                                                              def scroll_by_value(self, value: int):
                                                                                                                                                                  """Scroll by given distance."""
                                                                                                                                                                  self._value += value
                                                                                                                                                                  self._value = min(max(self.minimum(), self._value), self.maximum())
                                                                                                                                                                  self.setValue(self._value)
                                                                                                                                                          
                                                                                                                                                              def scroll_to(self, value: int):
                                                                                                                                                                  """Scroll to given position."""
                                                                                                                                                                  self._value = value
                                                                                                                                                                  self._value = min(max(self.minimum(), self._value), self.maximum())
                                                                                                                                                                  self.setValue(self._value)
                                                                                                                                                          
                                                                                                                                                              def reset_value(self, value):
                                                                                                                                                                  self._value = value
                                                                                                                                                          
                                                                                                                                                              def eventFilter(self, source, event) -> bool:
                                                                                                                                                                  if (
                                                                                                                                                                      self.widget is not None
                                                                                                                                                                      and event.type() == core.Event.Type.Wheel
                                                                                                                                                                      and source == self.widget.viewport()
                                                                                                                                                                  ):
                                                                                                                                                                      v_bar = self.widget.verticalScrollBar()
                                                                                                                                                                      if isinstance(v_bar, SmoothScrollBar):
                                                                                                                                                                          v_bar.scroll_by_value(-event.angleDelta().y())
                                                                                                                                                                      else:
                                                                                                                                                                          v_bar.setValue(v_bar.value() - event.angleDelta().y())
                                                                                                                                                                      return True
                                                                                                                                                                  return False
                                                                                                                                                          
                                                                                                                                                              def set_animation_duration(self, duration: int):
                                                                                                                                                                  self._animation.setDuration(duration)
                                                                                                                                                          
                                                                                                                                                              def get_animation_duration(self) -> int:
                                                                                                                                                                  return self._animation.duration()
                                                                                                                                                          
                                                                                                                                                              def set_animation_easing(
                                                                                                                                                                  self,
                                                                                                                                                                  easing: core.easingcurve.TypeStr | core.QEasingCurve.Type = "out_cubic",
                                                                                                                                                              ):
                                                                                                                                                                  self._animation.set_easing(easing)
                                                                                                                                                          
                                                                                                                                                              def get_animation_easing(
                                                                                                                                                                  self,
                                                                                                                                                              ) -> core.easingcurve.TypeStr | Callable[[float], float]:
                                                                                                                                                                  return self._animation.get_easing()
                                                                                                                                                          
                                                                                                                                                              def animationEasing(self) -> core.QEasingCurve.Type:
                                                                                                                                                                  return self._animation.easingCurve().type()
                                                                                                                                                          
                                                                                                                                                              animation_duration = core.Property(
                                                                                                                                                                  int,
                                                                                                                                                                  get_animation_duration,
                                                                                                                                                                  set_animation_duration,
                                                                                                                                                                  doc="Duration for the animation",
                                                                                                                                                              )
                                                                                                                                                              animation_easing = core.Property(
                                                                                                                                                                  core.EasingCurve.Type,
                                                                                                                                                                  get_animation_easing,
                                                                                                                                                                  set_animation_easing,
                                                                                                                                                                  doc="Animation easing type",
                                                                                                                                                              )
                                                                                                                                                          

                                                                                                                                                          scroll_by_value(value: int)

                                                                                                                                                          Scroll by given distance.

                                                                                                                                                          Source code in prettyqt/custom_widgets/scrollbars/smoothscrollbar.py
                                                                                                                                                          def scroll_by_value(self, value: int):
                                                                                                                                                              """Scroll by given distance."""
                                                                                                                                                              self._value += value
                                                                                                                                                              self._value = min(max(self.minimum(), self._value), self.maximum())
                                                                                                                                                              self.setValue(self._value)
                                                                                                                                                          

                                                                                                                                                          scroll_to(value: int)

                                                                                                                                                          Scroll to given position.

                                                                                                                                                          Source code in prettyqt/custom_widgets/scrollbars/smoothscrollbar.py
                                                                                                                                                          def scroll_to(self, value: int):
                                                                                                                                                              """Scroll to given position."""
                                                                                                                                                              self._value = value
                                                                                                                                                              self._value = min(max(self.minimum(), self._value), self.maximum())
                                                                                                                                                              self.setValue(self._value)
                                                                                                                                                          

                                                                                                                                                          SpanSlider

                                                                                                                                                          Bases: Slider

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/spanslider.py
                                                                                                                                                           53
                                                                                                                                                           54
                                                                                                                                                           55
                                                                                                                                                           56
                                                                                                                                                           57
                                                                                                                                                           58
                                                                                                                                                           59
                                                                                                                                                           60
                                                                                                                                                           61
                                                                                                                                                           62
                                                                                                                                                           63
                                                                                                                                                           64
                                                                                                                                                           65
                                                                                                                                                           66
                                                                                                                                                           67
                                                                                                                                                           68
                                                                                                                                                           69
                                                                                                                                                           70
                                                                                                                                                           71
                                                                                                                                                           72
                                                                                                                                                           73
                                                                                                                                                           74
                                                                                                                                                           75
                                                                                                                                                           76
                                                                                                                                                           77
                                                                                                                                                           78
                                                                                                                                                           79
                                                                                                                                                           80
                                                                                                                                                           81
                                                                                                                                                           82
                                                                                                                                                           83
                                                                                                                                                           84
                                                                                                                                                           85
                                                                                                                                                           86
                                                                                                                                                           87
                                                                                                                                                           88
                                                                                                                                                           89
                                                                                                                                                           90
                                                                                                                                                           91
                                                                                                                                                           92
                                                                                                                                                           93
                                                                                                                                                           94
                                                                                                                                                           95
                                                                                                                                                           96
                                                                                                                                                           97
                                                                                                                                                           98
                                                                                                                                                           99
                                                                                                                                                          100
                                                                                                                                                          101
                                                                                                                                                          102
                                                                                                                                                          103
                                                                                                                                                          104
                                                                                                                                                          105
                                                                                                                                                          106
                                                                                                                                                          107
                                                                                                                                                          108
                                                                                                                                                          109
                                                                                                                                                          110
                                                                                                                                                          111
                                                                                                                                                          112
                                                                                                                                                          113
                                                                                                                                                          114
                                                                                                                                                          115
                                                                                                                                                          116
                                                                                                                                                          117
                                                                                                                                                          118
                                                                                                                                                          119
                                                                                                                                                          120
                                                                                                                                                          121
                                                                                                                                                          122
                                                                                                                                                          123
                                                                                                                                                          124
                                                                                                                                                          125
                                                                                                                                                          126
                                                                                                                                                          127
                                                                                                                                                          128
                                                                                                                                                          129
                                                                                                                                                          130
                                                                                                                                                          131
                                                                                                                                                          132
                                                                                                                                                          133
                                                                                                                                                          134
                                                                                                                                                          135
                                                                                                                                                          136
                                                                                                                                                          137
                                                                                                                                                          138
                                                                                                                                                          139
                                                                                                                                                          140
                                                                                                                                                          141
                                                                                                                                                          142
                                                                                                                                                          143
                                                                                                                                                          144
                                                                                                                                                          145
                                                                                                                                                          146
                                                                                                                                                          147
                                                                                                                                                          148
                                                                                                                                                          149
                                                                                                                                                          150
                                                                                                                                                          151
                                                                                                                                                          152
                                                                                                                                                          153
                                                                                                                                                          154
                                                                                                                                                          155
                                                                                                                                                          156
                                                                                                                                                          157
                                                                                                                                                          158
                                                                                                                                                          159
                                                                                                                                                          160
                                                                                                                                                          161
                                                                                                                                                          162
                                                                                                                                                          163
                                                                                                                                                          164
                                                                                                                                                          165
                                                                                                                                                          166
                                                                                                                                                          167
                                                                                                                                                          168
                                                                                                                                                          169
                                                                                                                                                          170
                                                                                                                                                          171
                                                                                                                                                          172
                                                                                                                                                          173
                                                                                                                                                          174
                                                                                                                                                          175
                                                                                                                                                          176
                                                                                                                                                          177
                                                                                                                                                          178
                                                                                                                                                          179
                                                                                                                                                          180
                                                                                                                                                          181
                                                                                                                                                          182
                                                                                                                                                          183
                                                                                                                                                          184
                                                                                                                                                          185
                                                                                                                                                          186
                                                                                                                                                          187
                                                                                                                                                          188
                                                                                                                                                          189
                                                                                                                                                          190
                                                                                                                                                          191
                                                                                                                                                          192
                                                                                                                                                          193
                                                                                                                                                          194
                                                                                                                                                          195
                                                                                                                                                          196
                                                                                                                                                          197
                                                                                                                                                          198
                                                                                                                                                          199
                                                                                                                                                          200
                                                                                                                                                          201
                                                                                                                                                          202
                                                                                                                                                          203
                                                                                                                                                          204
                                                                                                                                                          205
                                                                                                                                                          206
                                                                                                                                                          207
                                                                                                                                                          208
                                                                                                                                                          209
                                                                                                                                                          210
                                                                                                                                                          211
                                                                                                                                                          212
                                                                                                                                                          213
                                                                                                                                                          214
                                                                                                                                                          215
                                                                                                                                                          216
                                                                                                                                                          217
                                                                                                                                                          218
                                                                                                                                                          219
                                                                                                                                                          220
                                                                                                                                                          221
                                                                                                                                                          222
                                                                                                                                                          223
                                                                                                                                                          224
                                                                                                                                                          225
                                                                                                                                                          226
                                                                                                                                                          227
                                                                                                                                                          228
                                                                                                                                                          229
                                                                                                                                                          230
                                                                                                                                                          231
                                                                                                                                                          232
                                                                                                                                                          233
                                                                                                                                                          234
                                                                                                                                                          235
                                                                                                                                                          236
                                                                                                                                                          237
                                                                                                                                                          238
                                                                                                                                                          239
                                                                                                                                                          240
                                                                                                                                                          241
                                                                                                                                                          242
                                                                                                                                                          243
                                                                                                                                                          244
                                                                                                                                                          245
                                                                                                                                                          246
                                                                                                                                                          247
                                                                                                                                                          248
                                                                                                                                                          249
                                                                                                                                                          250
                                                                                                                                                          251
                                                                                                                                                          252
                                                                                                                                                          253
                                                                                                                                                          254
                                                                                                                                                          255
                                                                                                                                                          256
                                                                                                                                                          257
                                                                                                                                                          258
                                                                                                                                                          259
                                                                                                                                                          260
                                                                                                                                                          261
                                                                                                                                                          262
                                                                                                                                                          263
                                                                                                                                                          264
                                                                                                                                                          265
                                                                                                                                                          266
                                                                                                                                                          267
                                                                                                                                                          268
                                                                                                                                                          269
                                                                                                                                                          270
                                                                                                                                                          271
                                                                                                                                                          272
                                                                                                                                                          273
                                                                                                                                                          274
                                                                                                                                                          275
                                                                                                                                                          276
                                                                                                                                                          277
                                                                                                                                                          278
                                                                                                                                                          279
                                                                                                                                                          280
                                                                                                                                                          281
                                                                                                                                                          282
                                                                                                                                                          283
                                                                                                                                                          284
                                                                                                                                                          285
                                                                                                                                                          286
                                                                                                                                                          287
                                                                                                                                                          288
                                                                                                                                                          289
                                                                                                                                                          290
                                                                                                                                                          291
                                                                                                                                                          292
                                                                                                                                                          293
                                                                                                                                                          294
                                                                                                                                                          295
                                                                                                                                                          296
                                                                                                                                                          297
                                                                                                                                                          298
                                                                                                                                                          299
                                                                                                                                                          300
                                                                                                                                                          301
                                                                                                                                                          302
                                                                                                                                                          303
                                                                                                                                                          304
                                                                                                                                                          305
                                                                                                                                                          306
                                                                                                                                                          307
                                                                                                                                                          308
                                                                                                                                                          309
                                                                                                                                                          310
                                                                                                                                                          311
                                                                                                                                                          312
                                                                                                                                                          313
                                                                                                                                                          314
                                                                                                                                                          315
                                                                                                                                                          316
                                                                                                                                                          317
                                                                                                                                                          318
                                                                                                                                                          319
                                                                                                                                                          320
                                                                                                                                                          321
                                                                                                                                                          322
                                                                                                                                                          323
                                                                                                                                                          324
                                                                                                                                                          325
                                                                                                                                                          326
                                                                                                                                                          327
                                                                                                                                                          328
                                                                                                                                                          329
                                                                                                                                                          330
                                                                                                                                                          331
                                                                                                                                                          332
                                                                                                                                                          333
                                                                                                                                                          334
                                                                                                                                                          335
                                                                                                                                                          336
                                                                                                                                                          337
                                                                                                                                                          338
                                                                                                                                                          339
                                                                                                                                                          340
                                                                                                                                                          341
                                                                                                                                                          342
                                                                                                                                                          343
                                                                                                                                                          344
                                                                                                                                                          345
                                                                                                                                                          346
                                                                                                                                                          347
                                                                                                                                                          348
                                                                                                                                                          349
                                                                                                                                                          350
                                                                                                                                                          351
                                                                                                                                                          352
                                                                                                                                                          353
                                                                                                                                                          354
                                                                                                                                                          355
                                                                                                                                                          356
                                                                                                                                                          357
                                                                                                                                                          358
                                                                                                                                                          359
                                                                                                                                                          360
                                                                                                                                                          361
                                                                                                                                                          362
                                                                                                                                                          363
                                                                                                                                                          364
                                                                                                                                                          365
                                                                                                                                                          366
                                                                                                                                                          367
                                                                                                                                                          368
                                                                                                                                                          369
                                                                                                                                                          370
                                                                                                                                                          371
                                                                                                                                                          372
                                                                                                                                                          373
                                                                                                                                                          374
                                                                                                                                                          375
                                                                                                                                                          376
                                                                                                                                                          377
                                                                                                                                                          378
                                                                                                                                                          379
                                                                                                                                                          380
                                                                                                                                                          381
                                                                                                                                                          382
                                                                                                                                                          383
                                                                                                                                                          384
                                                                                                                                                          385
                                                                                                                                                          386
                                                                                                                                                          387
                                                                                                                                                          388
                                                                                                                                                          389
                                                                                                                                                          390
                                                                                                                                                          391
                                                                                                                                                          392
                                                                                                                                                          393
                                                                                                                                                          394
                                                                                                                                                          395
                                                                                                                                                          396
                                                                                                                                                          397
                                                                                                                                                          398
                                                                                                                                                          399
                                                                                                                                                          400
                                                                                                                                                          401
                                                                                                                                                          402
                                                                                                                                                          403
                                                                                                                                                          404
                                                                                                                                                          405
                                                                                                                                                          406
                                                                                                                                                          407
                                                                                                                                                          408
                                                                                                                                                          409
                                                                                                                                                          410
                                                                                                                                                          411
                                                                                                                                                          412
                                                                                                                                                          413
                                                                                                                                                          414
                                                                                                                                                          415
                                                                                                                                                          416
                                                                                                                                                          417
                                                                                                                                                          418
                                                                                                                                                          419
                                                                                                                                                          420
                                                                                                                                                          421
                                                                                                                                                          422
                                                                                                                                                          423
                                                                                                                                                          424
                                                                                                                                                          425
                                                                                                                                                          426
                                                                                                                                                          427
                                                                                                                                                          428
                                                                                                                                                          429
                                                                                                                                                          430
                                                                                                                                                          431
                                                                                                                                                          432
                                                                                                                                                          433
                                                                                                                                                          434
                                                                                                                                                          435
                                                                                                                                                          436
                                                                                                                                                          437
                                                                                                                                                          438
                                                                                                                                                          439
                                                                                                                                                          440
                                                                                                                                                          441
                                                                                                                                                          442
                                                                                                                                                          443
                                                                                                                                                          444
                                                                                                                                                          445
                                                                                                                                                          446
                                                                                                                                                          447
                                                                                                                                                          448
                                                                                                                                                          449
                                                                                                                                                          450
                                                                                                                                                          451
                                                                                                                                                          452
                                                                                                                                                          453
                                                                                                                                                          454
                                                                                                                                                          455
                                                                                                                                                          456
                                                                                                                                                          457
                                                                                                                                                          458
                                                                                                                                                          459
                                                                                                                                                          460
                                                                                                                                                          461
                                                                                                                                                          462
                                                                                                                                                          463
                                                                                                                                                          464
                                                                                                                                                          465
                                                                                                                                                          466
                                                                                                                                                          467
                                                                                                                                                          468
                                                                                                                                                          469
                                                                                                                                                          470
                                                                                                                                                          471
                                                                                                                                                          472
                                                                                                                                                          473
                                                                                                                                                          474
                                                                                                                                                          475
                                                                                                                                                          476
                                                                                                                                                          477
                                                                                                                                                          478
                                                                                                                                                          479
                                                                                                                                                          480
                                                                                                                                                          481
                                                                                                                                                          482
                                                                                                                                                          483
                                                                                                                                                          484
                                                                                                                                                          class SpanSlider(widgets.Slider):
                                                                                                                                                              value_changed = core.Signal(object)
                                                                                                                                                              lower_pos_changed = core.Signal(float)
                                                                                                                                                              upper_pos_changed = core.Signal(float)
                                                                                                                                                              slider_pressed = core.Signal(object)
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args, object_name: str = "span_slider", **kwargs):
                                                                                                                                                                  super().__init__("horizontal", *args, object_name=object_name, **kwargs)
                                                                                                                                                                  self.rangeChanged.connect(self.update_range)
                                                                                                                                                                  self.sliderReleased.connect(self._move_pressed_handle)
                                                                                                                                                          
                                                                                                                                                                  self.lower_val = 0.0
                                                                                                                                                                  self.upper_val = 0.0
                                                                                                                                                                  self.lower_pos = 0.0
                                                                                                                                                                  self.upper_pos = 0.0
                                                                                                                                                                  self.offset = 0
                                                                                                                                                                  self.position = 0.0
                                                                                                                                                                  self.last_pressed: str | None = None
                                                                                                                                                                  self.upper_pressed = widgets.Style.SubControl.SC_None
                                                                                                                                                                  self.lower_pressed = widgets.Style.SubControl.SC_None
                                                                                                                                                                  self.movement: MovementModeStr = "no_crossing"
                                                                                                                                                                  self._main_control: Literal["lower", "upper"] = "lower"
                                                                                                                                                                  self._first_movement = False
                                                                                                                                                                  self._block_tracking = False
                                                                                                                                                                  dark_color = self.palette().color(gui.Palette.ColorRole.Dark)
                                                                                                                                                                  self.gradient_left = dark_color.lighter(110)
                                                                                                                                                                  self.gradient_right = dark_color.lighter(110)
                                                                                                                                                          
                                                                                                                                                              def mousePressEvent(self, event):
                                                                                                                                                                  if self.minimum() == self.maximum() or event.buttons() ^ event.button():
                                                                                                                                                                      event.ignore()
                                                                                                                                                                      return
                                                                                                                                                          
                                                                                                                                                                  self.upper_pressed = self._handle_mouse_press(
                                                                                                                                                                      event.position(), self.upper_pressed, self.upper_val, "upper"
                                                                                                                                                                  )
                                                                                                                                                                  if self.upper_pressed != HANDLE_STYLE:
                                                                                                                                                                      self.lower_pressed = self._handle_mouse_press(
                                                                                                                                                                          event.position(), self.lower_pressed, self.lower_val, "lower"
                                                                                                                                                                      )
                                                                                                                                                          
                                                                                                                                                                  self._first_movement = True
                                                                                                                                                                  event.accept()
                                                                                                                                                          
                                                                                                                                                              def mouseMoveEvent(self, event):
                                                                                                                                                                  if HANDLE_STYLE not in (self.lower_pressed, self.upper_pressed):
                                                                                                                                                                      event.ignore()
                                                                                                                                                                      return
                                                                                                                                                          
                                                                                                                                                                  opt = widgets.StyleOptionSlider()
                                                                                                                                                                  self.initStyleOption(opt)
                                                                                                                                                                  m = self.style().pixelMetric(
                                                                                                                                                                      widgets.Style.PixelMetric.PM_MaximumDragDistance, opt, self
                                                                                                                                                                  )
                                                                                                                                                                  pixel_pos = int(self.pick(event.position()) - self.offset)
                                                                                                                                                                  new_pos = float(self._pixel_pos_to_value(pixel_pos))
                                                                                                                                                                  if m >= 0:
                                                                                                                                                                      r = self.rect().adjusted(-m, -m, m, m)
                                                                                                                                                                      if not r.contains(event.position().toPoint()):
                                                                                                                                                                          new_pos = self.position
                                                                                                                                                          
                                                                                                                                                                  # pick the preferred handle on the first movement
                                                                                                                                                                  if self._first_movement:
                                                                                                                                                                      if self.lower_val == self.upper_val:
                                                                                                                                                                          if new_pos < self.get_lower_value():
                                                                                                                                                                              self._swap_controls()
                                                                                                                                                                              self._first_movement = False
                                                                                                                                                                      else:
                                                                                                                                                                          self._first_movement = False
                                                                                                                                                          
                                                                                                                                                                  match HANDLE_STYLE, self.movement:
                                                                                                                                                                      case self.lower_pressed, "no_crossing":
                                                                                                                                                                          new_pos = min(new_pos, self.upper_val)
                                                                                                                                                                          self.set_lower_pos(new_pos)
                                                                                                                                                                      case self.lower_pressed, "no_overlap":
                                                                                                                                                                          new_pos = min(new_pos, self.upper_val - 1)
                                                                                                                                                                          self.set_lower_pos(new_pos)
                                                                                                                                                                      case self.lower_pressed, "free" if new_pos > self.upper_val:
                                                                                                                                                                          self._swap_controls()
                                                                                                                                                                          self.set_upper_pos(new_pos)
                                                                                                                                                                      case self.upper_pressed, "no_crossing":
                                                                                                                                                                          new_pos = max(new_pos, self.get_lower_value())
                                                                                                                                                                          self.set_upper_pos(new_pos)
                                                                                                                                                                      case self.upper_pressed, "no_overlap":
                                                                                                                                                                          new_pos = max(new_pos, self.get_lower_value() + 1)
                                                                                                                                                                          self.set_upper_pos(new_pos)
                                                                                                                                                                      case self.upper_pressed, "free" if new_pos < self.lower_val:
                                                                                                                                                                          self._swap_controls()
                                                                                                                                                                          self.set_lower_pos(new_pos)
                                                                                                                                                                  event.accept()
                                                                                                                                                          
                                                                                                                                                              def mouseReleaseEvent(self, event):
                                                                                                                                                                  super().mouseReleaseEvent(event)
                                                                                                                                                                  self.setSliderDown(False)
                                                                                                                                                                  self.lower_pressed = self.upper_pressed = widgets.Style.SubControl.SC_None
                                                                                                                                                                  self.update()
                                                                                                                                                          
                                                                                                                                                              def paintEvent(self, event):
                                                                                                                                                                  painter = widgets.StylePainter(self)
                                                                                                                                                          
                                                                                                                                                                  # ticks
                                                                                                                                                                  opt = widgets.StyleOptionSlider()
                                                                                                                                                                  self.initStyleOption(opt)
                                                                                                                                                                  opt.subControls = widgets.Style.SubControl.SC_SliderTickmarks
                                                                                                                                                                  painter.draw_complex_control("slider", opt)
                                                                                                                                                          
                                                                                                                                                                  # groove
                                                                                                                                                                  opt.sliderPosition = 20
                                                                                                                                                                  opt.sliderValue = 0
                                                                                                                                                                  opt.subControls = GROOVE_STYLE
                                                                                                                                                                  painter.draw_complex_control("slider", opt)
                                                                                                                                                          
                                                                                                                                                                  # handle rects
                                                                                                                                                                  opt.sliderPosition = int(self.lower_pos)
                                                                                                                                                                  lr = self.style().subControlRect(SLIDER_STYLE, opt, HANDLE_STYLE, self)
                                                                                                                                                                  lrv = self.pick(lr.center())
                                                                                                                                                                  opt.sliderPosition = int(self.upper_pos)
                                                                                                                                                                  ur = self.style().subControlRect(SLIDER_STYLE, opt, HANDLE_STYLE, self)
                                                                                                                                                                  urv = self.pick(ur.center())
                                                                                                                                                          
                                                                                                                                                                  # span
                                                                                                                                                                  minv = min(lrv, urv)
                                                                                                                                                                  maxv = max(lrv, urv)
                                                                                                                                                                  c = self.style().subControlRect(SLIDER_STYLE, opt, GROOVE_STYLE, self).center()
                                                                                                                                                                  if self.is_horizontal():
                                                                                                                                                                      rect = core.Rect(core.Point(minv, c.y() - 2), core.Point(maxv, c.y() + 1))
                                                                                                                                                                  else:
                                                                                                                                                                      rect = core.Rect(core.Point(c.x() - 2, minv), core.Point(c.x() + 1, maxv))
                                                                                                                                                                  self._draw_span(painter, rect)
                                                                                                                                                          
                                                                                                                                                                  # handles
                                                                                                                                                                  if self.last_pressed == "lower":
                                                                                                                                                                      self.draw_handle(painter, "upper")
                                                                                                                                                                      self.draw_handle(painter, "lower")
                                                                                                                                                                  else:
                                                                                                                                                                      self.draw_handle(painter, "lower")
                                                                                                                                                                      self.draw_handle(painter, "upper")
                                                                                                                                                          
                                                                                                                                                              def get_lower_value(self) -> float:
                                                                                                                                                                  return min(self.lower_val, self.upper_val)
                                                                                                                                                          
                                                                                                                                                              def set_lower_value(self, lower: float):
                                                                                                                                                                  self.set_span(lower, self.upper_val)
                                                                                                                                                          
                                                                                                                                                              def get_upper_value(self) -> float:
                                                                                                                                                                  return max(self.lower_val, self.upper_val)
                                                                                                                                                          
                                                                                                                                                              def set_upper_value(self, upper: float):
                                                                                                                                                                  self.set_span(self.lower_val, upper)
                                                                                                                                                          
                                                                                                                                                              def on_value_change(self):
                                                                                                                                                                  self.value_changed.emit((self.lower_val, self.upper_val))
                                                                                                                                                          
                                                                                                                                                              def get_value(self) -> tuple[float, float]:
                                                                                                                                                                  return (self.lower_val, self.upper_val)
                                                                                                                                                          
                                                                                                                                                              def set_value(self, value: tuple[float, float]):
                                                                                                                                                                  self.set_lower_value(value[0])
                                                                                                                                                                  self.set_upper_value(value[1])
                                                                                                                                                          
                                                                                                                                                              def get_movement_mode(self) -> MovementModeStr:
                                                                                                                                                                  return self.movement
                                                                                                                                                          
                                                                                                                                                              def set_movement_mode(self, mode: MovementModeStr):
                                                                                                                                                                  """Set movement mode.
                                                                                                                                                          
                                                                                                                                                                  Args:
                                                                                                                                                                      mode: movement mode for the main window
                                                                                                                                                          
                                                                                                                                                                  Raises:
                                                                                                                                                                      ValueError: movement mode type does not exist
                                                                                                                                                                  """
                                                                                                                                                                  if mode not in MOVEMENT_MODE:
                                                                                                                                                                      msg = "Invalid movement mode"
                                                                                                                                                                      raise ValueError(msg)
                                                                                                                                                                  self.movement = mode
                                                                                                                                                          
                                                                                                                                                              def set_span(self, lower: float, upper: float):
                                                                                                                                                                  low = clamp(min(lower, upper), self.minimum(), self.maximum())
                                                                                                                                                                  upp = clamp(max(lower, upper), self.minimum(), self.maximum())
                                                                                                                                                                  changed = False
                                                                                                                                                                  if low != self.lower_val:
                                                                                                                                                                      self.lower_val = low
                                                                                                                                                                      self.lower_pos = low
                                                                                                                                                                      changed = True
                                                                                                                                                                  if upp != self.upper_val:
                                                                                                                                                                      self.upper_val = upp
                                                                                                                                                                      self.upper_pos = upp
                                                                                                                                                                      changed = True
                                                                                                                                                                  if changed:
                                                                                                                                                                      self.on_value_change()
                                                                                                                                                                      self.update()
                                                                                                                                                          
                                                                                                                                                              def set_lower_pos(self, lower: float):
                                                                                                                                                                  if self.lower_pos == lower:
                                                                                                                                                                      return
                                                                                                                                                                  self.lower_pos = lower
                                                                                                                                                                  if not self.hasTracking():
                                                                                                                                                                      self.update()
                                                                                                                                                                  if self.isSliderDown():
                                                                                                                                                                      self.lower_pos_changed.emit(lower)
                                                                                                                                                                  if self.hasTracking() and not self._block_tracking:
                                                                                                                                                                      main = self._main_control == "lower"
                                                                                                                                                                      self.trigger_action("move", main)
                                                                                                                                                          
                                                                                                                                                              def set_upper_pos(self, upper: float):
                                                                                                                                                                  if self.upper_pos == upper:
                                                                                                                                                                      return
                                                                                                                                                                  self.upper_pos = upper
                                                                                                                                                                  if not self.hasTracking():
                                                                                                                                                                      self.update()
                                                                                                                                                                  if self.isSliderDown():
                                                                                                                                                                      self.upper_pos_changed.emit(upper)
                                                                                                                                                                  if self.hasTracking() and not self._block_tracking:
                                                                                                                                                                      main = self._main_control == "upper"
                                                                                                                                                                      self.trigger_action("move", main)
                                                                                                                                                          
                                                                                                                                                              def set_left_color(self, color: datatypes.ColorType):
                                                                                                                                                                  self.gradient_left = colors.get_color(color)
                                                                                                                                                                  self.update()
                                                                                                                                                          
                                                                                                                                                              def set_right_color(self, color: datatypes.ColorType):
                                                                                                                                                                  self.gradient_right = colors.get_color(color)
                                                                                                                                                                  self.update()
                                                                                                                                                          
                                                                                                                                                              def _move_pressed_handle(self):
                                                                                                                                                                  if self.last_pressed == "lower":
                                                                                                                                                                      if self.lower_pos != self.lower_val:
                                                                                                                                                                          main = self._main_control == "lower"
                                                                                                                                                                          self.trigger_action("move", main)
                                                                                                                                                                  elif self.last_pressed == "upper" and self.upper_pos != self.upper_val:
                                                                                                                                                                      main = self._main_control == "upper"
                                                                                                                                                                      self.trigger_action("move", main)
                                                                                                                                                          
                                                                                                                                                              def pick(self, p: datatypes.PointType) -> int:
                                                                                                                                                                  if isinstance(p, tuple):
                                                                                                                                                                      return p[0] if self.is_horizontal() else p[1]
                                                                                                                                                                  return p.x() if self.is_horizontal() else p.y()
                                                                                                                                                          
                                                                                                                                                              def trigger_action(self, action: ActionStr, main: bool):
                                                                                                                                                                  value = 0.0
                                                                                                                                                                  no = False
                                                                                                                                                                  up = False
                                                                                                                                                                  my_min = self.minimum()
                                                                                                                                                                  my_max = self.maximum()
                                                                                                                                                                  self._block_tracking = True
                                                                                                                                                                  main_control = main and self._main_control == "upper"
                                                                                                                                                                  alt_control = not main and self._main_control == "lower"
                                                                                                                                                                  is_upper_handle = main_control or alt_control
                                                                                                                                                                  val = self.upper_val if is_upper_handle else self.lower_val
                                                                                                                                                                  match action:
                                                                                                                                                                      case "single_step_add":
                                                                                                                                                                          up = is_upper_handle
                                                                                                                                                                          value = clamp(val + self.singleStep(), my_min, my_max)
                                                                                                                                                                      case "single_step_sub":
                                                                                                                                                                          up = is_upper_handle
                                                                                                                                                                          value = clamp(val - self.singleStep(), my_min, my_max)
                                                                                                                                                                      case "to_minimum":
                                                                                                                                                                          up = is_upper_handle
                                                                                                                                                                          value = my_min
                                                                                                                                                                      case "to_maximum":
                                                                                                                                                                          up = is_upper_handle
                                                                                                                                                                          value = my_max
                                                                                                                                                                      case "move":
                                                                                                                                                                          up = is_upper_handle
                                                                                                                                                                          no = True
                                                                                                                                                                      case "none":
                                                                                                                                                                          no = True
                                                                                                                                                          
                                                                                                                                                                  if not no and not up:
                                                                                                                                                                      match self.movement:
                                                                                                                                                                          case "no_crossing":
                                                                                                                                                                              value = min(value, self.upper_val)
                                                                                                                                                                          case "no_overlap":
                                                                                                                                                                              value = min(value, self.upper_val - 1)
                                                                                                                                                          
                                                                                                                                                                          case "free" if value > self.upper_val:
                                                                                                                                                                              self._swap_controls()
                                                                                                                                                                              self.set_upper_pos(value)
                                                                                                                                                                          case "free":
                                                                                                                                                                              self.set_lower_pos(value)
                                                                                                                                                                  elif not no:
                                                                                                                                                                      match self.movement:
                                                                                                                                                                          case "no_crossing":
                                                                                                                                                                              value = max(value, self.lower_val)
                                                                                                                                                                          case "no_overlap":
                                                                                                                                                                              value = max(value, self.lower_val + 1)
                                                                                                                                                          
                                                                                                                                                                          case "free" if value < self.lower_val:
                                                                                                                                                                              self._swap_controls()
                                                                                                                                                                              self.set_lower_pos(value)
                                                                                                                                                                          case "free":
                                                                                                                                                                              self.set_upper_pos(value)
                                                                                                                                                          
                                                                                                                                                                  self._block_tracking = False
                                                                                                                                                                  self.set_lower_value(self.lower_pos)
                                                                                                                                                                  self.set_upper_value(self.upper_pos)
                                                                                                                                                          
                                                                                                                                                              def _swap_controls(self):
                                                                                                                                                                  self.lower_val, self.upper_val = self.upper_val, self.lower_val
                                                                                                                                                                  self.lower_pressed, self.upper_pressed = self.upper_pressed, self.lower_pressed
                                                                                                                                                                  self.last_pressed = "upper" if self.last_pressed == "lower" else "lower"
                                                                                                                                                                  self._main_control = "upper" if self._main_control == "lower" else "lower"
                                                                                                                                                          
                                                                                                                                                              def update_range(self, min_, max_):
                                                                                                                                                                  # set_span() takes care of keeping span in range
                                                                                                                                                                  self.set_span(self.lower_val, self.upper_val)
                                                                                                                                                          
                                                                                                                                                              def _setup_painter(
                                                                                                                                                                  self,
                                                                                                                                                                  painter: widgets.StylePainter,
                                                                                                                                                                  orientation: Literal["horizontal", "vertical"],
                                                                                                                                                                  x1: int,
                                                                                                                                                                  y1: int,
                                                                                                                                                                  x2: int,
                                                                                                                                                                  y2: int,
                                                                                                                                                              ):
                                                                                                                                                                  highlight = self.palette().color(gui.Palette.ColorRole.Highlight)
                                                                                                                                                                  gradient = gui.LinearGradient(x1, y1, x2, y2)
                                                                                                                                                                  gradient[0] = highlight.darker(120)
                                                                                                                                                                  gradient[1] = highlight.lighter(108)
                                                                                                                                                                  painter.setBrush(gradient)
                                                                                                                                                          
                                                                                                                                                                  val = 130 if orientation == "horizontal" else 150
                                                                                                                                                                  painter.set_pen(color=highlight.darker(val), width=0)
                                                                                                                                                          
                                                                                                                                                              def _draw_span(self, painter: widgets.StylePainter, rect: core.Rect):
                                                                                                                                                                  opt = widgets.StyleOptionSlider()
                                                                                                                                                                  self.initStyleOption(opt)
                                                                                                                                                                  painter.set_pen(color=self.gradient_left, width=0)
                                                                                                                                                                  groove = self.style().subControlRect(SLIDER_STYLE, opt, GROOVE_STYLE, self)
                                                                                                                                                                  if opt.is_horizontal():
                                                                                                                                                                      groove.adjust(0, 0, -1, 0)
                                                                                                                                                                      self._setup_painter(
                                                                                                                                                                          painter,
                                                                                                                                                                          opt.get_orientation(),
                                                                                                                                                                          groove.center().x(),
                                                                                                                                                                          groove.top(),
                                                                                                                                                                          groove.center().x(),
                                                                                                                                                                          groove.bottom(),
                                                                                                                                                                      )
                                                                                                                                                                  else:
                                                                                                                                                                      groove.adjust(0, 0, 0, -1)
                                                                                                                                                                      self._setup_painter(
                                                                                                                                                                          painter,
                                                                                                                                                                          opt.get_orientation(),
                                                                                                                                                                          groove.left(),
                                                                                                                                                                          groove.center().y(),
                                                                                                                                                                          groove.right(),
                                                                                                                                                                          groove.center().y(),
                                                                                                                                                                      )
                                                                                                                                                          
                                                                                                                                                                  # draw groove
                                                                                                                                                                  intersected = core.RectF(rect.intersected(groove))
                                                                                                                                                                  gradient = gui.LinearGradient(intersected.topLeft(), intersected.topRight())
                                                                                                                                                                  gradient[0] = self.gradient_left
                                                                                                                                                                  gradient[1] = self.gradient_right
                                                                                                                                                                  painter.fillRect(intersected, gradient)
                                                                                                                                                          
                                                                                                                                                              def draw_handle(self, painter: widgets.StylePainter, handle: HandleStr):
                                                                                                                                                                  opt = self.get_style_option(handle)
                                                                                                                                                                  opt.subControls = HANDLE_STYLE
                                                                                                                                                                  pressed = self.lower_pressed if handle == "lower" else self.upper_pressed
                                                                                                                                                                  if pressed == HANDLE_STYLE:
                                                                                                                                                                      opt.activeSubControls = pressed
                                                                                                                                                                      opt.state |= widgets.Style.StateFlag.State_Sunken
                                                                                                                                                                  painter.draw_complex_control("slider", opt)
                                                                                                                                                          
                                                                                                                                                              def get_style_option(self, handle: HandleStr) -> widgets.StyleOptionSlider:
                                                                                                                                                                  option = widgets.StyleOptionSlider()
                                                                                                                                                                  self.initStyleOption(option)
                                                                                                                                                                  if handle == "lower":
                                                                                                                                                                      option.sliderPosition = int(self.lower_pos)
                                                                                                                                                                      option.sliderValue = int(self.lower_val)
                                                                                                                                                                  else:
                                                                                                                                                                      option.sliderPosition = int(self.upper_pos)
                                                                                                                                                                      option.sliderValue = int(self.upper_val)
                                                                                                                                                                  return option
                                                                                                                                                          
                                                                                                                                                              def _handle_mouse_press(
                                                                                                                                                                  self, pos: core.QPointF, control, value: float, handle: HandleStr
                                                                                                                                                              ):
                                                                                                                                                                  opt = self.get_style_option(handle)
                                                                                                                                                                  old_control = control
                                                                                                                                                                  control = self.style().hitTestComplexControl(
                                                                                                                                                                      SLIDER_STYLE, opt, pos.toPoint(), self
                                                                                                                                                                  )
                                                                                                                                                                  sr = self.style().subControlRect(SLIDER_STYLE, opt, HANDLE_STYLE, self)
                                                                                                                                                                  if control == HANDLE_STYLE:
                                                                                                                                                                      self.position = value
                                                                                                                                                                      self.offset = self.pick(pos.toPoint() - sr.topLeft())
                                                                                                                                                                      self.last_pressed = handle
                                                                                                                                                                      self.setSliderDown(True)
                                                                                                                                                                      self.slider_pressed.emit(handle)
                                                                                                                                                                  if control != old_control:
                                                                                                                                                                      self.update(sr)
                                                                                                                                                                  return control
                                                                                                                                                          
                                                                                                                                                              def _pixel_pos_to_value(self, pos: int) -> int:
                                                                                                                                                                  opt = widgets.StyleOptionSlider()
                                                                                                                                                                  self.initStyleOption(opt)
                                                                                                                                                                  gr = self.style().subControlRect(SLIDER_STYLE, opt, GROOVE_STYLE, self)
                                                                                                                                                                  sr = self.style().subControlRect(SLIDER_STYLE, opt, HANDLE_STYLE, self)
                                                                                                                                                                  if self.is_horizontal():
                                                                                                                                                                      len_slider = sr.width()
                                                                                                                                                                      slider_min = gr.x()
                                                                                                                                                                      slider_end = gr.right()
                                                                                                                                                                  else:
                                                                                                                                                                      len_slider = sr.height()
                                                                                                                                                                      slider_min = gr.y()
                                                                                                                                                                      slider_end = gr.bottom()
                                                                                                                                                          
                                                                                                                                                                  return widgets.Style.sliderValueFromPosition(
                                                                                                                                                                      self.minimum(),
                                                                                                                                                                      self.maximum(),
                                                                                                                                                                      pos - slider_min,
                                                                                                                                                                      slider_end - len_slider + 1 - slider_min,
                                                                                                                                                                      opt.upsideDown,
                                                                                                                                                                  )
                                                                                                                                                          
                                                                                                                                                              lower_value = core.Property(
                                                                                                                                                                  float,
                                                                                                                                                                  get_lower_value,
                                                                                                                                                                  set_lower_value,
                                                                                                                                                                  doc="Lower value",
                                                                                                                                                              )
                                                                                                                                                              upper_value = core.Property(
                                                                                                                                                                  float,
                                                                                                                                                                  get_upper_value,
                                                                                                                                                                  set_upper_value,
                                                                                                                                                                  doc="Upper value",
                                                                                                                                                              )
                                                                                                                                                          

                                                                                                                                                          set_movement_mode(mode: MovementModeStr)

                                                                                                                                                          Set movement mode.

                                                                                                                                                          Parameters:

                                                                                                                                                          Name Type Description Default
                                                                                                                                                          mode MovementModeStr

                                                                                                                                                          movement mode for the main window

                                                                                                                                                          required

                                                                                                                                                          Raises:

                                                                                                                                                          Type Description
                                                                                                                                                          ValueError

                                                                                                                                                          movement mode type does not exist

                                                                                                                                                          Source code in prettyqt/custom_widgets/editors/spanslider.py
                                                                                                                                                          def set_movement_mode(self, mode: MovementModeStr):
                                                                                                                                                              """Set movement mode.
                                                                                                                                                          
                                                                                                                                                              Args:
                                                                                                                                                                  mode: movement mode for the main window
                                                                                                                                                          
                                                                                                                                                              Raises:
                                                                                                                                                                  ValueError: movement mode type does not exist
                                                                                                                                                              """
                                                                                                                                                              if mode not in MOVEMENT_MODE:
                                                                                                                                                                  msg = "Invalid movement mode"
                                                                                                                                                                  raise ValueError(msg)
                                                                                                                                                              self.movement = mode
                                                                                                                                                          

                                                                                                                                                          StandardIconsWidget

                                                                                                                                                          Bases: Widget

                                                                                                                                                          Dialog showing standard icons.

                                                                                                                                                          Source code in prettyqt/custom_widgets/standardiconswidget.py
                                                                                                                                                          class StandardIconsWidget(widgets.Widget):
                                                                                                                                                              """Dialog showing standard icons."""
                                                                                                                                                          
                                                                                                                                                              def __init__(self, parent: widgets.QWidget | None = None):
                                                                                                                                                                  super().__init__(parent)
                                                                                                                                                                  layout = custom_widgets.MultiLineLayout(parent=self)
                                                                                                                                                                  for k in widgets.style.STANDARD_PIXMAP:
                                                                                                                                                                      icon_layout = widgets.HBoxLayout()
                                                                                                                                                                      icon = widgets.Application.get_style_icon(k)
                                                                                                                                                                      label = widgets.Label(pixmap=icon.pixmap(32, 32))
                                                                                                                                                                      icon_layout.addWidget(label)
                                                                                                                                                                      icon_layout.addWidget(widgets.LineEdit(k))
                                                                                                                                                                      layout.addLayout(icon_layout)
                                                                                                                                                                  self.set_layout(layout)
                                                                                                                                                                  self.set_title("Standard Platform Icons")
                                                                                                                                                                  icon = widgets.Application.get_style_icon("titlebar_menu_button")
                                                                                                                                                                  self.set_icon(icon)
                                                                                                                                                          

                                                                                                                                                          SubsequenceCompleter

                                                                                                                                                          Bases: Completer

                                                                                                                                                          QCompleter specialised for subsequence matching.

                                                                                                                                                          Source code in prettyqt/custom_widgets/subsequencecompleter.py
                                                                                                                                                          class SubsequenceCompleter(widgets.Completer):
                                                                                                                                                              """QCompleter specialised for subsequence matching."""
                                                                                                                                                          
                                                                                                                                                              def __init__(self, *args):
                                                                                                                                                                  super().__init__(*args)
                                                                                                                                                                  self.completion_search_term = ""
                                                                                                                                                                  self.source_model = None
                                                                                                                                                                  self.set_completion_mode("unfiltered_popup")
                                                                                                                                                                  self.proxy_model = SubsequenceProxyModel(parent=self)
                                                                                                                                                                  self.proxy_model.setFilterCaseSensitivity(self.caseSensitivity())
                                                                                                                                                                  self.set_case_sensitive(False)
                                                                                                                                                                  self._force_next_update = True
                                                                                                                                                                  self.path_updated.connect(self._on_path_updated)
                                                                                                                                                                  self.setCompletionRole(constants.DISPLAY_ROLE)
                                                                                                                                                          
                                                                                                                                                              def setModel(self, model: core.QAbstractItemModel):
                                                                                                                                                                  self.source_model = model
                                                                                                                                                                  self.proxy_model = SubsequenceProxyModel(parent=self)
                                                                                                                                                                  self.proxy_model.setFilterCaseSensitivity(self.caseSensitivity())
                                                                                                                                                                  self.proxy_model.set_search_term(self.completion_search_term)
                                                                                                                                                                  self.proxy_model.setSourceModel(self.source_model)
                                                                                                                                                                  super().setModel(self.proxy_model)
                                                                                                                                                                  self.proxy_model.invalidate_rows_filter()
                                                                                                                                                                  # self.proxy_model.sort(0)
                                                                                                                                                                  self._force_next_update = True
                                                                                                                                                          
                                                                                                                                                              # def __getattr__(self, key):
                                                                                                                                                              #     return getattr(self.proxy_model, key)
                                                                                                                                                          
                                                                                                                                                              def set_case_sensitive(self, value: bool):
                                                                                                                                                                  super().set_case_sensitive(value)
                                                                                                                                                                  self.proxy_model.set_filter_case_sensitive(value)
                                                                                                                                                          
                                                                                                                                                              def _on_path_updated(self, path: str):
                                                                                                                                                                  if path == self.completion_search_term:
                                                                                                                                                                      return
                                                                                                                                                                  self.completion_search_term = path
                                                                                                                                                                  count = self.completionCount()
                                                                                                                                                                  if count or len(self.completion_search_term) <= 1 or self._force_next_update:
                                                                                                                                                                      self.proxy_model.set_search_term(self.completion_search_term)
                                                                                                                                                                  if count > 1:
                                                                                                                                                                      self.proxy_model.sort(0)
                                                                                                                                                                  self._force_next_update = False
                                                                                                                                                                  self.proxy_model.invalidate_rows_filter()  # force sorting/filtering