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