|
32 | 32 | QLibraryInfo, |
33 | 33 | QT_VERSION_STR, |
34 | 34 | QUrl) |
35 | | -from PyQt6.QtWidgets import (QWidget, |
| 35 | +from PyQt6.QtWidgets import (QAbstractItemView, |
| 36 | + QApplication, |
| 37 | + QDialog, |
36 | 38 | QFileDialog, |
37 | | - QAbstractItemView, |
| 39 | + QLabel, |
38 | 40 | QListView, |
39 | | - QTreeView, |
40 | | - QDialog, |
41 | | - QApplication, |
| 41 | + QSystemTrayIcon, |
| 42 | + QStyle, |
42 | 43 | QStyleFactory, |
43 | | - QSystemTrayIcon) |
| 44 | + QTreeView, |
| 45 | + QWidget) |
44 | 46 |
|
45 | 47 | from packaging.version import Version |
46 | 48 |
|
@@ -185,6 +187,62 @@ def update_combo_profiles(config, combo_profiles, current_profile_id): |
185 | 187 | if profile_id == current_profile_id: |
186 | 188 | combo_profiles.set_current_profile_id(profile_id) |
187 | 189 |
|
| 190 | + |
| 191 | +def create_icon_label( |
| 192 | + icon_type: QStyle.StandardPixmap, |
| 193 | + icon_size: QStyle.PixelMetric = QStyle.PixelMetric.PM_LargeIconSize, |
| 194 | + fixed_size_widget: bool = False) -> QLabel: |
| 195 | + """Return a ``QLabel`` instance containing an icon. |
| 196 | +
|
| 197 | + Args: |
| 198 | + icon_type: The icon, eg. info or warning. |
| 199 | + icon_size: Size reference. |
| 200 | + fixed_size_widget: Fix label size to its icon (default: False) |
| 201 | +
|
| 202 | + Returns: |
| 203 | + The QLabel |
| 204 | + """ |
| 205 | + style = QApplication.style() |
| 206 | + ico = style.standardIcon(icon_type) |
| 207 | + sz = style.pixelMetric(icon_size) |
| 208 | + |
| 209 | + pixmap = ico.pixmap(sz) |
| 210 | + |
| 211 | + label = QLabel() |
| 212 | + label.setPixmap(pixmap) |
| 213 | + |
| 214 | + if fixed_size_widget: |
| 215 | + label.setFixedSize(pixmap.size()) |
| 216 | + |
| 217 | + return label |
| 218 | + |
| 219 | + |
| 220 | +def create_icon_label_info( |
| 221 | + icon_size: QStyle.PixelMetric = QStyle.PixelMetric.PM_LargeIconSize, |
| 222 | + fixed_size_widget: bool = False) -> QLabel: |
| 223 | + """Return a QLabel with an info icon. |
| 224 | +
|
| 225 | + See `create_icon_label` for details. |
| 226 | + """ |
| 227 | + return create_icon_label( |
| 228 | + icon_type=QStyle.StandardPixmap.SP_MessageBoxInformation, |
| 229 | + icon_size=icon_size, |
| 230 | + fixed_size_widget=fixed_size_widget) |
| 231 | + |
| 232 | + |
| 233 | +def create_icon_label_warning( |
| 234 | + icon_size: QStyle.PixelMetric = QStyle.PixelMetric.PM_LargeIconSize, |
| 235 | + fixed_size_widget: bool = False) -> QLabel: |
| 236 | + """Return a QLabel with a warning icon. |
| 237 | +
|
| 238 | + See `create_icon_label` for details. |
| 239 | + """ |
| 240 | + return create_icon_label( |
| 241 | + icon_type=QStyle.StandardPixmap.SP_MessageBoxWarning, |
| 242 | + icon_size=icon_size, |
| 243 | + fixed_size_widget=fixed_size_widget) |
| 244 | + |
| 245 | + |
188 | 246 | # |---------------------| |
189 | 247 | # | Misc / Uncatgorized | |
190 | 248 | # |---------------------| |
|
0 commit comments