From 279395a7d770104e83c6bc79c02137e7d3c2235e Mon Sep 17 00:00:00 2001 From: Neil Munday Date: Sun, 1 Oct 2023 00:04:14 +0100 Subject: [PATCH] feat: added configMode toggle to ControlPadManager class --- src/pes/controlpad.py | 16 +++++++++++++ src/pes/qml/main.qml | 54 +++++++++++++++++++++++-------------------- 2 files changed, 45 insertions(+), 25 deletions(-) diff --git a/src/pes/controlpad.py b/src/pes/controlpad.py index 0253e31..a5f2ee4 100644 --- a/src/pes/controlpad.py +++ b/src/pes/controlpad.py @@ -233,6 +233,7 @@ class ControlPadManager(QObject): totalChangedEvent = pyqtSignal(int, arguments=['total']) __listener = ControlPadListener() # shared instance __controlPads = {} # shared dictionary of connected control pads + __configMode = False def __init__(self, parent=None): super().__init__(parent) @@ -296,6 +297,21 @@ def __fireTotalChangedEvent(self, total: int): logging.debug("ControlPadManager.__fireTotalChangedEvent: %d", total) self.totalChangedEvent.emit(total) + @pyqtProperty(bool) + def configMode(self) -> bool: + """ + Return's True if config mode has been enabled, False otherwise. + """ + return ControlPadManager.__configMode + + @configMode.setter + def configMode(self, mode: bool): + """ + Set the config mode to True or False. + """ + ControlPadManager.__configMode = mode + logging.debug("ControlPadManager.configMode = %s", mode) + @pyqtSlot(result=list) def getControlPads(self) -> list: """ diff --git a/src/pes/qml/main.qml b/src/pes/qml/main.qml index b7e56af..18c8dd9 100644 --- a/src/pes/qml/main.qml +++ b/src/pes/qml/main.qml @@ -57,35 +57,39 @@ ApplicationWindow { onAxisEvent: { const positive = value > 0 - switch(axis) { - case ControlPad.LeftX: { - if (positive) { - keyboardEmitter.keyPress(Qt.Key_Right) - } - else { - keyboardEmitter.keyPress(Qt.Key_Left) - } - }; break - case ControlPad.LeftY: { - if (positive) { - keyboardEmitter.keyPress(Qt.Key_Down) - } - else { - keyboardEmitter.keyPress(Qt.Key_Up) - } - }; break + if (!controlPadManager.configMode) { + switch(axis) { + case ControlPad.LeftX: { + if (positive) { + keyboardEmitter.keyPress(Qt.Key_Right) + } + else { + keyboardEmitter.keyPress(Qt.Key_Left) + } + }; break + case ControlPad.LeftY: { + if (positive) { + keyboardEmitter.keyPress(Qt.Key_Down) + } + else { + keyboardEmitter.keyPress(Qt.Key_Up) + } + }; break + } } } onButtonEvent: { - switch(button) { - case ControlPad.AButton: keyboardEmitter.keyPress(Qt.Key_Backspace); break; - case ControlPad.BButton: keyboardEmitter.keyPress(Qt.Key_Return); break; - case ControlPad.DownButton: keyboardEmitter.keyPress(Qt.Key_Down); break; - case ControlPad.GuideButton: PES.goHome(); break; - case ControlPad.LeftButton: keyboardEmitter.keyPress(Qt.Key_Left); break; - case ControlPad.RightButton: keyboardEmitter.keyPress(Qt.Key_Right); break; - case ControlPad.UpButton: keyboardEmitter.keyPress(Qt.Key_Up); break; + if (!controlPadManager.configMode) { + switch(button) { + case ControlPad.AButton: keyboardEmitter.keyPress(Qt.Key_Backspace); break; + case ControlPad.BButton: keyboardEmitter.keyPress(Qt.Key_Return); break; + case ControlPad.DownButton: keyboardEmitter.keyPress(Qt.Key_Down); break; + case ControlPad.GuideButton: PES.goHome(); break; + case ControlPad.LeftButton: keyboardEmitter.keyPress(Qt.Key_Left); break; + case ControlPad.RightButton: keyboardEmitter.keyPress(Qt.Key_Right); break; + case ControlPad.UpButton: keyboardEmitter.keyPress(Qt.Key_Up); break; + } } } }