|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2007 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the exceptions raised by the plugin system. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import QCoreApplication |
|
11 |
|
12 |
|
13 class PluginError(Exception): |
|
14 """ |
|
15 Class defining a special error for the plugin classes. |
|
16 """ |
|
17 def __init__(self): |
|
18 """ |
|
19 Constructor |
|
20 """ |
|
21 self._errorMessage = QCoreApplication.translate( |
|
22 "PluginError", "Unspecific plugin error.") |
|
23 |
|
24 def __repr__(self): |
|
25 """ |
|
26 Special method returning a representation of the exception. |
|
27 |
|
28 @return string representing the error message |
|
29 """ |
|
30 return str(self._errorMessage) |
|
31 |
|
32 def __str__(self): |
|
33 """ |
|
34 Special method returning a string representation of the exception. |
|
35 |
|
36 @return string representing the error message |
|
37 """ |
|
38 return str(self._errorMessage) |
|
39 |
|
40 |
|
41 class PluginPathError(PluginError): |
|
42 """ |
|
43 Class defining an error raised, when the plugin paths were not found and |
|
44 could not be created. |
|
45 """ |
|
46 def __init__(self, msg=None): |
|
47 """ |
|
48 Constructor |
|
49 |
|
50 @param msg message to be used by the exception (string) |
|
51 """ |
|
52 if msg: |
|
53 self._errorMessage = msg |
|
54 else: |
|
55 self._errorMessage = QCoreApplication.translate( |
|
56 "PluginError", |
|
57 "Plugin paths not found or not creatable.") |
|
58 |
|
59 |
|
60 class PluginModulesError(PluginError): |
|
61 """ |
|
62 Class defining an error raised, when no plugin modules were found. |
|
63 """ |
|
64 def __init__(self): |
|
65 """ |
|
66 Constructor |
|
67 """ |
|
68 self._errorMessage = QCoreApplication.translate( |
|
69 "PluginError", "No plugin modules found.") |
|
70 |
|
71 |
|
72 class PluginLoadError(PluginError): |
|
73 """ |
|
74 Class defining an error raised, when there was an error during plugin |
|
75 loading. |
|
76 """ |
|
77 def __init__(self, name): |
|
78 """ |
|
79 Constructor |
|
80 |
|
81 @param name name of the plugin module (string) |
|
82 """ |
|
83 self._errorMessage = QCoreApplication.translate( |
|
84 "PluginError", |
|
85 "Error loading plugin module: {0}" |
|
86 ).format(name) |
|
87 |
|
88 |
|
89 class PluginActivationError(PluginError): |
|
90 """ |
|
91 Class defining an error raised, when there was an error during plugin |
|
92 activation. |
|
93 """ |
|
94 def __init__(self, name): |
|
95 """ |
|
96 Constructor |
|
97 |
|
98 @param name name of the plugin module (string) |
|
99 """ |
|
100 self._errorMessage = QCoreApplication.translate( |
|
101 "PluginError", |
|
102 "Error activating plugin module: {0}" |
|
103 ).format(name) |
|
104 |
|
105 |
|
106 class PluginModuleFormatError(PluginError): |
|
107 """ |
|
108 Class defining an error raised, when the plugin module is invalid. |
|
109 """ |
|
110 def __init__(self, name, missing): |
|
111 """ |
|
112 Constructor |
|
113 |
|
114 @param name name of the plugin module (string) |
|
115 @param missing description of the missing element (string) |
|
116 """ |
|
117 self._errorMessage = QCoreApplication.translate( |
|
118 "PluginError", |
|
119 "The plugin module {0} is missing {1}." |
|
120 ).format(name, missing) |
|
121 |
|
122 |
|
123 class PluginClassFormatError(PluginError): |
|
124 """ |
|
125 Class defining an error raised, when the plugin module's class is invalid. |
|
126 """ |
|
127 def __init__(self, name, class_, missing): |
|
128 """ |
|
129 Constructor |
|
130 |
|
131 @param name name of the plugin module (string) |
|
132 @param class_ name of the class not satisfying the requirements |
|
133 (string) |
|
134 @param missing description of the missing element (string) |
|
135 """ |
|
136 self._errorMessage = QCoreApplication.translate( |
|
137 "PluginError", |
|
138 "The plugin class {0} of module {1} is missing {2}." |
|
139 ).format(class_, name, missing) |