Skip to content

Commit

Permalink
Merge pull request #467 from GoSecure/feature-player-show-time
Browse files Browse the repository at this point in the history
Player GUI: Added a label that shows time / total_time
  • Loading branch information
obilodeau committed Jan 19, 2024
2 parents a664c43 + 8ed6294 commit 3104808
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
34 changes: 33 additions & 1 deletion pyrdp/player/ReplayBar.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@ def __init__(self, duration: float, parent: QWidget = None):

self.log = logging.getLogger(LOGGER_NAMES.PLAYER)

# pretty display capture duration
self.duration = duration
self.duration_hours = int(self.duration // 3600)
remaining_seconds = int(self.duration % 3600)
minutes = int(remaining_seconds // 60)
seconds = int(remaining_seconds % 60)
if self.duration_hours > 0:
self.duration_pretty = "{:d}:{:02d}:{:02d}".format(
self.duration_hours, minutes, seconds)
else:
self.duration_pretty = "{:02d}:{:02d}".format(minutes, seconds)

self.button = PlayPauseButton()
self.button.setMaximumWidth(100)
self.button.clicked.connect(self.onButtonClicked)
Expand All @@ -36,9 +48,11 @@ def __init__(self, duration: float, parent: QWidget = None):

self.timeSlider = SeekBar()
self.timeSlider.setMinimum(0)
self.timeSlider.setMaximum(int(duration * 1000))
self.timeSlider.setMaximum(int(self.duration * 1000))
self.timeSlider.valueChanged.connect(self.onSeek)

self.timeLabel = QLabel(self.formatTimeLabel(0))

self.speedLabel = QLabel("Speed: 1x")

self.speedSlider = QSlider(Qt.Horizontal)
Expand All @@ -59,6 +73,7 @@ def __init__(self, duration: float, parent: QWidget = None):
horizontal = QHBoxLayout()
horizontal.addWidget(self.button)
horizontal.addWidget(self.timeSlider)
horizontal.addWidget(self.timeLabel)
vertical.addLayout(horizontal)

self.setLayout(vertical)
Expand All @@ -82,3 +97,20 @@ def onSpeedChanged(self):
self.log.debug("Slider changed value: %(arg1)d", {"arg1": speed})
self.speedLabel.setText("Speed: {}x".format(speed))
self.speedChanged.emit(speed)

def onTimeChanged(self, currentTime: float):
if currentTime >= self.duration:
currentTime = self.duration

self.timeLabel.setText(self.formatTimeLabel(currentTime))

def formatTimeLabel(self, current: float) -> str:
hours = int(current // 3600)
remaining_seconds = int(current % 3600)
minutes = int(remaining_seconds // 60)
seconds = int(remaining_seconds % 60)
if self.duration_hours > 0:
return "{:d}:{:02d}:{:02d} / {}".format(
hours, minutes, seconds, self.duration_pretty)
else:
return "{:02d}:{:02d} / {}".format(minutes, seconds, self.duration_pretty)
1 change: 1 addition & 0 deletions pyrdp/player/ReplayTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def onTimeUpdated(self, currentTime: float):
self.controlBar.timeSlider.blockSignals(True)
self.controlBar.timeSlider.setValue(int(currentTime * 1000))
self.controlBar.timeSlider.blockSignals(False)
self.controlBar.onTimeChanged(currentTime)

def clear(self):
"""
Expand Down

0 comments on commit 3104808

Please sign in to comment.