eric6/E5Gui/E5Application.py

changeset 7493
1696e91a5393
parent 7360
9190402e4505
child 7502
426f64d419f0
equal deleted inserted replaced
7492:39e3ed0bc0c6 7493:1696e91a5393
7 Class implementing a specialized application class. 7 Class implementing a specialized application class.
8 """ 8 """
9 9
10 10
11 from PyQt5.QtCore import Qt, QCoreApplication 11 from PyQt5.QtCore import Qt, QCoreApplication
12 from PyQt5.QtGui import QPalette
12 from PyQt5.QtWidgets import QApplication 13 from PyQt5.QtWidgets import QApplication
13 14
14 15
15 class E5Application(QApplication): 16 class E5Application(QApplication):
16 """ 17 """
19 def __init__(self, argv): 20 def __init__(self, argv):
20 """ 21 """
21 Constructor 22 Constructor
22 23
23 @param argv command line arguments 24 @param argv command line arguments
25 @type list
24 """ 26 """
25 try: 27 try:
26 QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling) 28 QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
27 # __IGNORE_EXCEPTION__ 29 # __IGNORE_EXCEPTION__
28 except AttributeError: 30 except AttributeError:
42 except AttributeError: 44 except AttributeError:
43 pass 45 pass
44 46
45 self.__objectRegistry = {} 47 self.__objectRegistry = {}
46 self.__pluginObjectRegistry = {} 48 self.__pluginObjectRegistry = {}
47 49
48 def registerObject(self, name, objectRef): 50 def registerObject(self, name, objectRef):
49 """ 51 """
50 Public method to register an object in the object registry. 52 Public method to register an object in the object registry.
51 53
52 @param name name of the object (string) 54 @param name name of the object
55 @type str
53 @param objectRef reference to the object 56 @param objectRef reference to the object
57 @type any
54 @exception KeyError raised when the given name is already in use 58 @exception KeyError raised when the given name is already in use
55 """ 59 """
56 if name in self.__objectRegistry: 60 if name in self.__objectRegistry:
57 raise KeyError('Object "{0}" already registered.'.format(name)) 61 raise KeyError('Object "{0}" already registered.'.format(name))
58 else: 62 else:
59 self.__objectRegistry[name] = objectRef 63 self.__objectRegistry[name] = objectRef
60 64
61 def getObject(self, name): 65 def getObject(self, name):
62 """ 66 """
63 Public method to get a reference to a registered object. 67 Public method to get a reference to a registered object.
64 68
65 @param name name of the object (string) 69 @param name name of the object
70 @type str
66 @return reference to the registered object 71 @return reference to the registered object
72 @type any
67 @exception KeyError raised when the given name is not known 73 @exception KeyError raised when the given name is not known
68 """ 74 """
69 if name in self.__objectRegistry: 75 if name in self.__objectRegistry:
70 return self.__objectRegistry[name] 76 return self.__objectRegistry[name]
71 else: 77 else:
72 raise KeyError('Object "{0}" is not registered.'.format(name)) 78 raise KeyError('Object "{0}" is not registered.'.format(name))
73 79
74 def registerPluginObject(self, name, objectRef, pluginType=None): 80 def registerPluginObject(self, name, objectRef, pluginType=None):
75 """ 81 """
76 Public method to register a plugin object in the object registry. 82 Public method to register a plugin object in the object registry.
77 83
78 @param name name of the plugin object (string) 84 @param name name of the plugin object
85 @type str
79 @param objectRef reference to the plugin object 86 @param objectRef reference to the plugin object
80 @keyparam pluginType type of the plugin object (string) 87 @type any
88 @param pluginType type of the plugin object
89 @type str
81 @exception KeyError raised when the given name is already in use 90 @exception KeyError raised when the given name is already in use
82 """ 91 """
83 if name in self.__pluginObjectRegistry: 92 if name in self.__pluginObjectRegistry:
84 raise KeyError( 93 raise KeyError(
85 'Pluginobject "{0}" already registered.'.format(name)) 94 'Pluginobject "{0}" already registered.'.format(name))
86 else: 95 else:
87 self.__pluginObjectRegistry[name] = (objectRef, pluginType) 96 self.__pluginObjectRegistry[name] = (objectRef, pluginType)
88 97
89 def unregisterPluginObject(self, name): 98 def unregisterPluginObject(self, name):
90 """ 99 """
91 Public method to unregister a plugin object in the object registry. 100 Public method to unregister a plugin object in the object registry.
92 101
93 @param name name of the plugin object (string) 102 @param name name of the plugin object
103 @type str
94 """ 104 """
95 if name in self.__pluginObjectRegistry: 105 if name in self.__pluginObjectRegistry:
96 del self.__pluginObjectRegistry[name] 106 del self.__pluginObjectRegistry[name]
97 107
98 def getPluginObject(self, name): 108 def getPluginObject(self, name):
99 """ 109 """
100 Public method to get a reference to a registered plugin object. 110 Public method to get a reference to a registered plugin object.
101 111
102 @param name name of the plugin object (string) 112 @param name name of the plugin object
113 @type str
103 @return reference to the registered plugin object 114 @return reference to the registered plugin object
115 @rtype any
104 @exception KeyError raised when the given name is not known 116 @exception KeyError raised when the given name is not known
105 """ 117 """
106 if name in self.__pluginObjectRegistry: 118 if name in self.__pluginObjectRegistry:
107 return self.__pluginObjectRegistry[name][0] 119 return self.__pluginObjectRegistry[name][0]
108 else: 120 else:
109 raise KeyError( 121 raise KeyError(
110 'Pluginobject "{0}" is not registered.'.format(name)) 122 'Pluginobject "{0}" is not registered.'.format(name))
111 123
112 def getPluginObjects(self): 124 def getPluginObjects(self):
113 """ 125 """
114 Public method to get a list of (name, reference) pairs of all 126 Public method to get a list of (name, reference) pairs of all
115 registered plugin objects. 127 registered plugin objects.
116 128
117 @return list of (name, reference) pairs 129 @return list of (name, reference) pairs
130 @rtype list of (str, any)
118 """ 131 """
119 objects = [] 132 objects = []
120 for name in self.__pluginObjectRegistry: 133 for name in self.__pluginObjectRegistry:
121 objects.append((name, self.__pluginObjectRegistry[name][0])) 134 objects.append((name, self.__pluginObjectRegistry[name][0]))
122 return objects 135 return objects
123 136
124 def getPluginObjectType(self, name): 137 def getPluginObjectType(self, name):
125 """ 138 """
126 Public method to get the type of a registered plugin object. 139 Public method to get the type of a registered plugin object.
127 140
128 @param name name of the plugin object (string) 141 @param name name of the plugin object
129 @return type of the plugin object (string) 142 @type str
143 @return type of the plugin object
144 @rtype str
130 @exception KeyError raised when the given name is not known 145 @exception KeyError raised when the given name is not known
131 """ 146 """
132 if name in self.__pluginObjectRegistry: 147 if name in self.__pluginObjectRegistry:
133 return self.__pluginObjectRegistry[name][1] 148 return self.__pluginObjectRegistry[name][1]
134 else: 149 else:
135 raise KeyError( 150 raise KeyError(
136 'Pluginobject "{0}" is not registered.'.format(name)) 151 'Pluginobject "{0}" is not registered.'.format(name))
152
153 def usesDarkPalette(self):
154 """
155 Public method to check, if the application uses a palette with a dark
156 background.
157
158 @return flag indicating the use of a palette with a dark background
159 @rtype bool
160 """
161 palette = self.palette()
162 lightness = palette.color(QPalette.Window).lightness()
163 return lightness <= 128
137 164
138 e5App = QCoreApplication.instance 165 e5App = QCoreApplication.instance

eric ide

mercurial