Skip to content

Add updatePristineValues arg to Parameter.setDefault#2853

Merged
outofculture merged 27 commits intopyqtgraph:masterfrom
outofculture:param-touch
Mar 7, 2024
Merged

Add updatePristineValues arg to Parameter.setDefault#2853
outofculture merged 27 commits intopyqtgraph:masterfrom
outofculture:param-touch

Conversation

@outofculture
Copy link
Copy Markdown
Contributor

@outofculture outofculture commented Oct 20, 2023

When a Parameter has its default changed, the value could change to match unless it has previously been modified by the user. The updatePristineValues argument will turn this behavior on, currently defaulting to False.

  • This also adds the valueModifiedSinceResetToDefault method, a necessary part of the implementation, but also a nice feature for possible application logic.
  • This also adds the hasValue method, to be better able to distinguish when a Parameter has an explicit value set.
  • This starts the deprecation countdown on being able to call without error value() and defaultValue() while they're respectively null.
  • This completes the deprecation of being able to use 'values' to specify the limits of a ListParameter.
  • This fixes a bug in PenParameter where the Qt setter methods were not being accessed properly.
  • This changes the behavior of the reset-to-default gui button: it will now be enabled if the parameter is in a dirty state relative to the default, not just an equal value comparison.
  • Various small cleanups and improvements of related code are included in this.

Other Tasks

Bump Dependency Versions

Files that need updates

Confirm the following files have been either updated or there has been a determination that no update is needed.

  • README.md
  • setup.py
  • tox.ini
  • .github/workflows/main.yml and associated requirements.txt and conda environemt.yml files
  • pyproject.toml
  • binder/requirements.txt
Pre-Release Checklist

Pre Release Checklist

  • Update version info in __init__.py
  • Update CHANGELOG primarily using contents from automated changelog generation in GitHub release page
  • Have git tag in the format of pyqtgraph-
Post-Release Checklist

Steps To Complete

  • Append .dev0 to __version__ in __init__.py
  • Announce on mail list
  • Announce on Twitter

import pyqtgraph as pg
import pytest

import pyqtgraph as pg

Check notice

Code scanning / CodeQL

Module is imported with 'import' and 'import from'

Module 'pyqtgraph' is imported with both 'import' and 'import from'.
Comment on lines +100 to +105
# with pytest.raises(ValueError):
# p.value()
# with pytest.raises(ValueError):
# p.defaultValue()
# with pytest.raises(ValueError):
# p.setToDefault()

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
@outofculture outofculture changed the title Add pinToDefault option to Parameter Add updatePristineValues arg to Parameter.setDefault Jan 19, 2024
Parameter.__init__(self, *args, **kargs)
@property
def itemClass(self):
from .bool import BoolParameterItem

Check notice

Code scanning / CodeQL

Cyclic import

Import of module [pyqtgraph.parametertree.parameterTypes.bool](1) begins an import cycle.
@property
def itemClass(self):
from .bool import BoolParameterItem
from .numeric import NumericParameterItem

Check notice

Code scanning / CodeQL

Cyclic import

Import of module [pyqtgraph.parametertree.parameterTypes.numeric](1) begins an import cycle.
def itemClass(self):
from .bool import BoolParameterItem
from .numeric import NumericParameterItem
from .str import StrParameterItem

Check notice

Code scanning / CodeQL

Cyclic import

Import of module [pyqtgraph.parametertree.parameterTypes.str](1) begins an import cycle.
Comment on lines +53 to +54
# with pytest.raises(ValueError):
# p.setToDefault()

Check notice

Code scanning / CodeQL

Commented-out code

This comment appears to contain commented-out code.
@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Feb 14, 2024

@ntjess want to look over this one? 😅

@ntjess
Copy link
Copy Markdown
Contributor

ntjess commented Feb 14, 2024

Is there a reason Parameter needs to be abstract? It can be valuable to track a value, state, and changed signals even if there isn't a defined type associated

@outofculture
Copy link
Copy Markdown
Contributor Author

Is there a reason Parameter needs to be abstract? It can be valuable to track a value, state, and changed signals even if there isn't a defined type associated

Good point. I was working back from the thought that there wasn't a generic widget that would make sense for editing a typeless parameter, but I hadn't considered that Parameters are useful outside of an interactive widget. The WidgetParameterItem.makeWidget method is already abstract, which is the most important part of signaling all this to a user, so yeah, I can skip the part of this PR that's about making Parameter abstract. Thanks for catching this!

except ImportError:
try:
from PySide6 import QtCore, QtGui, QtWidgets
from PySide6 import QtCore, QtGui, QtSvg, QtTest, QtWidgets
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious what the motivation here is for these extra imports? I'm not seeing them referenced elsewhere in the PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed while looking at a test that the pyi file was incomplete; we already import both of these in the actual Qt/__init__.py file. Though, now that I'm looking at it closer, they're both imported in blocks of

try:
    from PySide6 import QtTest
except ImportError as err:
    QtTest = FailedImport(err)

I don't know why QtTest wouldn't be available for import, but I'm guessing that maybe there are stripped-down distributions that don't include it? I don't know what that should mean for the pyi file, though. Probably any development environment is going to include the full qt library, which is what this file is intended for. However, the type-checking is going to run everywhere, regardless, and might throw an ImportError. Maybe I should just skip this and accept the lack of type hints... Thoughts?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh, QtTest is shown as being present in PySide6-essentials https://pypi.org/project/PySide6-Essentials/

That's weird it's not included, would it be under a different module or something?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the import worked fine on my machine just now?

In [1]: from PySide6 import QtTest

In [2]: import PySide6

In [3]: PySide6.__version__
Out[3]: '6.6.2'

In [4]:

Copy link
Copy Markdown
Contributor Author

@outofculture outofculture Mar 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

okay then, I say we tentatively go forward with importing like this in the pyi and expecting that nothing will blow up. I'll put in an issue to clean up Qt.py to keep it isolated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants