Skip to content

Commit

Permalink
feat(disk): enhance DiskWidget with group label toggling and configur…
Browse files Browse the repository at this point in the history
…ation options
  • Loading branch information
amnweb committed Jan 10, 2025
1 parent 13eccf4 commit dd960cb
Showing 1 changed file with 14 additions and 26 deletions.
40 changes: 14 additions & 26 deletions src/core/widgets/yasb/disk.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,11 @@
import re
from core.widgets.base import BaseWidget
from core.validation.widgets.yasb.disk import VALIDATION_SCHEMA
from PyQt6.QtWidgets import QLabel, QHBoxLayout, QWidget, QProgressBar, QVBoxLayout, QApplication
from PyQt6.QtCore import Qt, QPoint, pyqtSignal, QEvent
from PyQt6.QtWidgets import QLabel, QHBoxLayout, QWidget, QProgressBar, QVBoxLayout
from PyQt6.QtCore import Qt, QPoint, pyqtSignal
from core.utils.win32.blurWindow import Blur
from core.utils.utilities import is_windows_10

class PopupWidget(QWidget):
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)

from core.utils.utilities import PopupWidget

class ClickableDiskWidget(QWidget):
clicked = pyqtSignal()
Expand Down Expand Up @@ -75,6 +58,7 @@ def __init__(
self._create_dynamically_label(self._label_content, self._label_alt_content)

self.register_callback("toggle_label", self._toggle_label)
self.register_callback("toggle_group", self._toggle_group)
self.register_callback("update_label", self._update_label)
self.callback_left = callbacks['on_left']
self.callback_right = callbacks['on_right']
Expand All @@ -85,16 +69,17 @@ def __init__(


def _toggle_label(self):
if self._group_label['enabled']:
self.show_group_label()
return
self._show_alt_label = not self._show_alt_label
for widget in self._widgets:
widget.setVisible(not self._show_alt_label)
for widget in self._widgets_alt:
widget.setVisible(self._show_alt_label)
self._update_label()


def _toggle_group(self):
if self._group_label['enabled']:
self.show_group_label()

def _create_dynamically_label(self, content: str, content_alt: str):
def process_content(content, is_alt=False):
label_parts = re.split('(<span.*?>.*?</span>)', content)
Expand Down Expand Up @@ -157,6 +142,8 @@ def show_group_label(self):
self.dialog.setProperty("class", "disk-group")
self.dialog.setWindowFlag(Qt.WindowType.FramelessWindowHint)
self.dialog.setWindowFlag(Qt.WindowType.Popup)
self.dialog.setWindowFlag(Qt.WindowType.WindowStaysOnTopHint)

layout = QVBoxLayout()
for label in self._group_label['volume_labels']:
disk_space = self._get_space(label)
Expand Down Expand Up @@ -218,8 +205,9 @@ def show_group_label(self):
self.dialog.winId(),
Acrylic=True if is_windows_10() else False,
DarkMode=False,
RoundCorners=True,
BorderColor="System"
RoundCorners=self._group_label['round_corners'],
RoundCornersType=self._group_label['round_corners_type'],
BorderColor=self._group_label['border_color']
)

# Position the dialog
Expand Down

0 comments on commit dd960cb

Please sign in to comment.