1- import keyboard
21import sys
32import os
43from multiprocessing import freeze_support
54from PyQt6 .QtWidgets import QApplication , QMessageBox
6- from PyQt6 .QtCore import QTimer , Qt , QSharedMemory
7- from PyQt6 .QtGui import QKeySequence , QShortcut
5+ from PyQt6 .QtCore import QTimer , Qt , QSharedMemory , QEvent
86from PyQt6 .QtNetwork import QLocalServer , QLocalSocket
97from ui .quran_interface import QuranInterface
108from core_functions .athkar .athkar_scheduler import AthkarScheduler
@@ -22,11 +20,8 @@ def __init__(self, *args, **kwargs) -> None:
2220 self .local_server = QLocalServer (self )
2321 self .shared_memory = QSharedMemory ("Albayan" )
2422 self .is_running = self .shared_memory .attach ()
25-
2623 self .volume_controller = VolumeController ()
27- self .timer = QTimer ()
28- self .timer .timeout .connect (self .set_shortcut )
29- self .timer .start (100 )
24+ self .installEventFilter (self ) # تثبيت فلتر الأحداث على مستوى التطبيق
3025
3126 if not self .is_running :
3227 if not self .shared_memory .create (1 ):
@@ -37,6 +32,24 @@ def __init__(self, *args, **kwargs) -> None:
3732 self .notify_existing_instance ()
3833 sys .exit (0 )
3934
35+ def eventFilter (self , obj , event ):
36+
37+ if event .type () == QEvent .Type .KeyPress :
38+ key = event .key ()
39+ if key == Qt .Key .Key_F5 :
40+ self .volume_controller .switch_category ("next" )
41+ return True
42+ elif key == Qt .Key .Key_F6 :
43+ self .volume_controller .switch_category ("previous" )
44+ return True
45+ elif key == Qt .Key .Key_F7 :
46+ self .volume_controller .adjust_volume (- 1 )
47+ return True
48+ elif key == Qt .Key .Key_F8 :
49+ self .volume_controller .adjust_volume (1 )
50+ return True
51+ return super ().eventFilter (obj , event )
52+
4053 def setup_local_server (self ) -> None :
4154 if not self .local_server .listen (self .server_name ):
4255 Logger .error (f"Failed to start local server: { self .local_server .errorString ()} " )
@@ -70,17 +83,6 @@ def read_message(self, socket) -> None:
7083 def set_main_window (self , main_window ) -> None :
7184 self .main_window = main_window
7285
73- def set_shortcut (self ) -> None :
74- if self .activeWindow ():
75- if keyboard .is_pressed ('F5' ):
76- self .volume_controller .switch_category ("next" )
77- elif keyboard .is_pressed ('F6' ):
78- self .volume_controller .switch_category ("previous" )
79- elif keyboard .is_pressed ('F7' ):
80- self .volume_controller .adjust_volume (10 )
81- elif keyboard .is_pressed ('F8' ):
82- self .volume_controller .adjust_volume (- 10 )
83-
8486def call_after_starting (parent : QuranInterface ) -> None :
8587
8688 basmala = StartupSoundEffectPlayer ("Audio/basmala" )
0 commit comments