python-mpv icon indicating copy to clipboard operation
python-mpv copied to clipboard

Keybinding don't work in Pyside6 (PyQt).

Open Senkai350 opened this issue 3 years ago • 1 comments
trafficstars

When i try to use keybindings with Pyside they just don't work, but without pyside all works perfect, why? My code:

import os
os.add_dll_directory(os.getcwd())
import mpv
from PySide6.QtWidgets import *
from PySide6.QtCore import *
mpvfolderpath = f"mpv.net/portable_config/"
import sys
class Test(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)
        self.container = QWidget(self)
        self.setCentralWidget(self.container)
        self.container.setAttribute(Qt.WA_DontCreateNativeAncestors)
        self.container.setAttribute(Qt.WA_NativeWindow)
        player = mpv.MPV(wid=str(int(self.container.winId())),
                         vo="gpu",  # You may not need this
                         log_handler=print,
                         loglevel='debug',
                         input_default_bindings=True,
                         input_vo_keyboard=True)

        @player.on_key_press('f')
        def my_f_binding():
            print("f работает!")
        player.play('res/test.mp4')

app = QApplication(sys.argv)

# This is necessary since PyQT stomps over the locale settings needed by libmpv.
# This needs to happen after importing PyQT before creating the first mpv.MPV instance.
import locale
locale.setlocale(locale.LC_NUMERIC, 'C')
win = Test()
win.show()
sys.exit(app.exec_())

Senkai350 avatar Feb 23 '22 11:02 Senkai350

I've made a test in Linux with PyQt6, this works. In PyQt6 you must use app.exec() not app.exec()_

import os
#os.add_dll_directory(os.getcwd())
import mpv
from PyQt6.QtWidgets import *
from PyQt6.QtCore import *
mpvfolderpath = f"mpv.net/portable_config/"
import sys

class Test(QMainWindow):
    def __init__(self, parent=None):
        super().__init__(parent)
        
        self.setGeometry(100, 100, 400, 260)
        self.container = QWidget(self)
        self.setCentralWidget(self.container)

        self.player = mpv.MPV(wid=str(int(self.container.winId())),
                         log_handler=print,
                         loglevel='debug',
                         input_default_bindings=True,
                         input_vo_keyboard=True)


        @self.player.on_key_press('f')
        def my_f_binding():
            print("f работает!")
        self.player.play('test.mp4')
    

app = QApplication(sys.argv)

import locale
locale.setlocale(locale.LC_NUMERIC, 'C')
win = Test()
win.show()
sys.exit(app.exec())

Axel-Erfurt avatar Apr 02 '22 20:04 Axel-Erfurt