Parameter Editor#
Parameter Editor: dialog for user-editable application parameters.
This Python code defines a PyQt5 widget called
ParameterEditor
. It is used for editing a set of parameters
and provides functionality for accepting or resetting changes
made to the parameter values.
|
Edit a set of parameters in a scrollable QWidget. |
- class pyQParamWidget.param_editor.ParameterEditor(*args: Any, **kwargs: Any)[source]#
Edit a set of parameters in a scrollable QWidget.
Here is a breakdown of the key components and their purpose:
The class inherits from
QtWidgets.QWidget
and represents a scrollable widget for editing a set of parameters.The
ui_file
attribute specifies the path to the UI file used for building the GUI. ThemyLoadUi
function is used to load the UI file and populate the widget with the necessary elements.
Overall, this code provides a flexible parameter editing widget with the ability to track changes, validate inputs, and handle user interactions for accepting or resetting changes.
NOTES FOR THE CALLER
Caller should not close this window if
ParameterEditor.dirty()
returnsTrue
.Before closing this window:
User must
Accept
orReset
any changes (which setsdirty=False
).Verify:
ParameterEditor.dirty() == True
Get values:
results = ParameterEditor.values()
ATRRIBUTES
ui_file (str): Names the UI file used for building the GUI. The
myLoadUi
function is used to load the UI file and populate the widget with the necessary elements.
PARAMETERS
parent (object): QWidget parent
parameters (dict): Dictionary of ParameterItemBase objects. These objects represent the parameters that will be displayed and edited in the
ParameterEditor
widget. Each parameter is associated with a key defined by the caller.
Return dictionary with only the changed values.
dirty
()Have values been changed?
setDirty
(dirty)Set the dirty (values have changed) flag.
values
()Returns a dictionary containing the current widget values of all parameters.
- changedValues()[source]#
Return dictionary with only the changed values.
The
changedValues
method returns a dictionary containing only the parameter values that have been changed by the user.Note
Result is always empty dictionary when
dirty==True
. Usevalues()
to get the final values.
- closeEvent(event)[source]#
Do not allow editor to be closed if there are unresolved changes.
The
closeEvent
method is overridden to prevent the widget from being closed if there are any unsaved changes. It displays an alert dialog to inform the user about the unsaved changes.
- dirty() bool [source]#
Have values been changed?
The
dirty
method returns a boolean indicating whether there are any unsaved changes in the widget.
- do_accept()#
Update original values from widget values and clear dirty flag.
Called when the Accept button is pressed.
- do_reset()#
Update widget values from original values and clear dirty flag.
Called when the Reset button is pressed.
- setDirty(dirty: bool)[source]#
Set the dirty (values have changed) flag. Make it visible.
The
setDirty
method sets the dirty flag and enables or disables the Accept and Reset buttons accordingly.