/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
298.2.1 by Daniel Schierbeck
Refactored the GTK window code, creating a single base window class that handles keyboard events.
17
from bzrlib.plugins.gtk.window import Window
1 by Scott James Remnant
Commit the first version of bzrk.
18
from bzrlib.osutils import format_date
19
256.2.5 by Gary van der Merwe
Oops - Renamed file without changeing import lines
20
from linegraph import linegraph, same_branch
1 by Scott James Remnant
Commit the first version of bzrk.
21
from graphcell import CellRendererGraph
256.2.29 by Gary van der Merwe
Implement a TreeModel that loads revisions incrementaly.
22
from treemodel import TreeModel
303 by Daniel Schierbeck
Made basic signaling work.
23
from treeview  import TreeView
1 by Scott James Remnant
Commit the first version of bzrk.
24
298.2.1 by Daniel Schierbeck
Refactored the GTK window code, creating a single base window class that handles keyboard events.
25
class BranchWindow(Window):
1 by Scott James Remnant
Commit the first version of bzrk.
26
    """Branch window.
27
28
    This object represents and manages a single window containing information
29
    for a particular branch.
30
    """
31
315 by Daniel Schierbeck
Removed BranchWindow.set_branch(), used constructor instead.
32
    def __init__(self, branch, start, maxnum, parent=None):
298.2.1 by Daniel Schierbeck
Refactored the GTK window code, creating a single base window class that handles keyboard events.
33
        Window.__init__(self, parent=parent)
1 by Scott James Remnant
Commit the first version of bzrk.
34
        self.set_border_width(0)
315 by Daniel Schierbeck
Removed BranchWindow.set_branch(), used constructor instead.
35
36
        self.branch = branch
37
        self.start  = start
38
        self.maxnum = maxnum
39
40
        self.set_title(branch.nick + " - revision history")
1 by Scott James Remnant
Commit the first version of bzrk.
41
42
        # Use three-quarters of the screen by default
43
        screen = self.get_screen()
4 by Scott James Remnant
Use the size of the first monitor rather than the entire screen
44
        monitor = screen.get_monitor_geometry(0)
45
        width = int(monitor.width * 0.75)
46
        height = int(monitor.height * 0.75)
1 by Scott James Remnant
Commit the first version of bzrk.
47
        self.set_default_size(width, height)
48
49
        # FIXME AndyFitz!
50
        icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
51
        self.set_icon(icon)
52
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
53
        self.accel_group = gtk.AccelGroup()
54
        self.add_accel_group(self.accel_group)
55
1 by Scott James Remnant
Commit the first version of bzrk.
56
        self.construct()
57
58
    def construct(self):
59
        """Construct the window contents."""
44 by David Allouche
reorganise branch window
60
        vbox = gtk.VBox(spacing=0)
61
        self.add(vbox)
62
63
        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.
64
        vbox.pack_start(self.construct_loading_msg(), expand=False, fill=True)
65
        
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
66
        paned = gtk.VPaned()
67
        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,
68
        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
69
        paned.show()
44 by David Allouche
reorganise branch window
70
        vbox.pack_start(paned, expand=True, fill=True)
71
        vbox.set_focus_child(paned)
72
73
        vbox.show()
280.2.1 by Gary van der Merwe
Add a message to the viz window to indicate that graph is still loading.
74
    
75
    def construct_loading_msg(self):
76
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
77
                                                 gtk.ICON_SIZE_BUTTON)
78
        image_loading.show()
79
        
80
        label_loading = gtk.Label(_("Please wait, loading ancestral graph..."))
81
        label_loading.set_alignment(0.0, 0.5)        
82
        label_loading.show()
83
        
84
        self.loading_msg_box = gtk.HBox()
85
        self.loading_msg_box.set_spacing(5)
86
        self.loading_msg_box.set_border_width(5)        
87
        self.loading_msg_box.pack_start(image_loading, False, False)
88
        self.loading_msg_box.pack_start(label_loading, True, True)
89
        self.loading_msg_box.show()
90
        
91
        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
92
93
    def construct_top(self):
94
        """Construct the top-half of the window."""
316 by Daniel Schierbeck
Removed viz.TreeView.set_branch()
95
        self.treeview = TreeView(self.branch, self.start, self.maxnum)
315 by Daniel Schierbeck
Removed BranchWindow.set_branch(), used constructor instead.
96
310 by Daniel Schierbeck
Moved to using custom signal for handling revision selections.
97
        self.treeview.connect("revision-selected",
303 by Daniel Schierbeck
Made basic signaling work.
98
                self._treeselection_changed_cb)
99
307 by Daniel Schierbeck
Made load notification work again.
100
        self.treeview.connect('revisions-loaded', 
101
                lambda x: self.loading_msg_box.hide())
102
1 by Scott James Remnant
Commit the first version of bzrk.
103
        self.treeview.show()
104
303 by Daniel Schierbeck
Made basic signaling work.
105
        return self.treeview
44 by David Allouche
reorganise branch window
106
107
    def construct_navigation(self):
108
        """Construct the navigation buttons."""
109
        frame = gtk.Frame()
110
        frame.set_shadow_type(gtk.SHADOW_OUT)
111
        frame.show()
112
        
113
        hbox = gtk.HBox(spacing=12)
114
        frame.add(hbox)
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
115
        hbox.show()
116
117
        self.back_button = gtk.Button(stock=gtk.STOCK_GO_BACK)
44 by David Allouche
reorganise branch window
118
        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
119
        self.back_button.add_accelerator("clicked", self.accel_group, ord('['),
120
                                         0, 0)
121
        self.back_button.connect("clicked", self._back_clicked_cb)
122
        hbox.pack_start(self.back_button, expand=False, fill=True)
123
        self.back_button.show()
124
125
        self.fwd_button = gtk.Button(stock=gtk.STOCK_GO_FORWARD)
44 by David Allouche
reorganise branch window
126
        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
127
        self.fwd_button.add_accelerator("clicked", self.accel_group, ord(']'),
128
                                        0, 0)
129
        self.fwd_button.connect("clicked", self._fwd_clicked_cb)
130
        hbox.pack_start(self.fwd_button, expand=False, fill=True)
131
        self.fwd_button.show()
132
44 by David Allouche
reorganise branch window
133
        return frame
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
134
135
    def construct_bottom(self):
136
        """Construct the bottom half of the window."""
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
137
        from bzrlib.plugins.gtk.logview import LogView
256.2.23 by Gary van der Merwe
Show Children
138
        self.logview = LogView(None, True, [], True)
44 by David Allouche
reorganise branch window
139
        (width, height) = self.get_size()
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
140
        self.logview.set_size_request(width, int(height / 2.5))
141
        self.logview.show()
142
        self.logview.set_show_callback(self._show_clicked_cb)
143
        self.logview.set_go_callback(self._go_clicked_cb)
144
        return self.logview
265.1.1 by Gary van der Merwe
Show bzr viz interface quickly.
145
    
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)
146
    def _treeselection_changed_cb(self, selection, *args):
303 by Daniel Schierbeck
Made basic signaling work.
147
        """callback for when the treeview changes."""
148
        revision = self.treeview.get_revision()
149
        parents  = self.treeview.get_parents()
150
        children = self.treeview.get_children()
151
152
        if revision is not None:
256.2.62 by Gary van der Merwe
Merge Trunk.
153
            self.back_button.set_sensitive(len(parents) > 0)
154
            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)
155
            tags = []
156
            if self.branch.supports_tags():
157
                tagdict = self.branch.tags.get_reverse_tag_dict()
158
                if tagdict.has_key(revision.revision_id):
159
                    tags = tagdict[revision.revision_id]
256.2.62 by Gary van der Merwe
Merge Trunk.
160
            self.logview.set_revision(revision, tags, children)
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
161
3 by Scott James Remnant
Split the display in two with a pane, we'll use the bottom half to show
162
    def _back_clicked_cb(self, *args):
163
        """Callback for when the back button is clicked."""
304 by Daniel Schierbeck
Made forward/back buttons work again.
164
        self.treeview.back()
165
        
5 by Scott James Remnant
Reverse the meaning of the Back and Forward buttons so Back actually
166
    def _fwd_clicked_cb(self, *args):
167
        """Callback for when the forward button is clicked."""
304 by Daniel Schierbeck
Made forward/back buttons work again.
168
        self.treeview.forward()
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
169
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
170
    def _go_clicked_cb(self, revid):
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
171
        """Callback for when the go button for a parent is clicked."""
305 by Daniel Schierbeck
Moved revision selection to the new view.
172
        self.treeview.set_revision(revid)
152 by Jelmer Vernooij
Cleanup some more code.
173
147 by Jelmer Vernooij
Remove a bunch of duplicate functionality.
174
    def _show_clicked_cb(self, revid, parentid):
7 by Scott James Remnant
Put some information about the highlighted revision in the bottom pane,
175
        """Callback for when the show button for a parent is clicked."""
308 by Daniel Schierbeck
Made Show Diff work again.
176
        self.treeview.show_diff(self.branch, revid, parentid)
13 by Scott James Remnant
Keep the focus on the treeview
177
        self.treeview.grab_focus()
46 by Wouter van Heyst
show diff on row activation, LP# 44591
178