src/eric7/EricWidgets/EricMainWindow.py

Sat, 23 Dec 2023 15:48:12 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 23 Dec 2023 15:48:12 +0100
branch
eric7
changeset 10439
21c28b0f9e41
parent 10248
981456110843
child 10933
95a15b70f7bb
permissions
-rw-r--r--

Updated copyright for 2024.

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
10439
21c28b0f9e41 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10248
diff changeset
3 # Copyright (c) 2012 - 2024 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
981456110843 General
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10180
diff changeset
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
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
32 def setStyle(self, styleName, styleSheetFile):
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
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
41 """
5bac7dee9e1a Introduced the E5MainWindow class allowing to set a style for all the main windows.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 # 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
43 style = None
10180
3a595df36c9a Simplified some code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
44 if styleName != "System" and styleName in QStyleFactory.keys(): # noqa: Y118
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
45 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
46 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
47 style = QStyleFactory.create(self.defaultStyleName)
10248
981456110843 General
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10180
diff changeset
48
981456110843 General
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10180
diff changeset
49 if style is None:
981456110843 General
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10180
diff changeset
50 QApplication.setStyle(EricProxyStyle())
981456110843 General
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10180
diff changeset
51 else:
981456110843 General
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10180
diff changeset
52 QApplication.setStyle(EricProxyStyle(style))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
53
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
54 # 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
55 ericApp().setStyleSheetFile(styleSheetFile)

eric ide

mercurial