5 |
5 |
6 """ |
6 """ |
7 Class implementing a specialized application class. |
7 Class implementing a specialized application class. |
8 """ |
8 """ |
9 |
9 |
|
10 import contextlib |
10 import os |
11 import os |
11 |
12 |
12 from PyQt6.QtCore import QCoreApplication, Qt |
13 from PyQt6.QtCore import QCoreApplication, Qt |
13 from PyQt6.QtGui import QColor, QPalette |
14 from PyQt6.QtGui import QColor, QPalette |
14 from PyQt6.QtWidgets import QApplication |
15 from PyQt6.QtWidgets import QApplication |
68 primaryScreenSize = self.primaryScreen().size() |
69 primaryScreenSize = self.primaryScreen().size() |
69 self.__smallScreen = ( |
70 self.__smallScreen = ( |
70 primaryScreenSize.width() < 1920 or primaryScreenSize.height() < 1080 |
71 primaryScreenSize.width() < 1920 or primaryScreenSize.height() < 1080 |
71 ) |
72 ) |
72 |
73 |
|
74 self.__hasNonStandardPalette = False |
|
75 self.__hasUserStyleSheet = False |
|
76 |
73 def usesSmallScreen(self): |
77 def usesSmallScreen(self): |
74 """ |
78 """ |
75 Public method to determine, if the application is used on a small |
79 Public method to determine, if the application is used on a small |
76 screen. |
80 screen. |
77 |
81 |
236 # pre-process the style sheet to replace the placeholder for the |
240 # pre-process the style sheet to replace the placeholder for the |
237 # path to the icons |
241 # path to the icons |
238 styleIconsPath = self.getStyleIconsPath(universal=True) |
242 styleIconsPath = self.getStyleIconsPath(universal=True) |
239 styleSheet = styleSheet.replace("${path}", styleIconsPath) |
243 styleSheet = styleSheet.replace("${path}", styleIconsPath) |
240 |
244 |
|
245 self.__hasUserStyleSheet = True |
|
246 |
241 if "QPalette {" in styleSheet: |
247 if "QPalette {" in styleSheet: |
242 self.__setPaletteFromStyleSheet(styleSheet) |
248 self.__setPaletteFromStyleSheet(styleSheet) |
243 |
249 |
244 ericApp().setStyleSheet(styleSheet) |
250 ericApp().setStyleSheet(styleSheet) |
245 |
251 |
261 if role in self.PaletteRoleMapping and value.startswith("#"): |
267 if role in self.PaletteRoleMapping and value.startswith("#"): |
262 palette.setColor(self.PaletteRoleMapping[role], QColor(value)) |
268 palette.setColor(self.PaletteRoleMapping[role], QColor(value)) |
263 |
269 |
264 self.setPalette(palette) |
270 self.setPalette(palette) |
265 |
271 |
|
272 self.__hasNonStandardPalette = True |
|
273 |
266 def usesDarkPalette(self): |
274 def usesDarkPalette(self): |
267 """ |
275 """ |
268 Public method to check, if the application uses a palette with a dark |
276 Public method to check, if the application uses a palette with a dark |
269 background. |
277 background. |
270 |
278 |
271 @return flag indicating the use of a palette with a dark background |
279 @return flag indicating the use of a palette with a dark background |
272 @rtype bool |
280 @rtype bool |
273 """ |
281 """ |
|
282 if not self.__hasNonStandardPalette: |
|
283 with contextlib.suppress(AttributeError): |
|
284 return self.styleHints().colorScheme() == Qt.ColorScheme.Dark |
|
285 |
|
286 # backward compatibility for Qt < 6.5.0 or changed by user |
274 palette = self.palette() |
287 palette = self.palette() |
275 lightness = palette.color(QPalette.ColorRole.Window).lightness() |
288 return ( |
276 return lightness <= 128 |
289 palette.color(QPalette.ColorRole.WindowText).lightness() > |
|
290 palette.color(QPalette.ColorRole.Window).lightness() |
|
291 ) |
277 |
292 |
278 |
293 |
279 ericApp = QCoreApplication.instance |
294 ericApp = QCoreApplication.instance |