eric6/PluginManager/PluginInfoDialog.py

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

eric ide

mercurial