Package: pyside6-utils
PySide6 - Utilspyside6-utilsimplements several useful PySide6 widgets, models and delegates as well as some utility functions.
The package contains registrars for these widgets, which can beused to register the widgets in QtDesignerto quickly build UI's.This package was mainly developed around the python Dataclass-functionality. It was created in tandem with the following package:Configurun - A tool to create and manage machine learning training/testing-configurations and run them automatically and/or remotely..Table of contentsPySide6 - UtilsTable of contentsFeaturesInstallationQt-DesignerWidgetsDataclassTreeviewPandasTableView(andPandasTableModel)ExtendedMdiArea/FramelessMdiWindowCollapsibleGroupBoxConsole WidgetFileExplorerViewOverlayWidgetRangeSelectorSquareFrameWidgetListWidgetSwitcherUtilityClassesModelsAcknowledgementsFeaturesA quick list of the main widgets:DataclassTreeview(andDataClassModel&DataClassEditorDelegate)A view/model/delegate combination which mirrors a python dataclass (@dataclass) object and provides editors for each of the types defined. Edits are propagated to the dataclass object. We can usedataclasses.field()to customize how attributes are displayed and to change the editor-type and constraints.PandasTableView(andPandasTableModel)Provide an easy way to show and edit pandas dataframesCollapsibleGroupBoxA groupbox that acts as a layout, when the user check/unchecks the groupbox, the contents collapseConsoleWidgetA console-like widget to which multiple files can be mirorred, user can select the items to view the consoleitem-contensExtendedMdiArea/FramelessMdiWindowBased on PySide6.QtWidgets.QMdiArea, provides a way to load frameless windows with a custom UI, while also retaining resize/move/etc. A custom UI example is provided in./ui/FrameslessMdiWindow.uiFileExplorerViewBuilt around the use of a QFileSystemModel - enables right-click operations and undo/redo actions, as well as the possibility to set a "highlighted" fileOverlayWidgetProvides a container-widget to which another widget can be provided, when turning the overlay-mode of this widget on, this widget will be overlayed over the contained widget(s)SquareFrameA small widget wrapper that enforces squareness. Useful when designing UI's in QtDesigner.RangeSelectorWidget to select a range of float/int/datetime, provides extra styling if ticks are provided.WidgetListWidget to which we can pass a widget-factory or widget-type. The user can then add/remove widgets of this type to the list.WidgetSwitcherWrapper aroundQtWidgets.QStackedWidget, provides a way to switch between multiple widgets.InstallationThe easiest way to install this package is using pip install:pipinstallpyside6-utilsThe package can also be manually installed by downloading this repository, extracting it to the desired install location and running:pipinstall<install_path>Qt-DesignerThis package provides registrars for the implemented widgets, which means that the widgets can be made available directly in qt-designer (note thatpyside6-designershould be used).
To enable this, the environment variablePYSIDE_DESIGNER_PLUGINSshould be set to the../pyside6_utils/registrars-folder.Alternatively, we can automatically set environment variables by using the provided pyside6 launch script. We can use this script by runningpyside6_utils/examples/run_qt_designer.pyor by importing and running therun_qt_designer()-function using:frompyside6_utilities.examplesimportrun_qt_designerrun_qt_designer()If all is well, this should result in the widgets showing up in the left-hand side of Qt-designer, e.g. for the views it should look like this:WidgetsNOTE: every widget-module contains arun_example_app()function, which starts a qt app and an example-instance of the widget in question, the following example-widget-images are pictures of these examples. Example:frompyside6_utils.widgets.data_class_tree_viewimportrun_example_appDataclassTreeview.run_example_app()DataclassTreeviewDataclassTreeview,DataClassModelandDataClassEditorDelegateare a view/model/delegate combination (resp.) which mirror a python dataclass (@dataclass) object and provides editors for each of the types defined.The model is mainly built around thefield()functionality of dataclasses, which allows the model to make use of the default values, type hints and other information provided by the dataclass.
For each field, we can provide additional information in themetadataattribute offield(), this information is used by the model to determine the editor/limits to use for the field.
The following metadata is supported:Metadata KeyTypeDescription"display_name"strName to display for this attribute in the view - defaults to the variable name itself"display_path"strPath to display this attribute - we can group/structure items when using a treeview - defaults to no parents"help"strHelp-message which will be shown when the user hovers over this item - empty by default"constraints"List[sklearn_param_validation constraints]Additional constraints on which the editor will be determined to apply to the field*, if none provided, use typehint of the field"required"boolWhether this field is required to be filled in - if true - a red background will appear if the value is not set"editable"boolWhether this field is editable - if false - the editor will be disabled*Constraints are (almost fully) sourced from thesklearn.utils._validationmodule and provides a way to constrain the dataclass fields such that the user can only enter valid values. They are also packed into this package underclasses.constraints. The following constraints are supported:ConstraintDescriptionEditor TypetypeThe type of the value should match the type of the constraintbased on typeOptions/ContainerThe value should be one of the options provided in the constraintQComboBoxStrOptionsThe value should be one of the str-options provided in the constraintQComboBoxIntervalThe value should be within the interval provided in the constraintQSpinBoxorQDoubleSpinBox(limited)NoneNoneis a valid value for this fieldtyping.OptionalAdds reset-button to editorRangeThe value should be within the range provided in the constraintQSpinBox(limited)ConstrainedList*(Custom - not part of Sklearn)Indicates a list of of values of a constrained typeBased on type of list*=For example,ConstrainedList([Interval(float, 0.0, 1.0), StrOptions(["string1", "string2"])])indicates a list of values that should either be a float between 0.0 and 1.0, or the string "string1" or "string2". The editor for this field would be constructed as aWidgetListwith aWidgetSwitcheras the factory-widget. TheWidgetSwitcherwould then have two widgets, one with aQSpinBoxand one with aQComboBoxas the editor.NOTE:the same editor would be the result of aTyping.List[typing.Union[float, str]]typehint, minus the bounded-interval constraint on the float:Default values are saved and can be reset using right-click context menu. Values that have changed from default will appear in bold.An example of a dataclass-view is shown below:The dataclass from which this example was generated can be found under./examples/example_dataclass.py.PandasTableView(andPandasTableModel)Provide an easy way to show and edit pandas dataframes. Pandas-table model adds the possibility to copy/paste data from excel, as well as current selection information (e.g. selected cells, average, total and sum).ExtendedMdiArea/FramelessMdiWindowBased on PySide6.QtWidgets.QMdiArea, provides a way to load frameless windows with a custom UI, while also retaining resize/move/etc. The ui used by default is provided in./ui/FrameslessMdiWindow.ui.We can drag, resize and move the windows as we would expect from a normal window. The windows can also be maximized and minimized using the buttons in the top-right corner. A custom UI can be provided, all functionality will be retained if the ui contains the following widgets:contentLayout(QtWidgets.QLayout): The layout that will be used to add the content-widgettitleBar(QtWidgets.QWidget): The widget that will be used as the title bar, we can drag the window by using this, the parent-mdi area context menu will also be made available when right-clicking this widgettitleLabel(QtWidgets.QLabel): The label that will be used to display the titlezoomButton(QtWidget.QButtton): If pressed, set window to fullscreenminimizeButton(QtWidget.QButtton): If pressed, minimize the windowCollapsibleGroupBoxA QtWidgets.QGroupbox that acts as a layout, when the user check/unchecks the groupbox, the contents collapse
When opened:When collapsed:Console WidgetWe can importconsole_from_file_itemfrompyside6_utils.models.console_widget_modelsto create console items which mirror a text-output file. We can then add these items to the console-widget usingConsoleWidget.add_item.The user can then scroll between the various console-outputs, which are updated every time the target file changes. This is especially useful for managing multiple output-files.FileExplorerViewBuilt around the use of a QFileSystemModel - enables right-click operations and undo/redo actions, as well as the possibility to set a "highlighted" fileOverlayWidgetProvides a container-widget to which another widget can be provided, when turning the overlay-mode of this widget on, this widget will be overlayed over the contained widget(s).RangeSelectorWidget to select a range of float/int/datetime etc. Can drag in the middle to change both, or drag on the edges to change only min/max.
Provides extra styling when ticks are enabled.SquareFrameEnforces squareness of the widget inside. Useful when designing UI's in QtDesigner.WidgetListWidget to which we can pass a widget-factory or widget-type. The user can then add/remove widgets of this type to the list.
A value-getter can be specified to easily get the values of all widgets in the list.WidgetSwitcherWrapper aroundQtWidgets.QStackedWidget, provides a way to switch between multiple widgets. A context menu can be accessed via right click or via the small triangle in the right-bottom corner, which allows the user to switch between the widgets.Especially useful in combination withWidgetList. Provides the same value-getter functionality asWidgetList.UtilityThe utility submodule provides the following UI-based utility items:catch_show_exception_in_popup_decoratorA decorator that catches exceptions and shows them in a popupSignalBlockerEnables us to temporarily block PySide6 signals using awithstatementutility_functionsSeveral smaller utility functions used in this packageClassesThe classes submodule provides several useful classes that do not depend on PySide6:constraintsSklearn constraints, used forDataClassModelto constrain the editor-type based on the type-hint of the fieldSerializableMainly useful for@dataclass-like classes to parse from/to jsonModelsThe models submodule provides an implementation of the following:ConsoleFromFileItem/ConsoleModelAlso seeConsoleFromFileWidget- A model/item combination that mirrors a text-file, used inConsoleWidget. Use theaddItem()method ofConsoleModelto add a new file to the model.DataclassModelAlso seeDataclassTreeview- A model that mirrors a python dataclass (@dataclass) object and provides editors for each of the types defined. Edits are propagated to the dataclass object.ExtendedSortFilterProxyModelImplements more advanced sorting (using multiple columns) and aset_filter_function(...)that can be used to use (multiple) custom methods to filter the model.FileExplorerModelAlso seeFileExplorerView- Enabled highlighting itemsPandasTableModelAlso seePandasTableView- Mirrors pandas dataframe to a Qt tablemodelAcknowledgementsThis package uses icons from (and based off) theTango Desktop Project.