| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
from inspect import getdoc |
| 21 |
|
| 22 |
from PyQt5 import QtGui, QtWidgets |
| 23 |
|
| 24 |
from breezy import ( |
| 25 |
_format_version_tuple, |
| 26 |
osutils, |
| 27 |
plugin as mod_plugin, |
| 28 |
) |
| 29 |
|
| 30 |
from breezy.plugins.qbrz.lib.conditional_dataview import ( |
| 31 |
QBzrConditionalDataView, |
| 32 |
) |
| 33 |
from breezy.plugins.qbrz.lib.i18n import gettext |
| 34 |
from breezy.plugins.qbrz.lib.util import ( |
| 35 |
BTN_CLOSE, |
| 36 |
QBzrWindow, |
| 37 |
) |
| 38 |
|
| 39 |
|
| 40 |
class QBzrPluginsWindow(QBzrWindow): |
| 41 |
|
| 42 |
def __init__(self, parent=None): |
| 43 |
QBzrWindow.__init__(self, [], parent) |
| 44 |
self.set_title(gettext("Plugins")) |
| 45 |
self.restoreSize("plugins", (400,256)) |
| 46 |
view = self.build_view() |
| 47 |
btns = self.create_button_box(BTN_CLOSE) |
| 48 |
layout = QtWidgets.QVBoxLayout(self.centralWidget()) |
| 49 |
layout.addWidget(view) |
| 50 |
layout.addWidget(btns) |
| 51 |
self.refresh_view() |
| 52 |
|
| 53 |
def build_view(self): |
| 54 |
"""Build and return the widget displaying the data.""" |
| 55 |
summary_headers = [ |
| 56 |
gettext("Name"), |
| 57 |
gettext("Version"), |
| 58 |
gettext("Description"), |
| 59 |
] |
| 60 |
locations_headers = [ |
| 61 |
gettext("Name"), |
| 62 |
gettext("Directory"), |
| 63 |
] |
| 64 |
footer = gettext("Plugins installed: %(rows)d") |
| 65 |
details = None |
| 66 |
self._summary_viewer = QBzrConditionalDataView("tree", summary_headers, footer, details) |
| 67 |
self._locations_viewer = QBzrConditionalDataView("tree", locations_headers, footer, details) |
| 68 |
tabs = QtWidgets.QTabWidget() |
| 69 |
tabs.addTab(self._summary_viewer, gettext("Summary")) |
| 70 |
tabs.addTab(self._locations_viewer, gettext("Locations")) |
| 71 |
return tabs |
| 72 |
|
| 73 |
def refresh_view(self): |
| 74 |
"""Update the data in the view.""" |
| 75 |
plugins = mod_plugin.plugins() |
| 76 |
summary_data = [] |
| 77 |
locations_data = [] |
| 78 |
for name in sorted(plugins): |
| 79 |
plugin = plugins[name] |
| 80 |
version = format_plugin_version(plugin) |
| 81 |
description = format_plugin_description(plugin) |
| 82 |
directory = osutils.dirname(plugin.path()) |
| 83 |
summary_data.append((name, version, description)) |
| 84 |
locations_data.append((name, directory)) |
| 85 |
self._summary_viewer.setData(summary_data) |
| 86 |
self._locations_viewer.setData(locations_data) |
| 87 |
|
| 88 |
|
| 89 |
def format_plugin_version(plugin): |
| 90 |
"""Return the version of a plugin as a formatted string.""" |
| 91 |
version_info = plugin.version_info() |
| 92 |
if version_info is None: |
| 93 |
result = '' |
| 94 |
else: |
| 95 |
try: |
| 96 |
result = _format_version_tuple(version_info) |
| 97 |
except (ValueError, IndexError): |
| 98 |
|
| 99 |
|
| 100 |
result = ".".join([str(part) for part in version_info]) |
| 101 |
return result |
| 102 |
|
| 103 |
|
| 104 |
def format_plugin_description(plugin): |
| 105 |
d = getdoc(plugin.module) |
| 106 |
if d: |
| 107 |
doc = d.split('\n')[0] |
| 108 |
else: |
| 109 |
doc = gettext('(no description)') |
| 110 |
return doc |