Added clicks, simplified the mouse wheel event handling.

master
Jaka Perovšek 2022-08-11 01:28:27 +02:00
parent 68043adf00
commit a1bd41de9d
4 changed files with 24 additions and 8 deletions

View File

@ -3,8 +3,9 @@ import winput
from PySide2.QtCore import Qt
from PySide2.QtWidgets import QApplication, QMainWindow, QRadioButton, QGroupBox
from PySide2.QtWidgets import QVBoxLayout, QHBoxLayout, QWidget, QLabel, QSpinBox
from PySide2.QtWidgets import QAction
from PySide2.QtWidgets import QAction, QCheckBox
from PySide2.QtGui import QIcon
from PySide2.QtMultimedia import QSound
WM_MOUSEWHEEL = 0x020A # mouse wheel moved
@ -13,12 +14,18 @@ class ArtyWidget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.audio_effect_10 = QSound("sound1.wav")
self.audio_effect_10b = QSound("sound1b.wav")
self.audio_effect_50 = QSound("sound2.wav")
self.radio_type1 = QRadioButton("Type 1: MILRAD 622 - 978")
self.radio_type2 = QRadioButton("Type 2: MILRAD 800 - 1120")
self.sound_cbox = QCheckBox("Sound", checked=True)
gbox_layout = QVBoxLayout()
gbox_layout.addWidget(self.radio_type1)
gbox_layout.addWidget(self.radio_type2)
gbox_layout.addWidget(self.sound_cbox)
self.gbox = QGroupBox("Settings (Ctrl+H to hide the window bar)")
self.gbox.setLayout(gbox_layout)
@ -61,6 +68,7 @@ class ArtyWidget(QWidget):
self.update_elevation(self.target_range.value())
def update_elevation(self, value):
x0, x1 = 100, 1600
if self.radio_type1.isChecked():
y0, y1 = 978, 622
@ -75,10 +83,21 @@ class ArtyWidget(QWidget):
def increment_range(self, mouse_event):
if mouse_event.action == WM_MOUSEWHEEL:
if not self.isActiveWindow():
current_range = self.target_range.value()
increment = mouse_event.additional_data
self.target_range.setValue(current_range + increment)
current_range = self.target_range.value()
increment = mouse_event.additional_data
set_range = current_range + increment
self.target_range.setValue(set_range)
self.play_click(set_range, increment)
def play_click(self, set_range, increment):
if self.sound_cbox.isChecked():
if set_range % 50 == 0:
self.audio_effect_50.play()
elif set_range % 10 == 0:
if increment > 0:
self.audio_effect_10.play()
else:
self.audio_effect_10b.play()
class ArtyGUI(QMainWindow):
@ -110,9 +129,6 @@ class ArtyGUI(QMainWindow):
self.show()
self.arty_widget.target_range.setFocus()
def wheelEvent(self, event):
self.arty_widget.target_range.event(event)
if __name__ == "__main__":
app = QApplication(sys.argv)

BIN
sound1.wav 100644

Binary file not shown.

BIN
sound1b.wav 100644

Binary file not shown.

BIN
sound2.wav 100644

Binary file not shown.