src/eric7/EricWidgets/EricApplication.py

Sun, 03 Nov 2024 17:50:34 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 03 Nov 2024 17:50:34 +0100
branch
eric7
changeset 11034
7b8a21fd2d58
parent 10933
95a15b70f7bb
child 11035
e1e1d6e317c7
permissions
-rw-r--r--

Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.

55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
10439
21c28b0f9e41 Updated copyright for 2024.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10417
diff changeset
3 # Copyright (c) 2009 - 2024 Detlev Offenbach <detlev@die-offenbachs.de>
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Class implementing a specialized application class.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
9976
ceae971872de EricApplication: adapted the dark palette logic to Qt 6.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
10 import contextlib
8843
586ee2c4553a Enhanced style sheet previewer and style sheet handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8840
diff changeset
11 import os
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: 10909
diff changeset
12 import pathlib
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9995
diff changeset
13 import sys
8843
586ee2c4553a Enhanced style sheet previewer and style sheet handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8840
diff changeset
14
9473
3f23dbf37dbe Resorted the import statements using isort.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9448
diff changeset
15 from PyQt6.QtCore import QCoreApplication, Qt
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
16 from PyQt6.QtGui import QColor, QPalette
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
17 from PyQt6.QtWidgets import QApplication
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18
9400
5494faeaead2 Fixed a little nuisance setting the "AA_ShareOpenGLContexts" attribute.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
19 if not QCoreApplication.testAttribute(Qt.ApplicationAttribute.AA_ShareOpenGLContexts):
5494faeaead2 Fixed a little nuisance setting the "AA_ShareOpenGLContexts" attribute.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9221
diff changeset
20 QCoreApplication.setAttribute(Qt.ApplicationAttribute.AA_ShareOpenGLContexts, True)
7589
c1f81fd8c33a E5Application: fixed a warning related to initialisation of Qt.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7502
diff changeset
21
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
22 from . import EricMessageBox
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
23
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
24
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
25 class EricApplication(QApplication):
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 Eric application class with an object registry.
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 """
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
29
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
30 PaletteRoleMapping = {
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
31 "alternate-base": QPalette.ColorRole.AlternateBase,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
32 "base": QPalette.ColorRole.Base,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
33 "text": QPalette.ColorRole.Text,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
34 "bright-text": QPalette.ColorRole.BrightText,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
35 "placeholder-text": QPalette.ColorRole.PlaceholderText,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
36 "window": QPalette.ColorRole.Window,
10909
4a847e8260c1 Corrected an issue causing the window text color not being configured for a non-standard palette read from a style sheet file.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10689
diff changeset
37 "window-text": QPalette.ColorRole.WindowText,
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
38 "tooltip-base": QPalette.ColorRole.ToolTipBase,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
39 "tooltip-text": QPalette.ColorRole.ToolTipText,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
40 "button": QPalette.ColorRole.Button,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
41 "button-text": QPalette.ColorRole.ButtonText,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
42 "highlight": QPalette.ColorRole.Highlight,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
43 "highlighted-text": QPalette.ColorRole.HighlightedText,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
44 "link": QPalette.ColorRole.Link,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
45 "link-visited": QPalette.ColorRole.LinkVisited,
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
46 }
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
47
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9995
diff changeset
48 def __init__(self, args):
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 Constructor
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
51
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9995
diff changeset
52 @param args namespace object containing the parsed command line parameters
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9995
diff changeset
53 @type argparse.Namespace
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 """
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9995
diff changeset
55 super().__init__(sys.argv)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
56
7984
e48dd1b7b2fa E5Application: did some code cleanup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
57 QCoreApplication.setAttribute(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
58 Qt.ApplicationAttribute.AA_DontCreateNativeWidgetSiblings, True
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
59 )
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
60
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 self.__objectRegistry = {}
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 self.__pluginObjectRegistry = {}
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
63
10303
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9995
diff changeset
64 try:
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9995
diff changeset
65 self.__smallScreen = args.small_screen
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9995
diff changeset
66 except AttributeError:
ee1aadab1215 Changed code to use the 'argparse' module to parse the command line parameters instead of using own code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9995
diff changeset
67 self.__smallScreen = False
8729
226da2e26a84 Changed the 'small-screen' related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
68 if not self.__smallScreen:
226da2e26a84 Changed the 'small-screen' related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
69 primaryScreenSize = self.primaryScreen().size()
226da2e26a84 Changed the 'small-screen' related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
70 self.__smallScreen = (
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
71 primaryScreenSize.width() < 1920 or primaryScreenSize.height() < 1080
8729
226da2e26a84 Changed the 'small-screen' related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
72 )
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
73
9976
ceae971872de EricApplication: adapted the dark palette logic to Qt 6.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
74 self.__hasNonStandardPalette = False
ceae971872de EricApplication: adapted the dark palette logic to Qt 6.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
75
11034
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
76 self.__mainWindow = None
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
77
8729
226da2e26a84 Changed the 'small-screen' related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
78 def usesSmallScreen(self):
226da2e26a84 Changed the 'small-screen' related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
79 """
226da2e26a84 Changed the 'small-screen' related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
80 Public method to determine, if the application is used on a small
226da2e26a84 Changed the 'small-screen' related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
81 screen.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
82
8729
226da2e26a84 Changed the 'small-screen' related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
83 @return flag indicating the use of a small screen
226da2e26a84 Changed the 'small-screen' related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
84 @rtype bool
226da2e26a84 Changed the 'small-screen' related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
85 """
226da2e26a84 Changed the 'small-screen' related code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8358
diff changeset
86 return self.__smallScreen
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
87
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
88 def registerObject(self, name, objectRef):
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 Public method to register an object in the object registry.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
91
7493
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
92 @param name name of the object
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
93 @type str
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
94 @param objectRef reference to the object
10417
c6011e501282 Modernized some code and converted Debug Client and Debugger source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10303
diff changeset
95 @type Any
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 @exception KeyError raised when the given name is already in use
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 if name in self.__objectRegistry:
410
e5d1addeb90c Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
99 raise KeyError('Object "{0}" already registered.'.format(name))
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 else:
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
101 self.__objectRegistry[name] = objectRef
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
102
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 def getObject(self, name):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 Public method to get a reference to a registered object.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
106
7493
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
107 @param name name of the object
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
108 @type str
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 @return reference to the registered object
10417
c6011e501282 Modernized some code and converted Debug Client and Debugger source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10303
diff changeset
110 @rtype Any
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 @exception KeyError raised when the given name is not known
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 """
8205
4a0f1f896341 Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
113 if name not in self.__objectRegistry:
410
e5d1addeb90c Did some more string format conversions.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 55
diff changeset
114 raise KeyError('Object "{0}" is not registered.'.format(name))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
115
8205
4a0f1f896341 Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
116 return self.__objectRegistry[name]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
117
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
118 def registerPluginObject(self, name, objectRef, pluginType=None):
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 Public method to register a plugin object in the object registry.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
121
7493
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
122 @param name name of the plugin object
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
123 @type str
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
124 @param objectRef reference to the plugin object
10417
c6011e501282 Modernized some code and converted Debug Client and Debugger source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10303
diff changeset
125 @type Any
7493
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
126 @param pluginType type of the plugin object
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
127 @type str
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 @exception KeyError raised when the given name is already in use
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 if name in self.__pluginObjectRegistry:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
131 raise KeyError('Pluginobject "{0}" already registered.'.format(name))
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 else:
5587
ea526b78ee6c Started to fix code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5389
diff changeset
133 self.__pluginObjectRegistry[name] = (objectRef, pluginType)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
134
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
135 def unregisterPluginObject(self, name):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 Public method to unregister a plugin object in the object registry.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
138
7493
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
139 @param name name of the plugin object
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
140 @type str
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
141 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
142 if name in self.__pluginObjectRegistry:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 del self.__pluginObjectRegistry[name]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
144
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
145 def getPluginObject(self, name):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147 Public method to get a reference to a registered plugin object.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
148
7493
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
149 @param name name of the plugin object
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
150 @type str
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151 @return reference to the registered plugin object
10417
c6011e501282 Modernized some code and converted Debug Client and Debugger source code documentation to the new style.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10303
diff changeset
152 @rtype Any
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
153 @exception KeyError raised when the given name is not known
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
154 """
8205
4a0f1f896341 Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
155 if name not in self.__pluginObjectRegistry:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
156 raise KeyError('Pluginobject "{0}" is not registered.'.format(name))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
157
8205
4a0f1f896341 Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
158 return self.__pluginObjectRegistry[name][0]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
159
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 def getPluginObjects(self):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 Public method to get a list of (name, reference) pairs of all
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163 registered plugin objects.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
164
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 @return list of (name, reference) pairs
7493
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
166 @rtype list of (str, any)
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 objects = []
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 for name in self.__pluginObjectRegistry:
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 objects.append((name, self.__pluginObjectRegistry[name][0]))
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 return objects
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
172
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 def getPluginObjectType(self, name):
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 """
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 Public method to get the type of a registered plugin object.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
176
7493
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
177 @param name name of the plugin object
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
178 @type str
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
179 @return type of the plugin object
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
180 @rtype str
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
181 @exception KeyError raised when the given name is not known
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 """
8205
4a0f1f896341 Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
183 if name not in self.__pluginObjectRegistry:
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
184 raise KeyError('Pluginobject "{0}" is not registered.'.format(name))
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
185
8205
4a0f1f896341 Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8143
diff changeset
186 return self.__pluginObjectRegistry[name][1]
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
187
8880
4b631598f752 Corrected the style sheet path replacement function to use a path with forward slashes (i.e. non-native on Windows platforms).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8864
diff changeset
188 def getStyleIconsPath(self, universal=False):
8864
4a0f7105dbd8 Added configuration capability for the path containing the style icon sub-directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8843
diff changeset
189 """
4a0f7105dbd8 Added configuration capability for the path containing the style icon sub-directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8843
diff changeset
190 Public method to get the path for the style icons.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
191
8880
4b631598f752 Corrected the style sheet path replacement function to use a path with forward slashes (i.e. non-native on Windows platforms).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8864
diff changeset
192 @param universal flag indicating a universal file path (defaults to
4b631598f752 Corrected the style sheet path replacement function to use a path with forward slashes (i.e. non-native on Windows platforms).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8864
diff changeset
193 False)
4b631598f752 Corrected the style sheet path replacement function to use a path with forward slashes (i.e. non-native on Windows platforms).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8864
diff changeset
194 @type bool (optional)
8864
4a0f7105dbd8 Added configuration capability for the path containing the style icon sub-directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8843
diff changeset
195 @return directory path containing the style icons
4a0f7105dbd8 Added configuration capability for the path containing the style icon sub-directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8843
diff changeset
196 @rtype str
4a0f7105dbd8 Added configuration capability for the path containing the style icon sub-directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8843
diff changeset
197 """
9624
b47dfa7a137d Refactored the Utilities and Globals modules in order to enhance the maintainability.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9473
diff changeset
198 from eric7 import Preferences
9448
ea215f7afab3 Fixed an issue importing the eric7config module.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9413
diff changeset
199 from eric7.Globals import getConfig
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
200
8864
4a0f7105dbd8 Added configuration capability for the path containing the style icon sub-directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8843
diff changeset
201 styleIconsPath = Preferences.getUI("StyleIconsPath")
4a0f7105dbd8 Added configuration capability for the path containing the style icon sub-directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8843
diff changeset
202 if not styleIconsPath:
4a0f7105dbd8 Added configuration capability for the path containing the style icon sub-directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8843
diff changeset
203 # default is the 'StyleIcons' sub-directory of the icons
4a0f7105dbd8 Added configuration capability for the path containing the style icon sub-directories.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8843
diff changeset
204 # directory
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
205 styleIconsPath = os.path.join(getConfig("ericIconDir"), "StyleIcons")
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
206
8880
4b631598f752 Corrected the style sheet path replacement function to use a path with forward slashes (i.e. non-native on Windows platforms).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8864
diff changeset
207 if universal:
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: 10909
diff changeset
208 return (
95a15b70f7bb Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10909
diff changeset
209 pathlib.PurePath(styleIconsPath).as_posix()
95a15b70f7bb Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10909
diff changeset
210 if bool(styleIconsPath)
95a15b70f7bb Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10909
diff changeset
211 else ""
95a15b70f7bb Refactored some packages, modules and code to allow extracting the 'EricXxx' packages into a library project.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10909
diff changeset
212 )
8880
4b631598f752 Corrected the style sheet path replacement function to use a path with forward slashes (i.e. non-native on Windows platforms).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8864
diff changeset
213 else:
4b631598f752 Corrected the style sheet path replacement function to use a path with forward slashes (i.e. non-native on Windows platforms).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8864
diff changeset
214 return styleIconsPath
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
215
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
216 def setStyleSheetFile(self, filename):
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
217 """
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
218 Public method to read a QSS style sheet file and set the application
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
219 style sheet based on its contents.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
220
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
221 @param filename name of the QSS style sheet file
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
222 @type str
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
223 """
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
224 if filename:
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
225 try:
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
226 with open(filename, "r", encoding="utf-8") as f:
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
227 styleSheet = f.read()
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
228 except OSError as msg:
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
229 EricMessageBox.warning(
8908
48f55b2e7fe5 Fixed an issue in EricApplication.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8881
diff changeset
230 None,
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
231 QCoreApplication.translate(
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
232 "EricApplication", "Loading Style Sheet"
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
233 ),
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
234 QCoreApplication.translate(
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
235 "EricApplication",
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
236 """<p>The Qt Style Sheet file <b>{0}</b> could"""
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
237 """ not be read.<br>Reason: {1}</p>""",
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
238 ).format(filename, str(msg)),
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
239 )
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
240 return
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
241 else:
8840
c9fa102d0194 Fixed an issue during startup.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8837
diff changeset
242 styleSheet = ""
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
243
8843
586ee2c4553a Enhanced style sheet previewer and style sheet handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8840
diff changeset
244 if styleSheet:
8880
4b631598f752 Corrected the style sheet path replacement function to use a path with forward slashes (i.e. non-native on Windows platforms).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8864
diff changeset
245 # pre-process the style sheet to replace the placeholder for the
8843
586ee2c4553a Enhanced style sheet previewer and style sheet handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8840
diff changeset
246 # path to the icons
8880
4b631598f752 Corrected the style sheet path replacement function to use a path with forward slashes (i.e. non-native on Windows platforms).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8864
diff changeset
247 styleIconsPath = self.getStyleIconsPath(universal=True)
8843
586ee2c4553a Enhanced style sheet previewer and style sheet handling.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8840
diff changeset
248 styleSheet = styleSheet.replace("${path}", styleIconsPath)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
249
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
250 if "QPalette {" in styleSheet:
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
251 self.__setPaletteFromStyleSheet(styleSheet)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
252
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
253 ericApp().setStyleSheet(styleSheet)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
254
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
255 def __setPaletteFromStyleSheet(self, styleSheet):
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
256 """
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
257 Private method to set the palette from a style sheet.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
258
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
259 @param styleSheet style sheet
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
260 @type str
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
261 """
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
262 palette = self.palette()
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
263
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
264 paletteStr = styleSheet.split("QPalette {")[1].split("}")[0]
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
265 paletteLines = paletteStr.strip().splitlines()
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
266 for line in paletteLines:
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
267 role, value = line.strip().split()
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
268 role = role.strip("\t :").lower()
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
269 value = value.strip("\t ;")
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
270 if role in self.PaletteRoleMapping and value.startswith("#"):
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
271 palette.setColor(self.PaletteRoleMapping[role], QColor(value))
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
272
8837
6b4b2acc5324 Added capability to configure the eric application palette via a QSS file (handled internally by eric).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8729
diff changeset
273 self.setPalette(palette)
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
274
9976
ceae971872de EricApplication: adapted the dark palette logic to Qt 6.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
275 self.__hasNonStandardPalette = True
ceae971872de EricApplication: adapted the dark palette logic to Qt 6.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
276
7493
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
277 def usesDarkPalette(self):
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
278 """
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
279 Public method to check, if the application uses a palette with a dark
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
280 background.
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
281
7493
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
282 @return flag indicating the use of a palette with a dark background
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
283 @rtype bool
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
284 """
9976
ceae971872de EricApplication: adapted the dark palette logic to Qt 6.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
285 if not self.__hasNonStandardPalette:
ceae971872de EricApplication: adapted the dark palette logic to Qt 6.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
286 with contextlib.suppress(AttributeError):
ceae971872de EricApplication: adapted the dark palette logic to Qt 6.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
287 return self.styleHints().colorScheme() == Qt.ColorScheme.Dark
ceae971872de EricApplication: adapted the dark palette logic to Qt 6.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
288
ceae971872de EricApplication: adapted the dark palette logic to Qt 6.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
289 # backward compatibility for Qt < 6.5.0 or changed by user
7493
1696e91a5393 Added vector icons for the mercurial and subversion plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
290 palette = self.palette()
9976
ceae971872de EricApplication: adapted the dark palette logic to Qt 6.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
291 return (
9995
00eb2b418f8e Corrected some code formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9976
diff changeset
292 palette.color(QPalette.ColorRole.WindowText).lightness()
00eb2b418f8e Corrected some code formatting issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9976
diff changeset
293 > palette.color(QPalette.ColorRole.Window).lightness()
9976
ceae971872de EricApplication: adapted the dark palette logic to Qt 6.5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9653
diff changeset
294 )
55
b5c84934de9c Renamed E4Gui to E5Gui.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
295
11034
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
296 def setMainWindow(self, mainWindow):
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
297 """
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
298 Public method to set the reference to the application main window.
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
299
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
300 @param mainWindow reference to the application main window
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
301 @type QWidget
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
302 """
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
303 self.__mainWindow = mainWindow
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
304
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
305 def getMainWindow(self):
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
306 """
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
307 Public method to get a reference to the application main window.
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
308
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
309 @return reference to the application main window
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
310 @rtype QWidget
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
311 """
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
312 return self.__mainWindow
7b8a21fd2d58 Extended the EricMessageBox module to determine a parent widget if none was given and extended the EricApplication class to store a reference to the main widget.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 10933
diff changeset
313
9221
bf71ee032bb4 Reformatted the source code using the 'Black' utility.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 9209
diff changeset
314
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
315 ericApp = QCoreApplication.instance

eric ide

mercurial