Skip to content

Commit 6221537

Browse files
committed
feat(widget): add show_label_name option for group labels in DiskWidget
This update introduces a new configuration option 'show_label_name' for group labels in the DiskWidget. When enabled, it retrieves and displays the volume label for each drive, enhancing the widget's functionality and user experience.
1 parent db39043 commit 6221537

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

src/core/validation/widgets/yasb/disk.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
'group_label': {
88
'enabled': False,
99
'volume_labels': ['C'],
10+
'show_label_name': True,
1011
'blur': True,
1112
'round_corners': True,
1213
'round_corners_type': 'normal',
@@ -69,6 +70,10 @@
6970
},
7071
'default': DEFAULTS['group_label']['volume_labels']
7172
},
73+
'show_label_name': {
74+
'type': 'boolean',
75+
'default': DEFAULTS['group_label']['show_label_name']
76+
},
7277
'blur': {
7378
'type': 'boolean',
7479
'default': DEFAULTS['group_label']['blur']

src/core/widgets/yasb/disk.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import os
22
import psutil
33
import re
4+
import win32api
45
from core.widgets.base import BaseWidget
56
from core.validation.widgets.yasb.disk import VALIDATION_SCHEMA
67
from PyQt6.QtWidgets import QLabel, QHBoxLayout, QWidget, QProgressBar, QVBoxLayout
@@ -138,7 +139,15 @@ def _update_label(self):
138139
active_widgets[widget_index].setText(formatted_text)
139140
widget_index += 1
140141

141-
142+
def _get_volume_label(self, drive_letter):
143+
if not self._group_label['show_label_name']:
144+
return None
145+
try:
146+
volume_label = win32api.GetVolumeInformation(f"{drive_letter}:\\")[0]
147+
return volume_label
148+
except Exception:
149+
return None
150+
142151
def show_group_label(self):
143152
self.dialog = PopupWidget(self, self._group_label['blur'], self._group_label['round_corners'], self._group_label['round_corners_type'], self._group_label['border_color'])
144153
self.dialog.setProperty("class", "disk-group")
@@ -154,14 +163,17 @@ def show_group_label(self):
154163
row_widget = QWidget()
155164
row_widget.setProperty("class", "disk-group-row")
156165

166+
volume_label = self._get_volume_label(label)
167+
display_label = f"{volume_label} ({label}):" if volume_label else f"{label}:"
168+
157169
clicable_row = ClickableDiskWidget(label)
158170
clicable_row.clicked.connect(lambda lbl=label: self.open_explorer(lbl))
159171
clicable_row.setCursor(Qt.CursorShape.PointingHandCursor)
160172

161173
v_layout = QVBoxLayout(clicable_row)
162174
h_layout = QHBoxLayout()
163175

164-
label_widget = QLabel(f"{label}:")
176+
label_widget = QLabel(display_label)
165177
label_widget.setProperty("class", "disk-group-label")
166178
h_layout.addWidget(label_widget)
167179

0 commit comments

Comments
 (0)