/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to viz/branchwin.py

  • Committer: John Arbash Meinel
  • Date: 2007-10-30 21:15:13 UTC
  • mfrom: (326 trunk)
  • mto: (330.3.3 trunk)
  • mto: This revision was merged to the branch mainline in revision 368.
  • Revision ID: john@arbash-meinel.com-20071030211513-l8ukdfa81g1y74mi
Merge the latest trunk 326

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
15
import treemodel
 
16
 
 
17
from bzrlib.plugins.gtk.window import Window
 
18
from bzrlib.osutils import format_date
 
19
 
 
20
from linegraph import linegraph, same_branch
 
21
from graphcell import CellRendererGraph
 
22
from treemodel import TreeModel
 
23
from treeview  import TreeView
 
24
 
 
25
class BranchWindow(Window):
 
26
    """Branch window.
 
27
 
 
28
    This object represents and manages a single window containing information
 
29
    for a particular branch.
 
30
    """
 
31
 
 
32
    def __init__(self, branch, start, maxnum, parent=None):
 
33
        """Create a new BranchWindow.
 
34
 
 
35
        :param branch: Branch object for branch to show.
 
36
        :param start: Revision id of top revision.
 
37
        :param maxnum: Maximum number of revisions to display, 
 
38
                       None for no limit.
 
39
        """
 
40
 
 
41
        Window.__init__(self, parent=parent)
 
42
        self.set_border_width(0)
 
43
 
 
44
        self.branch = branch
 
45
        self.start  = start
 
46
        self.maxnum = maxnum
 
47
 
 
48
        self.set_title(branch.nick + " - revision history")
 
49
 
 
50
        # Use three-quarters of the screen by default
 
51
        screen = self.get_screen()
 
52
        monitor = screen.get_monitor_geometry(0)
 
53
        width = int(monitor.width * 0.75)
 
54
        height = int(monitor.height * 0.75)
 
55
        self.set_default_size(width, height)
 
56
 
 
57
        # FIXME AndyFitz!
 
58
        icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
 
59
        self.set_icon(icon)
 
60
 
 
61
        self.accel_group = gtk.AccelGroup()
 
62
        self.add_accel_group(self.accel_group)
 
63
 
 
64
        self.construct()
 
65
 
 
66
    def construct(self):
 
67
        """Construct the window contents."""
 
68
        vbox = gtk.VBox(spacing=0)
 
69
        self.add(vbox)
 
70
 
 
71
        vbox.pack_start(self.construct_navigation(), expand=False, fill=True)
 
72
        vbox.pack_start(self.construct_loading_msg(), expand=False, fill=True)
 
73
        
 
74
        paned = gtk.VPaned()
 
75
        paned.pack1(self.construct_top(), resize=True, shrink=False)
 
76
        paned.pack2(self.construct_bottom(), resize=False, shrink=True)
 
77
        paned.show()
 
78
        vbox.pack_start(paned, expand=True, fill=True)
 
79
        vbox.set_focus_child(paned)
 
80
 
 
81
        vbox.show()
 
82
    
 
83
    def construct_loading_msg(self):
 
84
        image_loading = gtk.image_new_from_stock(gtk.STOCK_REFRESH,
 
85
                                                 gtk.ICON_SIZE_BUTTON)
 
86
        image_loading.show()
 
87
        
 
88
        label_loading = gtk.Label(_("Please wait, loading ancestral graph..."))
 
89
        label_loading.set_alignment(0.0, 0.5)        
 
90
        label_loading.show()
 
91
        
 
92
        self.loading_msg_box = gtk.HBox()
 
93
        self.loading_msg_box.set_spacing(5)
 
94
        self.loading_msg_box.set_border_width(5)        
 
95
        self.loading_msg_box.pack_start(image_loading, False, False)
 
96
        self.loading_msg_box.pack_start(label_loading, True, True)
 
97
        self.loading_msg_box.show()
 
98
        
 
99
        return self.loading_msg_box
 
100
 
 
101
    def construct_top(self):
 
102
        """Construct the top-half of the window."""
 
103
        self.treeview = TreeView(self.branch, self.start, self.maxnum)
 
104
 
 
105
        self.treeview.connect("revision-selected",
 
106
                self._treeselection_changed_cb)
 
107
 
 
108
        self.treeview.connect('revisions-loaded', 
 
109
                lambda x: self.loading_msg_box.hide())
 
110
 
 
111
        self.treeview.show()
 
112
 
 
113
        return self.treeview
 
114
 
 
115
    def construct_navigation(self):
 
116
        """Construct the navigation buttons."""
 
117
        self.toolbar = gtk.Toolbar()
 
118
        self.toolbar.set_style(gtk.TOOLBAR_BOTH_HORIZ)
 
119
 
 
120
        self.back_button = gtk.ToolButton(stock_id=gtk.STOCK_GO_BACK)
 
121
        self.back_button.set_is_important(True)
 
122
        self.back_button.add_accelerator("clicked", self.accel_group, ord('['),
 
123
                                         0, 0)
 
124
        self.back_button.connect("clicked", self._back_clicked_cb)
 
125
        self.toolbar.insert(self.back_button, -1)
 
126
        self.back_button.show()
 
127
 
 
128
        self.fwd_button = gtk.ToolButton(stock_id=gtk.STOCK_GO_FORWARD)
 
129
        self.fwd_button.set_is_important(True)
 
130
        self.fwd_button.add_accelerator("clicked", self.accel_group, ord(']'),
 
131
                                        0, 0)
 
132
        self.fwd_button.connect("clicked", self._fwd_clicked_cb)
 
133
        self.toolbar.insert(self.fwd_button, -1)
 
134
        self.fwd_button.show()
 
135
 
 
136
        self.toolbar.show()
 
137
 
 
138
        return self.toolbar
 
139
 
 
140
    def construct_bottom(self):
 
141
        """Construct the bottom half of the window."""
 
142
        from bzrlib.plugins.gtk.logview import LogView
 
143
        self.logview = LogView(None, True, [], True)
 
144
        (width, height) = self.get_size()
 
145
        self.logview.set_size_request(width, int(height / 2.5))
 
146
        self.logview.show()
 
147
        self.logview.set_show_callback(self._show_clicked_cb)
 
148
        self.logview.set_go_callback(self._go_clicked_cb)
 
149
        return self.logview
 
150
    
 
151
    def _treeselection_changed_cb(self, selection, *args):
 
152
        """callback for when the treeview changes."""
 
153
        revision = self.treeview.get_revision()
 
154
        parents  = self.treeview.get_parents()
 
155
        children = self.treeview.get_children()
 
156
 
 
157
        if revision is not None:
 
158
            self.back_button.set_sensitive(len(parents) > 0)
 
159
            self.fwd_button.set_sensitive(len(children) > 0)
 
160
            tags = []
 
161
            if self.branch.supports_tags():
 
162
                tagdict = self.branch.tags.get_reverse_tag_dict()
 
163
                if tagdict.has_key(revision.revision_id):
 
164
                    tags = tagdict[revision.revision_id]
 
165
            self.logview.set_revision(revision, tags, children)
 
166
 
 
167
    def _back_clicked_cb(self, *args):
 
168
        """Callback for when the back button is clicked."""
 
169
        self.treeview.back()
 
170
        
 
171
    def _fwd_clicked_cb(self, *args):
 
172
        """Callback for when the forward button is clicked."""
 
173
        self.treeview.forward()
 
174
 
 
175
    def _go_clicked_cb(self, revid):
 
176
        """Callback for when the go button for a parent is clicked."""
 
177
        self.treeview.set_revision(revid)
 
178
 
 
179
    def _show_clicked_cb(self, revid, parentid):
 
180
        """Callback for when the show button for a parent is clicked."""
 
181
        self.treeview.show_diff(self.branch, revid, parentid)
 
182
        self.treeview.grab_focus()
 
183