Skip to content

Commit

Permalink
feat: Autoplay replay when only one is specified.
Browse files Browse the repository at this point in the history
  • Loading branch information
alxbl committed Mar 9, 2020
1 parent b23d424 commit 309df75
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
9 changes: 7 additions & 2 deletions pyrdp/player/MainWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,13 @@ def __init__(self, bind_address: str, port: int, filesToRead: [str]):
optionsMenu.addAction(focusTabAction)
optionsMenu.addAction(closeTabOnCtrlW)

for fileName in filesToRead:
self.replayWindow.openFile(fileName)
# If there's only one replay, play it immediately.
if len(filesToRead) == 1:
self.tabManager.setCurrentWidget(self.replayWindow)
self.replayWindow.openFile(filesToRead[0], autoplay=True)
else:
for f in filesToRead:
self.replayWindow.openFile(f)

def onOpenFile(self):
fileNames, _ = QFileDialog.getOpenFileNames(self, "Open File(s)")
Expand Down
5 changes: 4 additions & 1 deletion pyrdp/player/ReplayTab.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ def __init__(self, fileName: str, parent: QWidget = None):
self.player = PlayerLayer()
self.player.addObserver(self.eventHandler)

def play(self):
self.controlBar.play.emit()

def readEvent(self, position: int):
"""
Read an event from the file at the given position.
Expand Down Expand Up @@ -84,4 +87,4 @@ def clear(self):

def onClose(self):
self.thread.close()
self.thread.wait()
self.thread.wait()
4 changes: 3 additions & 1 deletion pyrdp/player/ReplayWindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ class ReplayWindow(BaseWindow):
def __init__(self, options: Dict[str, object], parent: QWidget = None):
super().__init__(options, parent)

def openFile(self, fileName: str):
def openFile(self, fileName: str, autoplay: bool = False):
"""
Open a replay file and open a new tab.
:param fileName: replay path.
"""
tab = ReplayTab(fileName)
self.addTab(tab, fileName)
self.log.debug("Loading replay file %(arg1)s", {"arg1": fileName})
if autoplay:
tab.play()

0 comments on commit 309df75

Please sign in to comment.