Mon, 24 Feb 2025 15:43:49 +0100
Adjusted the code to the modified issue codes.
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
1 | # -*- coding: utf-8 -*- |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
2 | |
11090
f5f5f5803935
Updated copyright for 2025.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10933
diff
changeset
|
3 | # Copyright (c) 2012 - 2025 Detlev Offenbach <detlev@die-offenbachs.de> |
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
4 | # |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
5 | |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
6 | """ |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
7 | Module implementing a main window class with styling support. |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
8 | """ |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
9 | |
9473
3f23dbf37dbe
Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9221
diff
changeset
|
10 | from PyQt6.QtWidgets import QApplication, QMainWindow, QStyleFactory |
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
11 | |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
12 | from .EricApplication import ericApp |
10248 | 13 | from .EricProxyStyle import EricProxyStyle |
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
14 | |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
15 | |
8356
68ec9c3d4de5
Renamed the modules and classes of the E5Gui package to have the prefix 'Eric' instead of 'E5'.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8318
diff
changeset
|
16 | class EricMainWindow(QMainWindow): |
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
17 | """ |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
18 | Class implementing a main window with styling support. |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
19 | """ |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
20 | |
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
21 | def __init__(self, parent=None): |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
22 | """ |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
23 | Constructor |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
24 | |
8843
586ee2c4553a
Enhanced style sheet previewer and style sheet handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8358
diff
changeset
|
25 | @param parent reference to the parent widget |
586ee2c4553a
Enhanced style sheet previewer and style sheet handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8358
diff
changeset
|
26 | @type QWidget |
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
27 | """ |
8218
7c09585bd960
Applied some more code simplifications suggested by the new Simplify checker (super(Foo, self) => super()).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8205
diff
changeset
|
28 | super().__init__(parent) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
29 | |
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
30 | self.defaultStyleName = QApplication.style().objectName() |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
31 | |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
32 | def setStyle(self, styleName, styleSheetFile, itemClickBehavior="default"): |
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
33 | """ |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
34 | Public method to set the style of the interface. |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
35 | |
8843
586ee2c4553a
Enhanced style sheet previewer and style sheet handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8358
diff
changeset
|
36 | @param styleName name of the style to set |
586ee2c4553a
Enhanced style sheet previewer and style sheet handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8358
diff
changeset
|
37 | @type str |
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
38 | @param styleSheetFile name of a style sheet file to read to overwrite |
8843
586ee2c4553a
Enhanced style sheet previewer and style sheet handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8358
diff
changeset
|
39 | defaults of the given style |
586ee2c4553a
Enhanced style sheet previewer and style sheet handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8358
diff
changeset
|
40 | @type str |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
41 | @param itemClickBehavior string describing the item activation behavior (one of |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
42 | "default", "doubleclick" or "singleclick") (defaults to "default") |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
43 | @type str (optional) |
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
44 | """ |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
45 | # step 1: set the style |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
46 | style = None |
11148
15e30f0c76a8
Adjusted the code to the modified issue codes.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
11090
diff
changeset
|
47 | if styleName != "System" and styleName in QStyleFactory.keys(): # noqa: Y-118 |
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
48 | style = QStyleFactory.create(styleName) |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
49 | if style is None: |
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
50 | style = QStyleFactory.create(self.defaultStyleName) |
10248 | 51 | |
10933
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
52 | QApplication.setStyle( |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
53 | EricProxyStyle(style=style, itemClickBehavior=itemClickBehavior) |
95a15b70f7bb
Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
10439
diff
changeset
|
54 | ) |
9221
bf71ee032bb4
Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
9209
diff
changeset
|
55 | |
2101
5bac7dee9e1a
Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff
changeset
|
56 | # step 2: set a style sheet |
8843
586ee2c4553a
Enhanced style sheet previewer and style sheet handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
8358
diff
changeset
|
57 | ericApp().setStyleSheetFile(styleSheetFile) |