1
1
import platform
2
2
import re
3
- from PyQt6 .QtWidgets import QApplication ,QFrame ,QGraphicsOpacityEffect
4
- from PyQt6 .QtCore import QEvent , QTimer
3
+ from PyQt6 .QtWidgets import QApplication ,QFrame ,QMenu
4
+ from PyQt6 .QtCore import QEvent
5
5
from PyQt6 .QtGui import QScreen
6
6
from core .utils .win32 .blurWindow import Blur
7
7
@@ -19,8 +19,19 @@ def get_screen_by_name(screen_name: str) -> QScreen:
19
19
return next (filter (lambda scr :screen_name in scr .name (),QApplication .screens ()),None )
20
20
21
21
class PopupWidget (QFrame ):
22
- """
23
- A custom QFrame widget that acts as a popup and hides itself when a mouse click occurs outside its geometry
22
+ """A custom QFrame widget that acts as a popup and hides itself when a mouse click occurs outside its geometry.
23
+ This widget provides functionality for creating popup windows with optional blur effects and rounded corners.
24
+ When a mouse click is detected outside the popup's geometry, it automatically hides and deletes itself.
25
+ Args:
26
+ parent (QWidget, optional): The parent widget. Defaults to None.
27
+ blur (bool, optional): Whether to apply blur effect to the popup. Defaults to False.
28
+ round_corners (bool, optional): Whether to apply rounded corners to the popup. Defaults to False.
29
+ round_corners_type (str, optional): Type of rounded corners ('normal', 'small'). Defaults to "normal".
30
+ border_color (str, optional): Color of the popup border ('System','hex', 'None'). Defaults to "None".
31
+ Methods:
32
+ showEvent(event): Handles the show event, applying blur effects if enabled.
33
+ eventFilter(obj, event): Filters mouse click events to hide popup when clicked outside.
34
+ hideEvent(event): Handles the hide event, cleaning up event filters.
24
35
"""
25
36
def __init__ (self ,parent = None ,blur = False ,round_corners = False ,round_corners_type = "normal" ,border_color = "None" ):
26
37
super ().__init__ (parent )
@@ -56,6 +67,38 @@ def hideEvent(self, event):
56
67
QApplication .instance ().removeEventFilter (self )
57
68
super ().hideEvent (event )
58
69
70
+ class ContextMenu (QMenu ):
71
+ """A custom context menu class that extends QMenu with additional functionality.
72
+ This class implements a context menu that automatically closes when clicking outside
73
+ its boundaries and provides proper window activation handling.
74
+ Methods:
75
+ showEvent(event): Handles the menu show event by activating the window
76
+ hideEvent(event): Handles the menu hide event by removing the event filter
77
+ eventFilter(obj, event): Filters events to detect clicks outside the menu
78
+ Inherits:
79
+ QMenu: Base menu class from Qt
80
+ """
81
+ def __init__ (self ,* args ,** kwargs ):
82
+ super ().__init__ (* args ,** kwargs )
83
+ QApplication .instance ().installEventFilter (self )
84
+
85
+ def showEvent (self ,event ):
86
+ self .activateWindow ()
87
+ super ().showEvent (event )
88
+
89
+ def hideEvent (self ,event ):
90
+ QApplication .instance ().removeEventFilter (self )
91
+ super ().hideEvent (event )
92
+
93
+ def eventFilter (self ,obj ,event ):
94
+ if event .type ()== QEvent .Type .MouseButtonPress :
95
+ global_pos = event .globalPosition ().toPoint ()
96
+ if not self .geometry ().contains (global_pos ):
97
+ self .hide ()
98
+ self .deleteLater ()
99
+ return True
100
+ return super ().eventFilter (obj ,event )
101
+
59
102
60
103
class Singleton (type ):
61
104
_instances = {}