Skip to content

Commit

Permalink
Add input field to display and navigate video frame number
Browse files Browse the repository at this point in the history
This commit introduces a new feature to the video slider component. An input field has been added to the top left corner of the slider. This field displays the current frame number, allowing users to easily track their progress within the video. Additionally, users can now input a specific frame number into the field and, upon pressing enter, the slider will jump to that frame, enabling seamless navigation within the video timeline.
  • Loading branch information
healthonrails committed Apr 16, 2024
1 parent baa473a commit e634721
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions annolid/gui/widgets/video_slider.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,31 @@ def __init__(
self.headerSeries = dict()
self._draw_header()

# Adding QLineEdit for input value
self.input_value = QtWidgets.QLineEdit(str(self.value()), self)
self.input_value.setFixedWidth(60)
self.input_value.setAlignment(QtCore.Qt.AlignCenter)
self.input_value.editingFinished.connect(self.updateValueFromInput)
self.input_value.move(2, 2)

# Methods to match API for QSlider

def updateValueFromInput(self):
# Get the input text
input_text = self.input_value.text()
try:
# Try converting the input to float
input_val = float(input_text)
# Check if the input value is within the range
if self._val_min <= input_val <= self._val_max:
self.setValue(input_val)
else:
# Reset the input text if it's out of range
self.input_value.setText(str(self._val_main))
except ValueError:
# Reset the input text if it's not a valid float
self.input_value.setText(str(self._val_main))

def value(self) -> float:
"""Returns value of slider."""
return self._val_main
Expand All @@ -250,6 +273,9 @@ def setValue(self, val: float) -> float:
x = self._toPos(val)
self.handle.setPos(x, 0)
self.ensureVisible(x, 0, self._handle_width, 0, 3, 0)
if hasattr(self, 'input_value'):
# Update input text value with slider's current value
self.input_value.setText(str(self._val_main))

def setMinimum(self, min: float) -> float:
"""Sets minimum value for slider."""
Expand Down Expand Up @@ -1064,6 +1090,9 @@ def done(x, y):
self.mouseMoved.emit(scenePos.x(), scenePos.y())
self.mousePressed.emit(scenePos.x(), scenePos.y())

# Update input text value with slider's current value
self.input_value.setText(str(self._val_main))

def mouseMoveEvent(self, event):
"""Override method to emit mouseMoved signal on drag."""
scenePos = self.mapToScene(event.pos())
Expand Down

0 comments on commit e634721

Please sign in to comment.