keyboard shortcuts

This commit is contained in:
Page Asgardius 2024-09-09 12:03:09 -07:00
parent 54a8cd9b4f
commit 9c4050240b

View file

@ -6,7 +6,6 @@ from PyQt6.QtMultimedia import QMediaPlayer, QAudioOutput
from PyQt6.QtMultimediaWidgets import QVideoWidget from PyQt6.QtMultimediaWidgets import QVideoWidget
from PyQt6.QtCore import QUrl, Qt, QEvent from PyQt6.QtCore import QUrl, Qt, QEvent
class VideoPlayer(QMainWindow): class VideoPlayer(QMainWindow):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
@ -21,16 +20,12 @@ class VideoPlayer(QMainWindow):
self.video_widget = QVideoWidget() self.video_widget = QVideoWidget()
self.installEventFilter(self) self.installEventFilter(self)
self.start_button = QPushButton("Start") self.start_button = QPushButton("▷||")
self.start_button.setFixedSize(60, 33) self.start_button.setFixedSize(33, 33)
self.start_button.clicked.connect(self.start_video) self.start_button.clicked.connect(self.start_video)
self.pause_button = QPushButton("Pause") self.stop_button = QPushButton("")
self.pause_button.setFixedSize(60, 33) self.stop_button.setFixedSize(33, 33)
self.pause_button.clicked.connect(self.pause_video)
self.stop_button = QPushButton("Stop")
self.stop_button.setFixedSize(60, 33)
self.stop_button.clicked.connect(self.stop_video) self.stop_button.clicked.connect(self.stop_video)
self.slider = QSlider(Qt.Orientation.Horizontal) self.slider = QSlider(Qt.Orientation.Horizontal)
@ -47,11 +42,11 @@ class VideoPlayer(QMainWindow):
layout = QVBoxLayout() layout = QVBoxLayout()
controls = QHBoxLayout() controls = QHBoxLayout()
controls.addWidget(self.start_button) controls.addWidget(self.start_button)
controls.addWidget(self.pause_button)
controls.addWidget(self.stop_button) controls.addWidget(self.stop_button)
controls.addWidget(self.slider)
layout.addWidget(self.video_widget) layout.addWidget(self.video_widget)
layout.addLayout(controls) layout.addLayout(controls)
layout.addWidget(self.slider) #layout.addWidget(self.slider)
container = QWidget() container = QWidget()
container.setLayout(layout) container.setLayout(layout)
@ -60,13 +55,10 @@ class VideoPlayer(QMainWindow):
def set_layout(self): def set_layout(self):
self.video_widget = QVideoWidget() self.video_widget = QVideoWidget()
self.start_button = QPushButton("Start") self.start_button = QPushButton("▷||")
self.start_button.setFixedSize(60, 33) self.start_button.setFixedSize(60, 33)
self.start_button.clicked.connect(self.start_video) self.start_button.clicked.connect(self.start_video)
self.pause_button = QPushButton("Pause") self.stop_button = QPushButton("")
self.pause_button.setFixedSize(60, 33)
self.pause_button.clicked.connect(self.pause_video)
self.stop_button = QPushButton("Stop")
self.stop_button.setFixedSize(60, 33) self.stop_button.setFixedSize(60, 33)
self.stop_button.clicked.connect(self.stop_video) self.stop_button.clicked.connect(self.stop_video)
self.slider = QSlider(Qt.Orientation.Horizontal) self.slider = QSlider(Qt.Orientation.Horizontal)
@ -75,21 +67,23 @@ class VideoPlayer(QMainWindow):
layout = QVBoxLayout() layout = QVBoxLayout()
controls = QHBoxLayout() controls = QHBoxLayout()
controls.addWidget(self.start_button) controls.addWidget(self.start_button)
controls.addWidget(self.pause_button)
controls.addWidget(self.stop_button) controls.addWidget(self.stop_button)
controls.addWidget(self.slider)
layout.addWidget(self.video_widget) layout.addWidget(self.video_widget)
layout.addLayout(controls) layout.addLayout(controls)
layout.addWidget(self.slider) #layout.addWidget(self.slider)
container = QWidget() container = QWidget()
container.setLayout(layout) container.setLayout(layout)
self.setCentralWidget(container) self.setCentralWidget(container)
def start_video(self): def start_video(self):
self.media_player.play() if self.media_player.isPlaying():
self.media_player.pause()
def pause_video(self): #self.start_button.setText("Play")
self.media_player.pause() else:
self.media_player.play()
#self.start_button.setText("Pause")
def stop_video(self): def stop_video(self):
self.media_player.stop() self.media_player.stop()
@ -116,17 +110,17 @@ class VideoPlayer(QMainWindow):
else: else:
if self.isMaximized(): if self.isMaximized():
self.fswindow = 1 self.fswindow = 1
print("maximized") #print("maximized")
else: else:
self.fswindow = 2 self.fswindow = 2
self.showFullScreen() self.showFullScreen()
self.setCentralWidget(self.video_widget) self.setCentralWidget(self.video_widget)
def dclickthr(self): def dclickthr(self):
self.dclick = True self.dclick = True
print(self.dclick) #print(self.dclick)
time.sleep(0.5) time.sleep(0.5)
self.dclick = False self.dclick = False
print(self.dclick) #print(self.dclick)
def eventFilter(self, obj, event): def eventFilter(self, obj, event):
@ -137,6 +131,18 @@ class VideoPlayer(QMainWindow):
dclickth = threading.Thread(target=self.dclickthr, name="Double Click") dclickth = threading.Thread(target=self.dclickthr, name="Double Click")
dclickth.start() dclickth.start()
#print(event.type()) #print(event.type())
elif event.type() == QEvent.Type.KeyPress:
if event.key() == 83:
self.media_player.stop()
elif event.key() == 68:
self.media_player.setPosition(self.media_player.position()+5000)
elif event.key() == 65:
self.media_player.setPosition(self.media_player.position()-5000)
elif event.key() == 87:
self.start_video()
elif event.key() == 70:
self.toglefs()
#print(event.key())
return True return True