1
# -*- coding: utf-8 -*-
3
# QBzr - Qt frontend to Bazaar commands
4
# Copyright (C) 2009 Canonical Ltd
6
# This program is free software; you can redistribute it and/or
7
# modify it under the terms of the GNU General Public License
8
# as published by the Free Software Foundation; either version 2
9
# of the License, or (at your option) any later version.
11
# This program is distributed in the hope that it will be useful,
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
# GNU General Public License for more details.
16
# You should have received a copy of the GNU General Public License
17
# along with this program; if not, write to the Free Software
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
from inspect import getdoc
22
from PyQt4 import QtCore, QtGui
25
_format_version_tuple,
30
from bzrlib.plugins.qbzr.lib.conditional_dataview import (
31
QBzrConditionalDataView,
33
from bzrlib.plugins.qbzr.lib.i18n import gettext
34
from bzrlib.plugins.qbzr.lib.util import (
40
class QBzrPluginsWindow(QBzrWindow):
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 = QtGui.QVBoxLayout(self.centralWidget())
49
layout.addWidget(view)
50
layout.addWidget(btns)
54
"""Build and return the widget displaying the data."""
58
gettext("Description"),
64
footer = gettext("Plugins installed: %(rows)d")
66
self._summary_viewer = QBzrConditionalDataView("tree",
67
summary_headers, footer, details)
68
self._locations_viewer = QBzrConditionalDataView("tree",
69
locations_headers, footer, details)
70
tabs = QtGui.QTabWidget()
71
tabs.addTab(self._summary_viewer, gettext("Summary"))
72
tabs.addTab(self._locations_viewer, gettext("Locations"))
75
def refresh_view(self):
76
"""Update the data in the view."""
77
plugins = mod_plugin.plugins()
80
for name in sorted(plugins):
81
plugin = plugins[name]
82
version = format_plugin_version(plugin)
83
description = format_plugin_description(plugin)
84
directory = osutils.dirname(plugin.path())
85
summary_data.append((name, version, description))
86
locations_data.append((name, directory))
87
self._summary_viewer.setData(summary_data)
88
self._locations_viewer.setData(locations_data)
91
def format_plugin_version(plugin):
92
"""Return the version of a plugin as a formatted string."""
93
version_info = plugin.version_info()
94
if version_info is None:
98
result = _format_version_tuple(version_info)
100
# Version info fails the expected rules.
101
# Format it nicely anyhow.
102
result = ".".join([str(part) for part in version_info])
106
def format_plugin_description(plugin):
107
d = getdoc(plugin.module)
109
doc = d.split('\n')[0]
111
doc = gettext('(no description)')