eric6/E5Gui/E5Application.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7229
53054eb5b15a
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2009 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Class implementing a specialized application class.
8 """
9
10 from __future__ import unicode_literals
11
12 from PyQt5.QtCore import Qt, QCoreApplication
13 from PyQt5.QtWidgets import QApplication
14
15
16 class E5Application(QApplication):
17 """
18 Eric application class with an object registry.
19 """
20 def __init__(self, argv):
21 """
22 Constructor
23
24 @param argv command line arguments
25 """
26 try:
27 QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
28 # __IGNORE_EXCEPTION__
29 except AttributeError:
30 pass
31 try:
32 QCoreApplication.setAttribute(Qt.AA_ShareOpenGLContexts)
33 # __IGNORE_EXCEPTION__
34 except AttributeError:
35 pass
36
37 super(E5Application, self).__init__(argv)
38
39 QCoreApplication.setAttribute(Qt.AA_DontCreateNativeWidgetSiblings)
40 try:
41 QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
42 # __IGNORE_EXCEPTION__
43 except AttributeError:
44 pass
45
46 self.__objectRegistry = {}
47 self.__pluginObjectRegistry = {}
48
49 def registerObject(self, name, objectRef):
50 """
51 Public method to register an object in the object registry.
52
53 @param name name of the object (string)
54 @param objectRef reference to the object
55 @exception KeyError raised when the given name is already in use
56 """
57 if name in self.__objectRegistry:
58 raise KeyError('Object "{0}" already registered.'.format(name))
59 else:
60 self.__objectRegistry[name] = objectRef
61
62 def getObject(self, name):
63 """
64 Public method to get a reference to a registered object.
65
66 @param name name of the object (string)
67 @return reference to the registered object
68 @exception KeyError raised when the given name is not known
69 """
70 if name in self.__objectRegistry:
71 return self.__objectRegistry[name]
72 else:
73 raise KeyError('Object "{0}" is not registered.'.format(name))
74
75 def registerPluginObject(self, name, objectRef, pluginType=None):
76 """
77 Public method to register a plugin object in the object registry.
78
79 @param name name of the plugin object (string)
80 @param objectRef reference to the plugin object
81 @keyparam pluginType type of the plugin object (string)
82 @exception KeyError raised when the given name is already in use
83 """
84 if name in self.__pluginObjectRegistry:
85 raise KeyError(
86 'Pluginobject "{0}" already registered.'.format(name))
87 else:
88 self.__pluginObjectRegistry[name] = (objectRef, pluginType)
89
90 def unregisterPluginObject(self, name):
91 """
92 Public method to unregister a plugin object in the object registry.
93
94 @param name name of the plugin object (string)
95 """
96 if name in self.__pluginObjectRegistry:
97 del self.__pluginObjectRegistry[name]
98
99 def getPluginObject(self, name):
100 """
101 Public method to get a reference to a registered plugin object.
102
103 @param name name of the plugin object (string)
104 @return reference to the registered plugin object
105 @exception KeyError raised when the given name is not known
106 """
107 if name in self.__pluginObjectRegistry:
108 return self.__pluginObjectRegistry[name][0]
109 else:
110 raise KeyError(
111 'Pluginobject "{0}" is not registered.'.format(name))
112
113 def getPluginObjects(self):
114 """
115 Public method to get a list of (name, reference) pairs of all
116 registered plugin objects.
117
118 @return list of (name, reference) pairs
119 """
120 objects = []
121 for name in self.__pluginObjectRegistry:
122 objects.append((name, self.__pluginObjectRegistry[name][0]))
123 return objects
124
125 def getPluginObjectType(self, name):
126 """
127 Public method to get the type of a registered plugin object.
128
129 @param name name of the plugin object (string)
130 @return type of the plugin object (string)
131 @exception KeyError raised when the given name is not known
132 """
133 if name in self.__pluginObjectRegistry:
134 return self.__pluginObjectRegistry[name][1]
135 else:
136 raise KeyError(
137 'Pluginobject "{0}" is not registered.'.format(name))
138
139 e5App = QCoreApplication.instance

eric ide

mercurial