/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 branchwin.py

  • Committer: Scott James Remnant
  • Date: 2005-10-17 01:07:49 UTC
  • Revision ID: scott@netsplit.com-20051017010749-15fa95fc2cf09289
Commit the first version of bzrk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# -*- coding: UTF-8 -*-
 
3
"""Branch window.
 
4
 
 
5
This module contains the code to manage the branch information window,
 
6
which contains both the revision graph and details panes.
 
7
"""
 
8
 
 
9
__copyright__ = "Copyright © 2005 Canonical Ltd."
 
10
__author__    = "Scott James Remnant <scott@ubuntu.com>"
 
11
 
 
12
 
 
13
import os
 
14
 
 
15
import gtk
 
16
import gobject
 
17
import pango
 
18
 
 
19
from bzrlib.osutils import format_date
 
20
 
 
21
from graph import graph
 
22
from graphcell import CellRendererGraph
 
23
 
 
24
 
 
25
class BranchWindow(gtk.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):
 
33
        gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
 
34
        self.set_border_width(0)
 
35
        self.set_title("bzrk")
 
36
 
 
37
        # Use three-quarters of the screen by default
 
38
        screen = self.get_screen()
 
39
        width = int(screen.get_width() * 0.75)
 
40
        height = int(screen.get_height() * 0.75)
 
41
        self.set_default_size(width, height)
 
42
 
 
43
        # FIXME AndyFitz!
 
44
        icon = self.render_icon(gtk.STOCK_INDEX, gtk.ICON_SIZE_BUTTON)
 
45
        self.set_icon(icon)
 
46
 
 
47
        self.construct()
 
48
 
 
49
    def construct(self):
 
50
        """Construct the window contents."""
 
51
        scrollwin = gtk.ScrolledWindow()
 
52
        scrollwin.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
 
53
        scrollwin.set_shadow_type(gtk.SHADOW_IN)
 
54
        scrollwin.set_border_width(12)
 
55
        self.add(scrollwin)
 
56
        scrollwin.show()
 
57
 
 
58
        self.treeview = gtk.TreeView()
 
59
        self.treeview.set_rules_hint(True)
 
60
        self.treeview.set_search_column(4)
 
61
        scrollwin.add(self.treeview)
 
62
        self.treeview.show()
 
63
 
 
64
        cell = CellRendererGraph()
 
65
        column = gtk.TreeViewColumn()
 
66
        column.set_resizable(False)
 
67
        column.pack_start(cell, expand=False)
 
68
        column.add_attribute(cell, "node", 1)
 
69
        column.add_attribute(cell, "in-lines", 2)
 
70
        column.add_attribute(cell, "out-lines", 3)
 
71
        self.treeview.append_column(column)
 
72
 
 
73
        cell = gtk.CellRendererText()
 
74
        cell.set_property("width-chars", 40)
 
75
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
 
76
        column = gtk.TreeViewColumn("Message")
 
77
        column.set_resizable(True)
 
78
        column.pack_start(cell, expand=True)
 
79
        column.add_attribute(cell, "text", 4)
 
80
        self.treeview.append_column(column)
 
81
 
 
82
        cell = gtk.CellRendererText()
 
83
        cell.set_property("width-chars", 40)
 
84
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
 
85
        column = gtk.TreeViewColumn("Committer")
 
86
        column.set_resizable(True)
 
87
        column.pack_start(cell, expand=True)
 
88
        column.add_attribute(cell, "text", 5)
 
89
        self.treeview.append_column(column)
 
90
 
 
91
        cell = gtk.CellRendererText()
 
92
        cell.set_property("ellipsize", pango.ELLIPSIZE_END)
 
93
        column = gtk.TreeViewColumn("Date")
 
94
        column.set_resizable(True)
 
95
        column.pack_start(cell, expand=True)
 
96
        column.add_attribute(cell, "text", 6)
 
97
        self.treeview.append_column(column)
 
98
 
 
99
    def set_branch(self, branch, start):
 
100
        """Set the branch and start position for this window.
 
101
 
 
102
        Creates a new TreeModel and populates it with information about
 
103
        the new branch before updating the window title and model of the
 
104
        treeview itself.
 
105
        """
 
106
        # [ revision, node, last_lines, lines, message, committer, timestamp ]
 
107
        model = gtk.ListStore(gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
 
108
                              gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
 
109
                              str, str, str)
 
110
 
 
111
        last_lines = []
 
112
        for revision, node, lines in graph(branch, start):
 
113
            message = revision.message.split("\n")[0]
 
114
            if revision.committer is not None:
 
115
                timestamp = format_date(revision.timestamp, revision.timezone)
 
116
            else:
 
117
                timestamp = None
 
118
 
 
119
            model.append([ revision, node, last_lines, lines,
 
120
                           message, revision.committer, timestamp ])
 
121
            last_lines = lines
 
122
 
 
123
        self.set_title(os.path.basename(branch.base) + " - bzrk")
 
124
        self.treeview.set_model(model)