16 |
16 |
17 class PluginInfoDialog(QDialog, Ui_PluginInfoDialog): |
17 class PluginInfoDialog(QDialog, Ui_PluginInfoDialog): |
18 """ |
18 """ |
19 Class implementing the Plugin Info Dialog. |
19 Class implementing the Plugin Info Dialog. |
20 """ |
20 """ |
|
21 |
21 def __init__(self, pluginManager, parent=None): |
22 def __init__(self, pluginManager, parent=None): |
22 """ |
23 """ |
23 Constructor |
24 Constructor |
24 |
25 |
25 @param pluginManager reference to the plugin manager object |
26 @param pluginManager reference to the plugin manager object |
26 @param parent parent of this dialog (QWidget) |
27 @param parent parent of this dialog (QWidget) |
27 """ |
28 """ |
28 super().__init__(parent) |
29 super().__init__(parent) |
29 self.setupUi(self) |
30 self.setupUi(self) |
30 self.setWindowFlags(Qt.WindowType.Window) |
31 self.setWindowFlags(Qt.WindowType.Window) |
31 |
32 |
32 self.pm = pluginManager |
33 self.pm = pluginManager |
33 |
34 |
34 self.__autoActivateColumn = 3 |
35 self.__autoActivateColumn = 3 |
35 self.__activeColumn = 4 |
36 self.__activeColumn = 4 |
36 |
37 |
37 self.pluginList.headerItem().setText(self.pluginList.columnCount(), "") |
38 self.pluginList.headerItem().setText(self.pluginList.columnCount(), "") |
38 |
39 |
39 # populate the list |
40 # populate the list |
40 self.__populateList() |
41 self.__populateList() |
41 self.pluginList.sortByColumn(0, Qt.SortOrder.AscendingOrder) |
42 self.pluginList.sortByColumn(0, Qt.SortOrder.AscendingOrder) |
42 |
43 |
43 self.__menu = QMenu(self) |
44 self.__menu = QMenu(self) |
44 self.__menu.addAction(self.tr('Show details'), self.__showDetails) |
45 self.__menu.addAction(self.tr("Show details"), self.__showDetails) |
45 self.__activateAct = self.__menu.addAction( |
46 self.__activateAct = self.__menu.addAction( |
46 self.tr('Activate'), self.__activatePlugin) |
47 self.tr("Activate"), self.__activatePlugin |
|
48 ) |
47 self.__deactivateAct = self.__menu.addAction( |
49 self.__deactivateAct = self.__menu.addAction( |
48 self.tr('Deactivate'), self.__deactivatePlugin) |
50 self.tr("Deactivate"), self.__deactivatePlugin |
49 self.pluginList.setContextMenuPolicy( |
51 ) |
50 Qt.ContextMenuPolicy.CustomContextMenu) |
52 self.pluginList.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu) |
51 self.pluginList.customContextMenuRequested.connect( |
53 self.pluginList.customContextMenuRequested.connect(self.__showContextMenu) |
52 self.__showContextMenu) |
54 |
53 |
|
54 def __populateList(self): |
55 def __populateList(self): |
55 """ |
56 """ |
56 Private method to (re)populate the list of plugins. |
57 Private method to (re)populate the list of plugins. |
57 """ |
58 """ |
58 self.pluginList.clear() |
59 self.pluginList.clear() |
59 for info in self.pm.getPluginInfos(): |
60 for info in self.pm.getPluginInfos(): |
60 self.__createEntry(info) |
61 self.__createEntry(info) |
61 self.pluginList.sortItems( |
62 self.pluginList.sortItems( |
62 self.pluginList.sortColumn(), |
63 self.pluginList.sortColumn(), self.pluginList.header().sortIndicatorOrder() |
63 self.pluginList.header().sortIndicatorOrder()) |
64 ) |
64 |
65 |
65 def __createEntry(self, info): |
66 def __createEntry(self, info): |
66 """ |
67 """ |
67 Private method to create a list entry based on the provided info. |
68 Private method to create a list entry based on the provided info. |
68 |
69 |
69 @param info dictionary giving the info for the entry (as returned by |
70 @param info dictionary giving the info for the entry (as returned by |
70 PluginManager.getPluginInfos()) |
71 PluginManager.getPluginInfos()) |
71 @type dict |
72 @type dict |
72 """ |
73 """ |
73 infoList = [ |
74 infoList = [ |
74 info["module_name"], |
75 info["module_name"], |
75 info["plugin_name"], |
76 info["plugin_name"], |
76 info["version"], |
77 info["version"], |
77 (info["auto_activate"] and self.tr("Yes") or self.tr("On-Demand")), |
78 (info["auto_activate"] and self.tr("Yes") or self.tr("On-Demand")), |
78 (info["active"] and self.tr("Yes") or self.tr("No")), |
79 (info["active"] and self.tr("Yes") or self.tr("No")), |
79 info["short_desc"] |
80 info["short_desc"], |
80 ] |
81 ] |
81 itm = QTreeWidgetItem(self.pluginList, infoList) |
82 itm = QTreeWidgetItem(self.pluginList, infoList) |
82 if info["error"]: |
83 if info["error"]: |
83 # plugin error |
84 # plugin error |
84 for col in range(self.pluginList.columnCount()): |
85 for col in range(self.pluginList.columnCount()): |
85 itm.setForeground(col, QBrush(Qt.GlobalColor.red)) |
86 itm.setForeground(col, QBrush(Qt.GlobalColor.red)) |
86 itm.setTextAlignment(self.__autoActivateColumn, |
87 itm.setTextAlignment(self.__autoActivateColumn, Qt.AlignmentFlag.AlignHCenter) |
87 Qt.AlignmentFlag.AlignHCenter) |
88 itm.setTextAlignment(self.__activeColumn, Qt.AlignmentFlag.AlignHCenter) |
88 itm.setTextAlignment(self.__activeColumn, |
89 |
89 Qt.AlignmentFlag.AlignHCenter) |
90 self.pluginList.header().resizeSections(QHeaderView.ResizeMode.ResizeToContents) |
90 |
|
91 self.pluginList.header().resizeSections( |
|
92 QHeaderView.ResizeMode.ResizeToContents) |
|
93 self.pluginList.header().setStretchLastSection(True) |
91 self.pluginList.header().setStretchLastSection(True) |
94 |
92 |
95 def __showContextMenu(self, coord): |
93 def __showContextMenu(self, coord): |
96 """ |
94 """ |
97 Private slot to show the context menu of the listview. |
95 Private slot to show the context menu of the listview. |
98 |
96 |
99 @param coord the position of the mouse pointer (QPoint) |
97 @param coord the position of the mouse pointer (QPoint) |
100 """ |
98 """ |
101 itm = self.pluginList.itemAt(coord) |
99 itm = self.pluginList.itemAt(coord) |
102 if itm is not None: |
100 if itm is not None: |
103 autoactivate = (itm.text(self.__autoActivateColumn) == |
101 autoactivate = itm.text(self.__autoActivateColumn) == self.tr("Yes") |
104 self.tr("Yes")) |
|
105 if itm.text(self.__activeColumn) == self.tr("Yes"): |
102 if itm.text(self.__activeColumn) == self.tr("Yes"): |
106 self.__activateAct.setEnabled(False) |
103 self.__activateAct.setEnabled(False) |
107 self.__deactivateAct.setEnabled(autoactivate) |
104 self.__deactivateAct.setEnabled(autoactivate) |
108 else: |
105 else: |
109 self.__activateAct.setEnabled(autoactivate) |
106 self.__activateAct.setEnabled(autoactivate) |
110 self.__deactivateAct.setEnabled(False) |
107 self.__deactivateAct.setEnabled(False) |
111 self.__menu.popup(self.mapToGlobal(coord)) |
108 self.__menu.popup(self.mapToGlobal(coord)) |
112 |
109 |
113 @pyqtSlot(QTreeWidgetItem, int) |
110 @pyqtSlot(QTreeWidgetItem, int) |
114 def on_pluginList_itemActivated(self, item, column): |
111 def on_pluginList_itemActivated(self, item, column): |
115 """ |
112 """ |
116 Private slot to show details about a plugin. |
113 Private slot to show details about a plugin. |
117 |
114 |
118 @param item reference to the selected item (QTreeWidgetItem) |
115 @param item reference to the selected item (QTreeWidgetItem) |
119 @param column column number (integer) |
116 @param column column number (integer) |
120 """ |
117 """ |
121 moduleName = item.text(0) |
118 moduleName = item.text(0) |
122 details = self.pm.getPluginDetails(moduleName) |
119 details = self.pm.getPluginDetails(moduleName) |
123 if details is None: |
120 if details is None: |
124 pass |
121 pass |
125 else: |
122 else: |
126 from .PluginDetailsDialog import PluginDetailsDialog |
123 from .PluginDetailsDialog import PluginDetailsDialog |
|
124 |
127 dlg = PluginDetailsDialog(details, self) |
125 dlg = PluginDetailsDialog(details, self) |
128 dlg.show() |
126 dlg.show() |
129 |
127 |
130 def __showDetails(self): |
128 def __showDetails(self): |
131 """ |
129 """ |
132 Private slot to handle the "Show details" context menu action. |
130 Private slot to handle the "Show details" context menu action. |
133 """ |
131 """ |
134 itm = self.pluginList.currentItem() |
132 itm = self.pluginList.currentItem() |
135 self.on_pluginList_itemActivated(itm, 0) |
133 self.on_pluginList_itemActivated(itm, 0) |
136 |
134 |
137 def __activatePlugin(self): |
135 def __activatePlugin(self): |
138 """ |
136 """ |
139 Private slot to handle the "Deactivate" context menu action. |
137 Private slot to handle the "Deactivate" context menu action. |
140 """ |
138 """ |
141 itm = self.pluginList.currentItem() |
139 itm = self.pluginList.currentItem() |
142 moduleName = itm.text(0) |
140 moduleName = itm.text(0) |
143 self.pm.activatePlugin(moduleName) |
141 self.pm.activatePlugin(moduleName) |
144 # repopulate the list |
142 # repopulate the list |
145 self.__populateList() |
143 self.__populateList() |
146 |
144 |
147 def __deactivatePlugin(self): |
145 def __deactivatePlugin(self): |
148 """ |
146 """ |
149 Private slot to handle the "Activate" context menu action. |
147 Private slot to handle the "Activate" context menu action. |
150 """ |
148 """ |
151 itm = self.pluginList.currentItem() |
149 itm = self.pluginList.currentItem() |