Skip to content

Commit

Permalink
feat(popup): add PopupWidget class
Browse files Browse the repository at this point in the history
  • Loading branch information
amnweb committed Jan 10, 2025
1 parent fe80ca0 commit f6688c4
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions src/core/utils/utilities.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import platform
import re
from PyQt6.QtWidgets import QApplication
from PyQt6.QtWidgets import QApplication, QFrame
from PyQt6.QtCore import QEvent
from PyQt6.QtGui import QScreen

# General Utility Methods
def is_windows_10() -> bool:
version = platform.version()
return bool(re.match(r'^10\.0\.1\d{4}$', version))
Expand All @@ -17,6 +17,26 @@ def is_valid_percentage_str(s: str) -> bool:
def get_screen_by_name(screen_name: str) -> QScreen:
return next(filter(lambda scr: screen_name in scr.name(), QApplication.screens()), None)

class PopupWidget(QFrame):
"""
A custom QFrame widget that acts as a popup and hides itself when a mouse click occurs outside its geometry.
"""
def __init__(self, parent=None):
super().__init__(parent)
QApplication.instance().installEventFilter(self)

def eventFilter(self, obj, event):
if event.type() == QEvent.Type.MouseButtonPress:
global_pos = event.globalPosition().toPoint()
if not self.geometry().contains(global_pos):
self.hide()
return True
return super().eventFilter(obj, event)

def hideEvent(self, event):
QApplication.instance().removeEventFilter(self)
super().hideEvent(event)

class Singleton(type):
_instances = {}

Expand Down

0 comments on commit f6688c4

Please sign in to comment.