/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
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
195.1.23 by Szilveszter Farkas (Phanatic)
Make the Revision Browser feel faster.
17
import time
18
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
19
try:
20
    import pygtk
21
    pygtk.require("2.0")
22
except:
23
    pass
24
25
import gobject
26
import gtk
27
28
from bzrlib.osutils import format_date
29
30
31
class RevisionBrowser(gtk.Dialog):
32
    """ Revision Browser main window. """
33
    def __init__(self, branch, parent=None):
34
        gtk.Dialog.__init__(self, title="Revision Browser - Olive",
35
                                  parent=parent,
36
                                  flags=gtk.DIALOG_MODAL,
37
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
38
    
39
        # Get arguments
40
        self.branch = branch
41
        
42
        # Create the widgets
195.1.23 by Szilveszter Farkas (Phanatic)
Make the Revision Browser feel faster.
43
        self._hbox = gtk.HBox()
44
        self._image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH, gtk.ICON_SIZE_BUTTON)
45
        self._label_loading = gtk.Label(_("Please wait, revisions are being loaded..."))
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
46
        self._scrolledwindow = gtk.ScrolledWindow()
47
        self._treeview = gtk.TreeView()
48
        self._button_select = gtk.Button(_("_Select"), use_underline=True)
49
        
50
        # Set callbacks
51
        self._button_select.connect('clicked', self._on_select_clicked)
52
        self._treeview.connect('row-activated', self._on_treeview_row_activated)
53
        
54
        # Set properties
55
        self._scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC,
56
                                        gtk.POLICY_AUTOMATIC)
57
        self.vbox.set_spacing(3)
58
        self.set_default_size(600, 400)
195.1.23 by Szilveszter Farkas (Phanatic)
Make the Revision Browser feel faster.
59
        self._label_loading.set_alignment(0.0, 0.5)
60
        self._hbox.set_spacing(5)
61
        self._hbox.set_border_width(5)
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
62
        
63
        # Construct the TreeView columns
64
        self._treeview.append_column(gtk.TreeViewColumn(_('Revno'),
65
                                     gtk.CellRendererText(), text=0))
66
        self._treeview.append_column(gtk.TreeViewColumn(_('Summary'),
67
                                     gtk.CellRendererText(), text=1))
68
        self._treeview.append_column(gtk.TreeViewColumn(_('Committer'),
69
                                     gtk.CellRendererText(), text=2))
70
        self._treeview.append_column(gtk.TreeViewColumn(_('Time'),
71
                                     gtk.CellRendererText(), text=3))
72
        self._treeview.get_column(1).get_cell_renderers()[0].set_property("width-chars", 40)
73
        self._treeview.get_column(2).get_cell_renderers()[0].set_property("width-chars", 40)
74
        self._treeview.get_column(3).get_cell_renderers()[0].set_property("width-chars", 40)
75
        
76
        # Construct the dialog
77
        self.action_area.pack_end(self._button_select)
78
        
79
        self._scrolledwindow.add(self._treeview)
80
        
195.1.23 by Szilveszter Farkas (Phanatic)
Make the Revision Browser feel faster.
81
        self._hbox.pack_start(self._image_loading, False, False)
82
        self._hbox.pack_start(self._label_loading, True, True)
83
        
84
        self.vbox.pack_start(self._hbox, False, False)
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
85
        self.vbox.pack_start(self._scrolledwindow, True, True)
195.1.23 by Szilveszter Farkas (Phanatic)
Make the Revision Browser feel faster.
86
87
        # Show the dialog
88
        self.show_all()
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
89
        
90
        # Fill up with revisions
91
        self._fill_revisions()
92
93
    def _fill_revisions(self):
94
        """ Fill up the treeview with the revisions. """
190.1.5 by Szilveszter Farkas (Phanatic)
Revision Browser now provides revision ID.
95
        # [ revno, message, committer, timestamp, revid ]
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
96
        self.model = gtk.ListStore(gobject.TYPE_STRING,
97
                                   gobject.TYPE_STRING,
98
                                   gobject.TYPE_STRING,
190.1.5 by Szilveszter Farkas (Phanatic)
Revision Browser now provides revision ID.
99
                                   gobject.TYPE_STRING,
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
100
                                   gobject.TYPE_STRING)
101
        self._treeview.set_model(self.model)
195.1.23 by Szilveszter Farkas (Phanatic)
Make the Revision Browser feel faster.
102
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
103
        repo = self.branch.repository
104
        revs = self.branch.revision_history()
105
        r = repo.get_revisions(revs)
106
        r.reverse()
195.1.23 by Szilveszter Farkas (Phanatic)
Make the Revision Browser feel faster.
107
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
108
        for rev in r:
109
            if rev.committer is not None:
110
                timestamp = format_date(rev.timestamp, rev.timezone)
111
            else:
112
                timestamp = None
113
            self.model.append([ self.branch.revision_id_to_revno(rev.revision_id),
114
                                rev.get_summary(),
115
                                rev.committer,
190.1.5 by Szilveszter Farkas (Phanatic)
Revision Browser now provides revision ID.
116
                                timestamp,
117
                                rev.revision_id ])
195.1.23 by Szilveszter Farkas (Phanatic)
Make the Revision Browser feel faster.
118
            while gtk.events_pending():
119
                gtk.main_iteration()
120
        tend = time.time()
121
        
122
        # Finished loading
123
        self._hbox.hide()
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
124
    
125
    def _get_selected_revno(self):
126
        """ Return the selected revision's revno. """
127
        treeselection = self._treeview.get_selection()
128
        (model, iter) = treeselection.get_selected()
129
        
130
        if iter is None:
131
            return None
132
        else:
133
            return model.get_value(iter, 0)
134
    
190.1.5 by Szilveszter Farkas (Phanatic)
Revision Browser now provides revision ID.
135
    def _get_selected_revid(self):
136
        """ Return the selected revision's revid. """
137
        treeselection = self._treeview.get_selection()
138
        (model, iter) = treeselection.get_selected()
139
        
140
        if iter is None:
141
            return None
142
        else:
143
            return model.get_value(iter, 4)
144
    
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
145
    def _on_treeview_row_activated(self, treeview, path, column):
146
        """ Double-click on a row should also select a revision. """
147
        self._on_select_clicked(treeview)
148
    
149
    def _on_select_clicked(self, widget):
150
        """ Select button clicked handler. """
151
        self.selected_revno = self._get_selected_revno()
190.1.5 by Szilveszter Farkas (Phanatic)
Revision Browser now provides revision ID.
152
        self.selected_revid = self._get_selected_revid()
126.1.17 by Szilveszter Farkas (Phanatic)
Forgot to add the Revision Browser.
153
        self.response(gtk.RESPONSE_OK)