-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make ValueLabel formatting consistent with SpinBox #2254
base: master
Are you sure you want to change the base?
Conversation
That's the ValueLabel I'd like to have.
Going to tag @ixjlyons on this one since SpinBox has become his baby |
To avoid the braking of old code, added numerous properties. As the properties are very pythonic, added even more of them.
Hi @StSav012 Sorry I haven't given you a response/review in some time here... thanks for the PR! I still need to go over this closer, but I want to point out that pyqtgraph generally doesn't use the python property/getter/setters, as we adopt the Qt API naming convention by using methods with the associated property name like def brush(self) -> QBrush:
return self._brush
def setBrush(self, brush: QBrush) -> None:
self._brush = brush
return None The pyqtgraph code-base does have the use of the property decorator in a few places, but that's primarily for backward compatibility issues. Anyway, I'll try and read through this and give you some more thorough feedback shortly. |
These additions make sense to me. Aside from the getter/setter stuff mentioned above, I also wonder if it makes sense to refactor this and |
@StSav012 can you convert the python properties to Qt style setter and getter methods, I'll merge this. For example, for the def setValue(self, value):
self._value = value
....
def value(self):
return self._value |
@j9ac9k, I used Python properties to keep the class compatible with old code. In In theory, I can compose monstrous classes that would behave like a built-in Python float or string, but could be called and, then, syntax like def make_callable(x):
if callable(x):
return x # don't break the callable
class _Callable(type(x)):
def __call__(self) -> type(x):
return self
return _Callable(x)
class Foo:
def __init__(self):
self._egg = 1
self._spam = 'python'
@property
def egg(self):
return make_callable(self._egg)
@egg.setter
def egg(self, new_value) -> None:
self._egg = new_value
def setEgg(self, new_value) -> None:
self._egg = new_value
@property
def spam(self):
return make_callable(self._spam)
@spam.setter
def spam(self, new_value) -> None:
self._spam = new_value
def setSpam(self, new_value) -> None:
self._spam = new_value
foo = Foo()
# access any way
print(foo.egg, foo.spam())
print(foo.egg(), foo.spam)
# set as a property
foo.egg = 2
foo.spam = foo.spam().capitalize()
print(foo.egg, foo.spam())
print(foo.egg(), foo.spam)
# set in Qt style
foo.setEgg(foo.egg + 1)
foo.setSpam(foo.spam[::-1])
print(foo.egg, foo.spam())
print(foo.egg(), foo.spam) |
That's the ValueLabel I'd like to have.