Skip to content
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

Update Play slider #2

Merged
merged 3 commits into from
Oct 7, 2024
Merged

Conversation

t20100
Copy link

@t20100 t20100 commented Oct 7, 2024

Some propositions of changes for PR silx-kit#4176

Comment on lines +249 to +253
def value(self) -> int:
return self._spinbox.value()

def setValue(self, value: int):
self._spinbox.setValue(value)
Copy link
Author

Choose a reason for hiding this comment

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

Best to provide an API than accessing private attributes

self._build()

def _build(self):
self._framerate_action = SliderPlayWidgetAction(self, label="FPS:", tooltip="Display speed in frames per second")
Copy link
Author

Choose a reason for hiding this comment

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

Let's use CamelCase everywhere in Qt stuff

@@ -294,13 +329,17 @@ def __init__(self, parent=None):
self._playButton.setToolTip("Display movie with frames")
self._playButton.setIcon(icons.getQIcon("camera"))
self._playButton.setIconSize(iconSize)
self._playButton.setCheckable(True)
Copy link
Author

Choose a reason for hiding this comment

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

Use button checkstate rather than changing the icon (or the a real stop action should be used)

self.mainLayout.addWidget(self._playButton)

self._playButton.clicked.connect(self._playStopSequence)
self._playButton.toggled.connect(self._playButtonToggled)
Copy link
Author

Choose a reason for hiding this comment

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

Use toggled rather than clicked so it is also called when set programmatically.

self._menuPlaySlider = _PlayButtonContextMenu(self)
self._menuPlaySlider.sigFrameRateChanged.connect(self._frameRateChanged)
Copy link
Author

Choose a reason for hiding this comment

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

Update the timer interval when changing the frame rate: This enables changing the frame rate while playing

Comment on lines -363 to -370
def spinBoxFrameRate(self) -> qt.QSpinBox:
"""Returns the SpinBox widget for FrameRate display."""
return self._menuPlaySlider._framerate_action._spinbox

def spinBoxInterval(self) -> qt.QSpinBox:
"""Returns the SpinBox widget for interval display."""
return self._menuPlaySlider._interval_action._spinbox

Copy link
Author

Choose a reason for hiding this comment

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

Even if it is done for other widgets here, it is IMO not a good idea to expose internal widgets through the public API, it's best to provide the API to get/set the corresponding state.

def setInterval(self, value: int):
"""Set the Interval value for the PlaySlider"""
self.spinBoxInterval().setValue(value)
def setPlayImageStep(self, value: int):
Copy link
Author

Choose a reason for hiding this comment

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

Proposition to replace Interval which is quite generic (e.g., QTimer.setInterval which set the time interval) with something more specific.
Any better proposition welcomed

Comment on lines +422 to +427
def _playButtonToggled(self, checked: bool):
"""Start/Stop the slider sequence."""
if self.__timer.isActive():
self._stopTimer()
else:
self._startTimer()

if checked:
self.__timer.start()
return
self.__timer.stop()
Copy link
Author

Choose a reason for hiding this comment

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

Rework the QTimer and button to make it simpler: use the check state of the button to handle the QTimer

@EdgarGF93 EdgarGF93 merged commit 025d940 into EdgarGF93:play_slider Oct 7, 2024
6 of 9 checks passed
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.

2 participants