51 self.__external = True |
51 self.__external = True |
52 else: |
52 else: |
53 self.__pluginManager = pluginManager |
53 self.__pluginManager = pluginManager |
54 self.__external = False |
54 self.__external = False |
55 |
55 |
56 self.pluginDirectoryCombo.addItem(self.trUtf8("User plugins directory"), |
56 self.pluginDirectoryCombo.addItem( |
|
57 self.trUtf8("User plugins directory"), |
57 self.__pluginManager.getPluginDir("user")) |
58 self.__pluginManager.getPluginDir("user")) |
58 |
59 |
59 globalDir = self.__pluginManager.getPluginDir("global") |
60 globalDir = self.__pluginManager.getPluginDir("global") |
60 if globalDir is not None and os.access(globalDir, os.W_OK): |
61 if globalDir is not None and os.access(globalDir, os.W_OK): |
61 self.pluginDirectoryCombo.addItem(self.trUtf8("Global plugins directory"), |
62 self.pluginDirectoryCombo.addItem( |
|
63 self.trUtf8("Global plugins directory"), |
62 globalDir) |
64 globalDir) |
63 |
65 |
64 @pyqtSlot(int) |
66 @pyqtSlot(int) |
65 def on_pluginDirectoryCombo_currentIndexChanged(self, index): |
67 def on_pluginDirectoryCombo_currentIndexChanged(self, index): |
66 """ |
68 """ |
69 |
71 |
70 @param index index of the selected item (integer) |
72 @param index index of the selected item (integer) |
71 """ |
73 """ |
72 pluginDirectory = self.pluginDirectoryCombo\ |
74 pluginDirectory = self.pluginDirectoryCombo\ |
73 .itemData(index) |
75 .itemData(index) |
74 pluginNames = sorted(self.__pluginManager.getPluginModules(pluginDirectory)) |
76 pluginNames = sorted(self.__pluginManager.getPluginModules( |
|
77 pluginDirectory)) |
75 self.pluginNameCombo.clear() |
78 self.pluginNameCombo.clear() |
76 for pluginName in pluginNames: |
79 for pluginName in pluginNames: |
77 fname = "{0}.py".format(os.path.join(pluginDirectory, pluginName)) |
80 fname = "{0}.py".format(os.path.join(pluginDirectory, pluginName)) |
78 self.pluginNameCombo.addItem(pluginName, fname) |
81 self.pluginNameCombo.addItem(pluginName, fname) |
79 self.buttonBox.button(QDialogButtonBox.Ok)\ |
82 self.buttonBox.button(QDialogButtonBox.Ok)\ |
100 .itemData(self.pluginNameCombo.currentIndex()) |
103 .itemData(self.pluginNameCombo.currentIndex()) |
101 |
104 |
102 if not self.__pluginManager.unloadPlugin(pluginName): |
105 if not self.__pluginManager.unloadPlugin(pluginName): |
103 E5MessageBox.critical(self, |
106 E5MessageBox.critical(self, |
104 self.trUtf8("Plugin Uninstallation"), |
107 self.trUtf8("Plugin Uninstallation"), |
105 self.trUtf8("""<p>The plugin <b>{0}</b> could not be unloaded.""" |
108 self.trUtf8( |
106 """ Aborting...</p>""").format(pluginName)) |
109 """<p>The plugin <b>{0}</b> could not be unloaded.""" |
|
110 """ Aborting...</p>""").format(pluginName)) |
107 return False |
111 return False |
108 |
112 |
109 if not pluginDirectory in sys.path: |
113 if not pluginDirectory in sys.path: |
110 sys.path.insert(2, pluginDirectory) |
114 sys.path.insert(2, pluginDirectory) |
111 module = imp.load_source(pluginName, pluginFile) |
115 module = imp.load_source(pluginName, pluginFile) |
112 if not hasattr(module, "packageName"): |
116 if not hasattr(module, "packageName"): |
113 E5MessageBox.critical(self, |
117 E5MessageBox.critical(self, |
114 self.trUtf8("Plugin Uninstallation"), |
118 self.trUtf8("Plugin Uninstallation"), |
115 self.trUtf8("""<p>The plugin <b>{0}</b> has no 'packageName' attribute.""" |
119 self.trUtf8( |
116 """ Aborting...</p>""").format(pluginName)) |
120 """<p>The plugin <b>{0}</b> has no 'packageName'""" |
|
121 """ attribute. Aborting...</p>""").format(pluginName)) |
117 return False |
122 return False |
118 |
123 |
119 package = getattr(module, "packageName") |
124 package = getattr(module, "packageName") |
120 if package is None: |
125 if package is None: |
121 package = "None" |
126 package = "None" |
125 if hasattr(module, "prepareUninstall"): |
130 if hasattr(module, "prepareUninstall"): |
126 module.prepareUninstall() |
131 module.prepareUninstall() |
127 internalPackages = [] |
132 internalPackages = [] |
128 if hasattr(module, "internalPackages"): |
133 if hasattr(module, "internalPackages"): |
129 # it is a comma separated string |
134 # it is a comma separated string |
130 internalPackages = [p.strip() for p in module.internalPackages.split(",")] |
135 internalPackages = [p.strip() for p in |
|
136 module.internalPackages.split(",")] |
131 del module |
137 del module |
132 |
138 |
133 # clean sys.modules |
139 # clean sys.modules |
134 self.__pluginManager.removePluginFromSysModules( |
140 self.__pluginManager.removePluginFromSysModules( |
135 pluginName, package, internalPackages) |
141 pluginName, package, internalPackages) |
144 |
150 |
145 fnamec = "{0}c".format(pluginFile) |
151 fnamec = "{0}c".format(pluginFile) |
146 if os.path.exists(fnamec): |
152 if os.path.exists(fnamec): |
147 os.remove(fnamec) |
153 os.remove(fnamec) |
148 |
154 |
149 pluginDirCache = os.path.join(os.path.dirname(pluginFile), "__pycache__") |
155 pluginDirCache = os.path.join( |
|
156 os.path.dirname(pluginFile), "__pycache__") |
150 if os.path.exists(pluginDirCache): |
157 if os.path.exists(pluginDirCache): |
151 pluginFileName = os.path.splitext(os.path.basename(pluginFile))[0] |
158 pluginFileName = os.path.splitext( |
152 for fnameo in glob.glob( |
159 os.path.basename(pluginFile))[0] |
153 os.path.join(pluginDirCache, "{0}*.pyo".format(pluginFileName))): |
160 for fnameo in glob.glob(os.path.join( |
|
161 pluginDirCache, "{0}*.pyo".format(pluginFileName))): |
154 os.remove(fnameo) |
162 os.remove(fnameo) |
155 for fnamec in glob.glob( |
163 for fnamec in glob.glob(os.path.join( |
156 os.path.join(pluginDirCache, "{0}*.pyc".format(pluginFileName))): |
164 pluginDirCache, "{0}*.pyc".format(pluginFileName))): |
157 os.remove(fnamec) |
165 os.remove(fnamec) |
158 |
166 |
159 os.remove(pluginFile) |
167 os.remove(pluginFile) |
160 except OSError as err: |
168 except OSError as err: |
161 E5MessageBox.critical(self, |
169 E5MessageBox.critical(self, |
162 self.trUtf8("Plugin Uninstallation"), |
170 self.trUtf8("Plugin Uninstallation"), |
163 self.trUtf8("""<p>The plugin package <b>{0}</b> could not be""" |
171 self.trUtf8( |
164 """ removed. Aborting...</p>""" |
172 """<p>The plugin package <b>{0}</b> could not be""" |
165 """<p>Reason: {1}</p>""").format(packageDir, str(err))) |
173 """ removed. Aborting...</p>""" |
|
174 """<p>Reason: {1}</p>""").format(packageDir, str(err))) |
166 return False |
175 return False |
167 |
176 |
168 if not self.__external: |
177 if not self.__external: |
169 ui = e5App().getObject("UserInterface") |
178 ui = e5App().getObject("UserInterface") |
170 if ui.notificationsEnabled(): |
179 if ui.notificationsEnabled(): |
171 ui.showNotification(UI.PixmapCache.getPixmap("plugin48.png"), |
180 ui.showNotification(UI.PixmapCache.getPixmap("plugin48.png"), |
172 self.trUtf8("Plugin Uninstallation"), |
181 self.trUtf8("Plugin Uninstallation"), |
173 self.trUtf8("""<p>The plugin <b>{0}</b> was uninstalled successfully""" |
182 self.trUtf8( |
174 """ from {1}.</p>""")\ |
183 """<p>The plugin <b>{0}</b> was uninstalled successfully""" |
|
184 """ from {1}.</p>""")\ |
175 .format(pluginName, pluginDirectory)) |
185 .format(pluginName, pluginDirectory)) |
176 return True |
186 return True |
177 |
187 |
178 E5MessageBox.information(self, |
188 E5MessageBox.information(self, |
179 self.trUtf8("Plugin Uninstallation"), |
189 self.trUtf8("Plugin Uninstallation"), |
180 self.trUtf8("""<p>The plugin <b>{0}</b> was uninstalled successfully""" |
190 self.trUtf8( |
181 """ from {1}.</p>""")\ |
191 """<p>The plugin <b>{0}</b> was uninstalled successfully""" |
|
192 """ from {1}.</p>""")\ |
182 .format(pluginName, pluginDirectory)) |
193 .format(pluginName, pluginDirectory)) |
183 return True |
194 return True |
184 |
195 |
185 |
196 |
186 class PluginUninstallDialog(QDialog): |
197 class PluginUninstallDialog(QDialog): |
224 self.cw = PluginUninstallWidget(None, self) |
235 self.cw = PluginUninstallWidget(None, self) |
225 size = self.cw.size() |
236 size = self.cw.size() |
226 self.setCentralWidget(self.cw) |
237 self.setCentralWidget(self.cw) |
227 self.resize(size) |
238 self.resize(size) |
228 |
239 |
229 self.setStyle(Preferences.getUI("Style"), Preferences.getUI("StyleSheet")) |
240 self.setStyle(Preferences.getUI("Style"), |
|
241 Preferences.getUI("StyleSheet")) |
230 |
242 |
231 self.cw.buttonBox.accepted[()].connect(self.close) |
243 self.cw.buttonBox.accepted[()].connect(self.close) |
232 self.cw.buttonBox.rejected[()].connect(self.close) |
244 self.cw.buttonBox.rejected[()].connect(self.close) |