14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from gi.repository import Gtk
19
25
from bzrlib.config import GlobalConfig
20
from bzrlib.plugins.gtk.preferences.identity import IdentityPage
21
from bzrlib.plugins.gtk.preferences.plugins import PluginsPage
22
from bzrlib.plugins.gtk.preferences.notifications import NotificationsPage
24
class PreferencesWindow(Gtk.Dialog):
27
class PreferencesWindow(gtk.Dialog):
25
28
"""Displays global preferences windows."""
26
# Note that we don't allow configuration of aliases or
27
# default log formats. This is because doing so wouldn't make
28
# a lot of sense to pure GUI users. Users that need these settings
29
# will already be familiar with the configuration file.
31
29
def __init__(self, config=None):
32
30
""" Initialize the Status window. """
33
super(PreferencesWindow, self).__init__(flags=Gtk.DialogFlags.MODAL)
31
super(PreferencesWindow, self).__init__(flags=gtk.DIALOG_MODAL)
34
32
self.set_title("Bazaar Preferences")
35
33
self.config = config
36
34
if self.config is None:
37
35
self.config = GlobalConfig()
38
def _create_mainpage(self):
39
table = gtk.Table(rows=4, columns=2)
40
table.set_row_spacings(6)
41
table.set_col_spacings(6)
43
align = gtk.Alignment(1.0, 0.5)
45
label.set_markup("<b>User Id:</b>")
47
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
49
self.username = gtk.Entry()
50
self.username.set_text(self.config.username())
51
table.attach(self.username, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
53
align = gtk.Alignment(1.0, 0.5)
55
label.set_markup("<b>GPG signing command:</b>")
57
table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
59
self.email = gtk.Entry()
60
self.email.set_text(self.config.gpg_signing_command())
61
table.attach(self.email, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
63
align = gtk.Alignment(1.0, 0.5)
65
label.set_markup("<b>Check GPG Signatures:</b>")
67
table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
70
self.check_sigs_if_possible = gtk.RadioButton(None,
72
sigvals.pack_start(self.check_sigs_if_possible)
73
self.check_sigs_always = gtk.RadioButton(self.check_sigs_if_possible,
75
sigvals.pack_start(self.check_sigs_always)
76
self.check_sigs_never = gtk.RadioButton(self.check_sigs_if_possible,
78
sigvals.pack_start(self.check_sigs_never)
80
table.attach(sigvals, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
82
align = gtk.Alignment(1.0, 0.5)
84
label.set_markup("<b>Create GPG Signatures:</b>")
86
table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
88
create_sigs = gtk.VBox()
89
self.create_sigs_when_required = gtk.RadioButton(None,
90
"Sign When _Required")
91
create_sigs.pack_start(self.create_sigs_when_required)
92
self.create_sigs_always = gtk.RadioButton(
93
self.create_sigs_when_required, "Sign _Always")
94
create_sigs.pack_start(self.create_sigs_always)
95
self.create_sigs_never = gtk.RadioButton(
96
self.create_sigs_when_required, "Sign _Never")
97
create_sigs.pack_start(self.create_sigs_never)
99
table.attach(create_sigs, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
103
def _create_pluginpage(self):
105
scrolledwindow = gtk.ScrolledWindow()
106
scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
107
model = gtk.ListStore(str, str)
108
treeview = gtk.TreeView()
109
scrolledwindow.add(treeview)
110
paned.pack1(scrolledwindow, resize=True, shrink=False)
112
table = gtk.Table(columns=2)
113
table.set_row_spacings(6)
114
table.set_col_spacings(6)
116
def row_selected(tv, path, tvc):
117
p = bzrlib.plugin.all_plugins()[model[path][0]]
118
from inspect import getdoc
120
for w in table.get_children():
123
if getattr(p, '__author__', None) is not None:
124
align = gtk.Alignment(1.0, 0.5)
126
label.set_markup("<b>Author:</b>")
128
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
132
align = gtk.Alignment(0.0, 0.5)
134
author.set_text(p.__author__)
135
author.set_selectable(True)
137
table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
139
if getattr(p, '__version__', None) is not None:
140
align = gtk.Alignment(1.0, 0.5)
142
label.set_markup("<b>Version:</b>")
144
table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
148
align = gtk.Alignment(0.0, 0.5)
150
author.set_text(p.__version__)
151
author.set_selectable(True)
153
table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
155
if getdoc(p) is not None:
156
align = gtk.Alignment(0.0, 0.5)
157
description = gtk.Label()
158
description.set_text(getdoc(p))
159
description.set_selectable(True)
160
align.add(description)
161
table.attach(align, 0, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
165
treeview.set_headers_visible(False)
166
treeview.set_model(model)
167
treeview.connect("row-activated", row_selected)
169
cell = gtk.CellRendererText()
170
column = gtk.TreeViewColumn()
171
column.pack_start(cell, expand=True)
172
column.add_attribute(cell, "text", 0)
173
treeview.append_column(column)
175
cell = gtk.CellRendererText()
176
column = gtk.TreeViewColumn()
177
column.pack_start(cell, expand=True)
178
column.add_attribute(cell, "text", 1)
179
treeview.append_column(column)
182
plugins = bzrlib.plugin.all_plugins()
183
plugin_names = plugins.keys()
185
for name in plugin_names:
186
model.append([name, getattr(plugins[name], '__file__', None)])
188
scrolledwindow = gtk.ScrolledWindow()
189
scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
190
scrolledwindow.add_with_viewport(table)
191
paned.pack2(scrolledwindow, resize=False, shrink=True)
40
196
def _create(self):
41
self.set_default_size(320, 480)
42
self.set_border_width(0)
44
notebook = Gtk.Notebook()
45
notebook.set_border_width(12)
46
for (label, page) in self._create_pages():
47
notebook.append_page(page, Gtk.Label(label=label))
49
notebook.set_current_page(0)
50
content_area = self.get_content_area()
51
content_area.set_border_width(0)
52
content_area.pack_start(notebook, True, True, 0)
53
content_area.show_all()
54
self.get_action_area().set_border_width(12)
56
def _create_pages(self):
57
return [("Identity", IdentityPage(self.config)),
58
("Plugins", PluginsPage()),
59
("Notifications", NotificationsPage(self.config))]
197
self.set_default_size(600, 600)
198
notebook = gtk.Notebook()
199
notebook.insert_page(self._create_mainpage(), gtk.Label("Main"))
200
notebook.insert_page(self._create_pluginpage(), gtk.Label("Plugins"))
201
self.vbox.pack_start(notebook, True, True)
61
204
def display(self):
62
205
self.window.show_all()