11 import os |
11 import os |
12 import importlib |
12 import importlib |
13 import shutil |
13 import shutil |
14 import glob |
14 import glob |
15 |
15 |
16 from PyQt6.QtCore import pyqtSlot, pyqtSignal |
16 from PyQt6.QtCore import pyqtSlot, pyqtSignal, Qt |
17 from PyQt6.QtWidgets import QWidget, QDialog, QDialogButtonBox, QVBoxLayout |
17 from PyQt6.QtWidgets import QWidget, QDialog, QVBoxLayout, QListWidgetItem |
18 |
18 |
19 from EricWidgets import EricMessageBox |
19 from EricWidgets import EricMessageBox |
20 from EricWidgets.EricMainWindow import EricMainWindow |
20 from EricWidgets.EricMainWindow import EricMainWindow |
21 from EricWidgets.EricApplication import ericApp |
21 from EricWidgets.EricApplication import ericApp |
22 |
22 |
61 globalDir = self.__pluginManager.getPluginDir("global") |
60 globalDir = self.__pluginManager.getPluginDir("global") |
62 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): |
63 self.pluginDirectoryCombo.addItem( |
62 self.pluginDirectoryCombo.addItem( |
64 self.tr("Global plugins directory"), |
63 self.tr("Global plugins directory"), |
65 globalDir) |
64 globalDir) |
66 |
|
67 msh = self.minimumSizeHint() |
|
68 self.resize(max(self.width(), msh.width()), msh.height()) |
|
69 |
65 |
70 @pyqtSlot(int) |
66 @pyqtSlot(int) |
71 def on_pluginDirectoryCombo_currentIndexChanged(self, index): |
67 def on_pluginDirectoryCombo_currentIndexChanged(self, index): |
72 """ |
68 """ |
73 Private slot to populate the plugin name combo upon a change of the |
69 Private slot to populate the plugin name combo upon a change of the |
76 @param index index of the selected item (integer) |
72 @param index index of the selected item (integer) |
77 """ |
73 """ |
78 pluginDirectory = self.pluginDirectoryCombo.itemData(index) |
74 pluginDirectory = self.pluginDirectoryCombo.itemData(index) |
79 pluginNames = sorted(self.__pluginManager.getPluginModules( |
75 pluginNames = sorted(self.__pluginManager.getPluginModules( |
80 pluginDirectory)) |
76 pluginDirectory)) |
81 self.pluginNameCombo.clear() |
77 |
|
78 self.pluginsList.clear() |
82 for pluginName in pluginNames: |
79 for pluginName in pluginNames: |
83 fname = "{0}.py".format(os.path.join(pluginDirectory, pluginName)) |
80 fname = "{0}.py".format(os.path.join(pluginDirectory, pluginName)) |
84 self.pluginNameCombo.addItem(pluginName, fname) |
81 itm = QListWidgetItem(pluginName) |
85 self.buttonBox.button(QDialogButtonBox.StandardButton.Ok).setEnabled( |
82 itm.setData(Qt.ItemDataRole.UserRole, fname) |
86 self.pluginNameCombo.currentText() != "") |
83 itm.setFlags(Qt.ItemFlag.ItemIsEnabled | |
|
84 Qt.ItemFlag.ItemIsUserCheckable) |
|
85 itm.setCheckState(Qt.CheckState.Unchecked) |
|
86 self.pluginsList.addItem(itm) |
87 |
87 |
88 @pyqtSlot() |
88 @pyqtSlot() |
89 def on_buttonBox_accepted(self): |
89 def on_buttonBox_accepted(self): |
90 """ |
90 """ |
91 Private slot to handle the accepted signal of the button box. |
91 Private slot to handle the accepted signal of the button box. |
92 """ |
92 """ |
93 if self.__uninstallPlugin(): |
93 if self.__uninstallPlugins(): |
94 self.accepted.emit() |
94 self.accepted.emit() |
95 |
95 |
96 def __uninstallPlugin(self): |
96 def __getCheckedPlugins(self): |
97 """ |
97 """ |
98 Private slot to uninstall the selected plugin. |
98 Private method to get the list of plugins to be uninstalled. |
99 |
99 |
100 @return flag indicating success (boolean) |
100 @return list of tuples with the plugin name and plugin file name |
|
101 @rtype list of tuples of (str, str) |
|
102 """ |
|
103 plugins = [] |
|
104 for row in range(self.pluginsList.count()): |
|
105 itm = self.pluginsList.item(row) |
|
106 if itm.checkState() == Qt.CheckState.Checked: |
|
107 plugins.append((itm.text(), |
|
108 itm.data(Qt.ItemDataRole.UserRole))) |
|
109 return plugins |
|
110 |
|
111 def __uninstallPlugins(self): |
|
112 """ |
|
113 Private method to uninstall the selected plugins. |
|
114 |
|
115 @return flag indicating success |
|
116 @rtype bool |
|
117 """ |
|
118 checkedPlugins = self.__getCheckedPlugins() |
|
119 uninstallCount = 0 |
|
120 for pluginName, pluginFile in checkedPlugins: |
|
121 if self.__uninstallPlugin(pluginName, pluginFile): |
|
122 uninstallCount += 1 |
|
123 return uninstallCount == len(checkedPlugins) |
|
124 |
|
125 def __uninstallPlugin(self, pluginName, pluginFile): |
|
126 """ |
|
127 Private method to uninstall a given plugin. |
|
128 |
|
129 @param pluginName name of the plugin |
|
130 @type str |
|
131 @param pluginFile file name of the plugin |
|
132 @type str |
|
133 @return flag indicating success |
|
134 @rtype bool |
101 """ |
135 """ |
102 pluginDirectory = self.pluginDirectoryCombo.itemData( |
136 pluginDirectory = self.pluginDirectoryCombo.itemData( |
103 self.pluginDirectoryCombo.currentIndex()) |
137 self.pluginDirectoryCombo.currentIndex()) |
104 pluginName = self.pluginNameCombo.currentText() |
|
105 pluginFile = self.pluginNameCombo.itemData( |
|
106 self.pluginNameCombo.currentIndex()) |
|
107 |
138 |
108 if not self.__pluginManager.unloadPlugin(pluginName): |
139 if not self.__pluginManager.unloadPlugin(pluginName): |
109 EricMessageBox.critical( |
140 EricMessageBox.critical( |
110 self, |
141 self, |
111 self.tr("Plugin Uninstallation"), |
142 self.tr("Plugin Uninstallation"), |