Skip to content

Commit

Permalink
Updating keypress detection for arrow keys, moving to QShortcut on We…
Browse files Browse the repository at this point in the history
…bview, to fix issues on WebEngine which would eat certain keypress events (left, right, up, down)
  • Loading branch information
jonoomph committed Apr 1, 2023
1 parent 19ef8fc commit 65ce747
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 37 deletions.
4 changes: 0 additions & 4 deletions src/settings/_default.settings
Original file line number Diff line number Diff line change
Expand Up @@ -738,10 +738,6 @@
"value": "-",
"type": "text"
},




{
"category": "Keyboard",
"title": "Previous Frame",
Expand Down
33 changes: 1 addition & 32 deletions src/windows/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -1592,45 +1592,14 @@ def keyPressEvent(self, event):
fps_float = float(fps["num"]) / float(fps["den"])
playhead_position = float(self.preview_thread.current_frame - 1) / fps_float

# Basic shortcuts i.e just a letter
if key.matches(self.getShortcutByName("seekPreviousFrame")) == QKeySequence.ExactMatch:
# Pause video
self.PauseSignal.emit()
self.SpeedSignal.emit(0)
# Seek to previous frame
self.SeekSignal.emit(player.Position() - 1)

# Notify properties dialog
self.propertyTableView.select_frame(player.Position())

elif key.matches(self.getShortcutByName("seekNextFrame")) == QKeySequence.ExactMatch:
# Pause video
self.PauseSignal.emit()
self.SpeedSignal.emit(0)
# Seek to next frame
self.SeekSignal.emit(player.Position() + 1)

# Notify properties dialog
self.propertyTableView.select_frame(player.Position())

elif key.matches(self.getShortcutByName("rewindVideo")) == QKeySequence.ExactMatch:
if key.matches(self.getShortcutByName("rewindVideo")) == QKeySequence.ExactMatch:
# Toggle rewind and start playback
self.actionRewind.trigger()

elif key.matches(self.getShortcutByName("fastforwardVideo")) == QKeySequence.ExactMatch:
# Toggle fastforward button and start playback
self.actionFastForward.trigger()

elif any([
key.matches(self.getShortcutByName("playToggle")) == QKeySequence.ExactMatch,
key.matches(self.getShortcutByName("playToggle1")) == QKeySequence.ExactMatch,
key.matches(self.getShortcutByName("playToggle2")) == QKeySequence.ExactMatch,
key.matches(self.getShortcutByName("playToggle3")) == QKeySequence.ExactMatch,
]):
# Toggle playbutton and show properties
self.actionPlay.trigger()
self.propertyTableView.select_frame(player.Position())

elif any([
key.matches(self.getShortcutByName("deleteItem")) == QKeySequence.ExactMatch,
key.matches(self.getShortcutByName("deleteItem1")) == QKeySequence.ExactMatch,
Expand Down
49 changes: 48 additions & 1 deletion src/windows/views/webview.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

from PyQt5.QtCore import QFileInfo, pyqtSlot, QUrl, Qt, QCoreApplication, QTimer, pyqtSignal
from PyQt5.QtGui import QCursor, QKeySequence, QColor
from PyQt5.QtWidgets import QMenu, QDialog
from PyQt5.QtWidgets import QMenu, QDialog, QShortcut

from classes import info, updates
from classes.app import get_app
Expand Down Expand Up @@ -3309,6 +3309,43 @@ def render_cache_json(self):
# Log the exception and ignore
log.warning("Exception processing timeline cache: %s", ex)

def seekPreviousFrame(self):
"""Handle previous-frame keypress"""
player = get_app().window.preview_thread.player
frame_num = player.Position() - 1

# Seek to prevoius frame
get_app().window.PauseSignal.emit()
get_app().window.SpeedSignal.emit(0)
get_app().window.previewFrameSignal.emit(frame_num)

# Notify properties dialog
get_app().window.propertyTableView.select_frame(frame_num)

def seekNextFrame(self):
"""Handle next-frame keypress"""
player = get_app().window.preview_thread.player
frame_num = player.Position() + 1

# Seek to next frame
get_app().window.PauseSignal.emit()
get_app().window.SpeedSignal.emit(0)
get_app().window.previewFrameSignal.emit(frame_num)

# Notify properties dialog
get_app().window.propertyTableView.select_frame(frame_num)

def playToggle(self):
"""Handle play-pause-toggle keypress"""
player = get_app().window.preview_thread.player
frame_num = player.Position()

# Toggle Play/Pause
get_app().window.actionPlay.trigger()

# Notify properties dialog
get_app().window.propertyTableView.select_frame(frame_num)

def __init__(self, window):
super().__init__()
self.setObjectName("TimelineWebView")
Expand Down Expand Up @@ -3366,3 +3403,13 @@ def __init__(self, window):
# connect signal to receive waveform data
self.clipAudioDataReady.connect(self.clipAudioDataReady_Triggered)
self.fileAudioDataReady.connect(self.fileAudioDataReady_Triggered)

# Use shortcuts to override keypress capturing for arrow keys
# This is needed mostly due to WebEngine backend eating keypress events
# This approach works well for ALL backends though
QShortcut(app.window.getShortcutByName("seekPreviousFrame"), self, activated=self.seekPreviousFrame)
QShortcut(app.window.getShortcutByName("seekNextFrame"), self, activated=self.seekNextFrame)
QShortcut(app.window.getShortcutByName("playToggle"), self, activated=self.playToggle)
QShortcut(app.window.getShortcutByName("playToggle1"), self, activated=self.playToggle)
QShortcut(app.window.getShortcutByName("playToggle2"), self, activated=self.playToggle)
QShortcut(app.window.getShortcutByName("playToggle3"), self, activated=self.playToggle)

0 comments on commit 65ce747

Please sign in to comment.