/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
1 by Scott James Remnant
Commit the first version of bzrk.
1
# -*- coding: UTF-8 -*-
2
"""Branch window.
3
4
This module contains the code to manage the branch information window,
5
which contains both the revision graph and details panes.
6
"""
7
8
__copyright__ = "Copyright © 2005 Canonical Ltd."
9
__author__    = "Scott James Remnant <scott@ubuntu.com>"
10
11
12
import gtk
13
import gobject
14
import pango
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
15
import treemodel
1 by Scott James Remnant
Commit the first version of bzrk.
16
17
from bzrlib.osutils import format_date
18
256.2.5 by Gary van der Merwe
Oops - Renamed file without changeing import lines
19
from linegraph import linegraph, same_branch
1 by Scott James Remnant
Commit the first version of bzrk.
20
from graphcell import CellRendererGraph
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
21
from treemodel import TreeModel
303 by Daniel Schierbeck
Made basic signaling work.
22
from treeview  import TreeView
1 by Scott James Remnant
Commit the first version of bzrk.
23
24
class BranchWindow(gtk.Window):
25
    """Branch window.
26
27
    This object represents and manages a single window containing information
28
    for a particular branch.
29
    """
30
275.1.6 by Daniel Schierbeck
Made Ctrl-W call gtk.main_quit if the window has no parent.
31
    def __init__(self, parent=None):
1 by Scott James Remnant
Commit the first version of bzrk.
32
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
33
        self.set_border_width(0)
292.2.1 by Daniel Schierbeck
Changed title of the viz window to 'revision history'
34
        self.set_title("Revision history")
1 by Scott James Remnant
Commit the first version of bzrk.
35
275.1.6 by Daniel Schierbeck
Made Ctrl-W call gtk.main_quit if the window has no parent.
36
        self._parent = parent
37
38
        self.connect('key-press-event', self._on_key_pressed)
275.1.1 by Daniel Schierbeck
Close branch visualization window when 'destroy' message is received.
39
1 by Scott James Remnant
Commit the first version of bzrk.
40
        # Use three-quarters of the screen by default
41
        screen = self.get_screen()
4 by Scott James Remnant
Use the size of the first monitor rather than the entire screen
42
        monitor = screen.get_monitor_geometry(0)
43
        width = int(monitor.width * 0.75)
44
        height = int(monitor.height * 0.75)
1 by Scott James Remnant
Commit the first version of bzrk.
45
        self.set_default_size(width, height)
46
47
        # FIXME AndyFitz!
48
        icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
49
        self.set_icon(icon)
50
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
51
        self.accel_group = gtk.AccelGroup()
52
        self.add_accel_group(self.accel_group)
53
1 by Scott James Remnant
Commit the first version of bzrk.
54
        self.construct()
55
56
    def construct(self):
57
        """Construct the window contents."""
44 by David Allouche
reorganise branch window
58
        vbox = gtk.VBox(spacing=0)
59
        self.add(vbox)
60
61
        vbox.pack_start(self.construct_navigation(), expand=False, fill=True)
280.2.1 by Gary van der Merwe
Add a message to the viz window to indicate that graph is still loading.
62
        vbox.pack_start(self.construct_loading_msg(), expand=False, fill=True)
63
        
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
64
        paned = gtk.VPaned()
65
        paned.pack1(self.construct_top(), resize=True, shrink=False)
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
66
        paned.pack2(self.construct_bottom(), resize=False, shrink=True)
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
67
        paned.show()
44 by David Allouche
reorganise branch window
68
        vbox.pack_start(paned, expand=True, fill=True)
69
        vbox.set_focus_child(paned)
70
71
        vbox.show()
280.2.1 by Gary van der Merwe
Add a message to the viz window to indicate that graph is still loading.
72
    
73
    def construct_loading_msg(self):
74
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
75
                                                 gtk.ICON_SIZE_BUTTON)
76
        image_loading.show()
77
        
78
        label_loading = gtk.Label(_("Please wait, loading ancestral graph..."))
79
        label_loading.set_alignment(0.0, 0.5)        
80
        label_loading.show()
81
        
82
        self.loading_msg_box = gtk.HBox()
83
        self.loading_msg_box.set_spacing(5)
84
        self.loading_msg_box.set_border_width(5)        
85
        self.loading_msg_box.pack_start(image_loading, False, False)
86
        self.loading_msg_box.pack_start(label_loading, True, True)
87
        self.loading_msg_box.show()
88
        
89
        return self.loading_msg_box
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
90
91
    def construct_top(self):
92
        """Construct the top-half of the window."""
303 by Daniel Schierbeck
Made basic signaling work.
93
        self.treeview = TreeView()
94
310 by Daniel Schierbeck
Moved to using custom signal for handling revision selections.
95
        self.treeview.connect("revision-selected",
303 by Daniel Schierbeck
Made basic signaling work.
96
                self._treeselection_changed_cb)
97
307 by Daniel Schierbeck
Made load notification work again.
98
        self.treeview.connect('revisions-loaded', 
99
                lambda x: self.loading_msg_box.hide())
100
1 by Scott James Remnant
Commit the first version of bzrk.
101
        self.treeview.show()
102
303 by Daniel Schierbeck
Made basic signaling work.
103
        return self.treeview
44 by David Allouche
reorganise branch window
104
105
    def construct_navigation(self):
106
        """Construct the navigation buttons."""
107
        frame = gtk.Frame()
108
        frame.set_shadow_type(gtk.SHADOW_OUT)
109
        frame.show()
110
        
111
        hbox = gtk.HBox(spacing=12)
112
        frame.add(hbox)
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
113
        hbox.show()
114
115
        self.back_button = gtk.Button(stock=gtk.STOCK_GO_BACK)
44 by David Allouche
reorganise branch window
116
        self.back_button.set_relief(gtk.RELIEF_NONE)
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
117
        self.back_button.add_accelerator("clicked", self.accel_group, ord('['),
118
                                         0, 0)
119
        self.back_button.connect("clicked", self._back_clicked_cb)
120
        hbox.pack_start(self.back_button, expand=False, fill=True)
121
        self.back_button.show()
122
123
        self.fwd_button = gtk.Button(stock=gtk.STOCK_GO_FORWARD)
44 by David Allouche
reorganise branch window
124
        self.fwd_button.set_relief(gtk.RELIEF_NONE)
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
125
        self.fwd_button.add_accelerator("clicked", self.accel_group, ord(']'),
126
                                        0, 0)
127
        self.fwd_button.connect("clicked", self._fwd_clicked_cb)
128
        hbox.pack_start(self.fwd_button, expand=False, fill=True)
129
        self.fwd_button.show()
130
44 by David Allouche
reorganise branch window
131
        return frame
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
132
133
    def construct_bottom(self):
134
        """Construct the bottom half of the window."""
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
135
        from bzrlib.plugins.gtk.logview import LogView
256.2.23 by Gary van der Merwe
Show Children
136
        self.logview = LogView(None, True, [], True)
44 by David Allouche
reorganise branch window
137
        (width, height) = self.get_size()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
138
        self.logview.set_size_request(width, int(height / 2.5))
139
        self.logview.show()
140
        self.logview.set_show_callback(self._show_clicked_cb)
141
        self.logview.set_go_callback(self._go_clicked_cb)
142
        return self.logview
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
143
40 by David Allouche
remove --robust, pyflakes fixes, update README
144
    def set_branch(self, branch, start, maxnum):
1 by Scott James Remnant
Commit the first version of bzrk.
145
        """Set the branch and start position for this window.
146
147
        Creates a new TreeModel and populates it with information about
148
        the new branch before updating the window title and model of the
149
        treeview itself.
150
        """
10 by Scott James Remnant
Add an extra window type, clicking the little icons next to a parent
151
        self.branch = branch
292.2.1 by Daniel Schierbeck
Changed title of the viz window to 'revision history'
152
        self.set_title(branch.nick + " - revision history")
303 by Daniel Schierbeck
Made basic signaling work.
153
        self.treeview.set_branch(branch, start, maxnum)
265.1.1 by Gary van der Merwe
Show bzr viz interface quickly.
154
    
275.1.5 by Daniel Schierbeck
Made windows close correctly on Ctrl-W and made the application quit on Ctrl-Q.
155
    def _on_key_pressed(self, widget, event):
156
        """ Key press event handler. """
157
        keyname = gtk.gdk.keyval_name(event.keyval)
158
        func = getattr(self, '_on_key_press_' + keyname, None)
159
        if func:
160
            return func(event)
161
162
    def _on_key_press_w(self, event):
163
        if event.state & gtk.gdk.CONTROL_MASK:
164
            self.destroy()
275.1.6 by Daniel Schierbeck
Made Ctrl-W call gtk.main_quit if the window has no parent.
165
            if self._parent is None:
166
                gtk.main_quit()
275.1.5 by Daniel Schierbeck
Made windows close correctly on Ctrl-W and made the application quit on Ctrl-Q.
167
168
    def _on_key_press_q(self, event):
169
        if event.state & gtk.gdk.CONTROL_MASK:
170
            gtk.main_quit()
265.1.1 by Gary van der Merwe
Show bzr viz interface quickly.
171
    
280.1.2 by Daniel Schierbeck
Switched to handle the 'changed' signal from the treeview's treeselection instead of the 'cursor-changed' signal from the treeview itself, allowing more flexibility (particularly the ability to handle programmatic selections)
172
    def _treeselection_changed_cb(self, selection, *args):
303 by Daniel Schierbeck
Made basic signaling work.
173
        """callback for when the treeview changes."""
174
        revision = self.treeview.get_revision()
175
        parents  = self.treeview.get_parents()
176
        children = self.treeview.get_children()
177
178
        if revision is not None:
256.2.62 by Gary van der Merwe
Merge Trunk.
179
            self.back_button.set_sensitive(len(parents) > 0)
180
            self.fwd_button.set_sensitive(len(children) > 0)
280.1.2 by Daniel Schierbeck
Switched to handle the 'changed' signal from the treeview's treeselection instead of the 'cursor-changed' signal from the treeview itself, allowing more flexibility (particularly the ability to handle programmatic selections)
181
            tags = []
182
            if self.branch.supports_tags():
183
                tagdict = self.branch.tags.get_reverse_tag_dict()
184
                if tagdict.has_key(revision.revision_id):
185
                    tags = tagdict[revision.revision_id]
256.2.62 by Gary van der Merwe
Merge Trunk.
186
            self.logview.set_revision(revision, tags, children)
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
187
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
188
    def _back_clicked_cb(self, *args):
189
        """Callback for when the back button is clicked."""
304 by Daniel Schierbeck
Made forward/back buttons work again.
190
        self.treeview.back()
191
        
5 by Scott James Remnant
Reverse the meaning of the Back and Forward buttons so Back actually
192
    def _fwd_clicked_cb(self, *args):
193
        """Callback for when the forward button is clicked."""
304 by Daniel Schierbeck
Made forward/back buttons work again.
194
        self.treeview.forward()
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
195
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
196
    def _go_clicked_cb(self, revid):
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
197
        """Callback for when the go button for a parent is clicked."""
305 by Daniel Schierbeck
Moved revision selection to the new view.
198
        self.treeview.set_revision(revid)
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
199
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
200
    def _show_clicked_cb(self, revid, parentid):
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
201
        """Callback for when the show button for a parent is clicked."""
308 by Daniel Schierbeck
Made Show Diff work again.
202
        self.treeview.show_diff(self.branch, revid, parentid)
13 by Scott James Remnant
Keep the focus on the treeview
203
        self.treeview.grab_focus()
46 by Wouter van Heyst
show diff on row activation, LP# 44591
204