/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
171 by Jelmer Vernooij
Initial work on a preferences dialog in GTK+, including a list of plugins with metadata browser.
1
# Copyright (C) 2007 Jelmer Vernooij <jelmer@samba.org>
2
#
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
try:
18
    import pygtk
19
    pygtk.require("2.0")
20
except:
21
    pass
22
23
import gtk
24
25
from bzrlib.config import GlobalConfig
26
27
class PreferencesWindow(gtk.Dialog):
28
    """Displays global preferences windows."""
29
    def __init__(self, config=None):
30
        """ Initialize the Status window. """
31
        super(PreferencesWindow, self).__init__(flags=gtk.DIALOG_MODAL)
32
        self.set_title("Bazaar Preferences")
33
        self.config = config
34
        if self.config is None:
35
            self.config = GlobalConfig()
36
        self._create()
37
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)
42
43
        align = gtk.Alignment(1.0, 0.5)
44
        label = gtk.Label()
45
        label.set_markup("<b>User Id:</b>")
46
        align.add(label)
47
        table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
48
49
        self.username = gtk.Entry()
50
        self.username.set_text(self.config.username())
237 by Jelmer Vernooij
Some UI improvements for preferences dialog.
51
        table.attach(self.username, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
171 by Jelmer Vernooij
Initial work on a preferences dialog in GTK+, including a list of plugins with metadata browser.
52
53
        align = gtk.Alignment(1.0, 0.5)
54
        label = gtk.Label()
55
        label.set_markup("<b>GPG signing command:</b>")
56
        align.add(label)
57
        table.attach(align, 0, 1, 1, 2, gtk.FILL, gtk.FILL)
58
59
        self.email = gtk.Entry()
60
        self.email.set_text(self.config.gpg_signing_command())
237 by Jelmer Vernooij
Some UI improvements for preferences dialog.
61
        table.attach(self.email, 1, 2, 1, 2, gtk.EXPAND | gtk.FILL, gtk.FILL)
171 by Jelmer Vernooij
Initial work on a preferences dialog in GTK+, including a list of plugins with metadata browser.
62
63
        align = gtk.Alignment(1.0, 0.5)
64
        label = gtk.Label()
65
        label.set_markup("<b>Check GPG Signatures:</b>")
66
        align.add(label)
67
        table.attach(align, 0, 1, 2, 3, gtk.FILL, gtk.FILL)
68
213 by Jelmer Vernooij
Show preferences dialog from notify area icon, fix GPG display.
69
        sigvals = gtk.VBox()
70
        self.check_sigs_if_possible = gtk.RadioButton(None, 
71
                                                      "_Check if possible")
72
        sigvals.pack_start(self.check_sigs_if_possible)
73
        self.check_sigs_always = gtk.RadioButton(self.check_sigs_if_possible, 
74
                                                 "Check _always")
75
        sigvals.pack_start(self.check_sigs_always)
76
        self.check_sigs_never = gtk.RadioButton(self.check_sigs_if_possible,
77
                                                "Check _never")
215 by Jelmer Vernooij
Fix double add.
78
        sigvals.pack_start(self.check_sigs_never)
213 by Jelmer Vernooij
Show preferences dialog from notify area icon, fix GPG display.
79
        # FIXME: Set default
237 by Jelmer Vernooij
Some UI improvements for preferences dialog.
80
        table.attach(sigvals, 1, 2, 2, 3, gtk.EXPAND | gtk.FILL, gtk.FILL)
171 by Jelmer Vernooij
Initial work on a preferences dialog in GTK+, including a list of plugins with metadata browser.
81
82
        align = gtk.Alignment(1.0, 0.5)
83
        label = gtk.Label()
84
        label.set_markup("<b>Create GPG Signatures:</b>")
85
        align.add(label)
86
        table.attach(align, 0, 1, 3, 4, gtk.FILL, gtk.FILL)
87
213 by Jelmer Vernooij
Show preferences dialog from notify area icon, fix GPG display.
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)
98
        # FIXME: Set default
237 by Jelmer Vernooij
Some UI improvements for preferences dialog.
99
        table.attach(create_sigs, 1, 2, 3, 4, gtk.EXPAND | gtk.FILL, gtk.FILL)
171 by Jelmer Vernooij
Initial work on a preferences dialog in GTK+, including a list of plugins with metadata browser.
100
101
        return table
102
103
    def _create_pluginpage(self):
237 by Jelmer Vernooij
Some UI improvements for preferences dialog.
104
        paned = gtk.VPaned()
171 by Jelmer Vernooij
Initial work on a preferences dialog in GTK+, including a list of plugins with metadata browser.
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)
237 by Jelmer Vernooij
Some UI improvements for preferences dialog.
110
        paned.pack1(scrolledwindow, resize=True, shrink=False)
171 by Jelmer Vernooij
Initial work on a preferences dialog in GTK+, including a list of plugins with metadata browser.
111
112
        table = gtk.Table(columns=2)
113
        table.set_row_spacings(6)
114
        table.set_col_spacings(6)
115
116
        def row_selected(tv, path, tvc):
117
            p = bzrlib.plugin.all_plugins()[model[path][0]]
118
            from inspect import getdoc
119
120
            for w in table.get_children():
121
                table.remove(w)
122
123
            if getattr(p, '__author__', None) is not None:
124
                align = gtk.Alignment(1.0, 0.5)
125
                label = gtk.Label()
126
                label.set_markup("<b>Author:</b>")
127
                align.add(label)
128
                table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
129
                align.show()
130
                label.show()
131
132
                align = gtk.Alignment(0.0, 0.5)
133
                author = gtk.Label()
134
                author.set_text(p.__author__)
135
                author.set_selectable(True)
136
                align.add(author)
137
                table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
138
139
            if getattr(p, '__version__', None) is not None:
140
                align = gtk.Alignment(1.0, 0.5)
141
                label = gtk.Label()
142
                label.set_markup("<b>Version:</b>")
143
                align.add(label)
144
                table.attach(align, 0, 1, 0, 1, gtk.FILL, gtk.FILL)
145
                align.show()
146
                label.show()
147
148
                align = gtk.Alignment(0.0, 0.5)
149
                author = gtk.Label()
150
                author.set_text(p.__version__)
151
                author.set_selectable(True)
152
                align.add(author)
153
                table.attach(align, 1, 2, 0, 1, gtk.EXPAND | gtk.FILL, gtk.FILL)
154
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)
162
163
            table.show_all()
164
165
        treeview.set_headers_visible(False)
166
        treeview.set_model(model)
167
        treeview.connect("row-activated", row_selected)
168
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)
174
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)
180
        
181
        import bzrlib.plugin
194 by Jelmer Vernooij
Sort plugins by name.
182
        plugins = bzrlib.plugin.all_plugins()
183
        plugin_names = plugins.keys()
184
        plugin_names.sort()
185
        for name in plugin_names:
186
            model.append([name, getattr(plugins[name], '__file__', None)])
171 by Jelmer Vernooij
Initial work on a preferences dialog in GTK+, including a list of plugins with metadata browser.
187
                 
237 by Jelmer Vernooij
Some UI improvements for preferences dialog.
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)
192
        paned.show()
193
194
        return paned
171 by Jelmer Vernooij
Initial work on a preferences dialog in GTK+, including a list of plugins with metadata browser.
195
196
    def _create(self):
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)
202
        self.vbox.show_all()
203
204
    def display(self):
205
        self.window.show_all()
206
207
    def close(self, widget=None):
208
        self.window.destroy()
213 by Jelmer Vernooij
Show preferences dialog from notify area icon, fix GPG display.
209
210
class BranchPreferencesWindow(gtk.Dialog):
211
    """Displays global preferences windows."""
212
    def __init__(self, config=None):
213
        super(BranchPreferencesWindow, self).__init__(config)
214