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

  • Committer: Jelmer Vernooij
  • Date: 2007-07-15 15:22:29 UTC
  • Revision ID: jelmer@samba.org-20070715152229-clmlen0vpd8d2pzx
Add docstrings, remove unused code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2008 Jelmer Vernooij <jelmer@samba.org>
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
 
 
17
 
try:
18
 
    import pygtk
19
 
    pygtk.require("2.0")
20
 
except:
21
 
    pass
22
 
 
23
 
import gtk
24
 
import gobject
25
 
 
26
 
from bzrlib.plugins.gtk.diff import DiffWidget
27
 
from bzrlib.plugins.gtk.dialog import question_dialog
28
 
from bzrlib.plugins.loom import (
29
 
    branch as loom_branch,
30
 
    tree as loom_tree,
31
 
    )
32
 
from bzrlib.plugins.gtk.i18n import _i18n
33
 
 
34
 
 
35
 
class LoomDialog(gtk.Dialog):
36
 
    """Simple Loom browse dialog."""
37
 
 
38
 
    def __init__(self, branch, tree=None, parent=None):
39
 
        gtk.Dialog.__init__(self, title="Threads",
40
 
                                  parent=parent,
41
 
                                  flags=0,
42
 
                                  buttons=(gtk.STOCK_CLOSE,gtk.RESPONSE_OK))
43
 
        self.branch = branch
44
 
        if tree is not None:
45
 
            self.tree = loom_tree.LoomTreeDecorator(tree)
46
 
        else:
47
 
            self.tree = None
48
 
 
49
 
        self._construct()
50
 
 
51
 
    def run(self):
52
 
        try:
53
 
            loom_branch.require_loom_branch(self.branch)
54
 
        except loom_branch.NotALoom:
55
 
            response = question_dialog(
56
 
                _i18n("Upgrade to Loom branch?"),
57
 
                _i18n("Branch is not a loom branch. Upgrade to Loom format?"),
58
 
                parent=self)
59
 
                # Doesn't set a parent for the dialog..
60
 
            if response == gtk.RESPONSE_NO:
61
 
                return
62
 
            assert self.branch.nick is not None
63
 
            loom_branch.loomify(self.branch)
64
 
        self._load_threads()
65
 
        return super(LoomDialog, self).run()
66
 
 
67
 
    def _construct(self):
68
 
        hbox = gtk.HBox()
69
 
 
70
 
        self._threads_scroller = gtk.ScrolledWindow()
71
 
        self._threads_scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
72
 
        self._threads_view = gtk.TreeView()
73
 
        self._threads_scroller.add(self._threads_view)
74
 
        self._threads_scroller.set_shadow_type(gtk.SHADOW_IN)
75
 
        hbox.pack_start(self._threads_scroller)
76
 
 
77
 
        self._threads_store = gtk.ListStore(
78
 
                gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT, gobject.TYPE_STRING)
79
 
        self._threads_view.set_model(self._threads_store)
80
 
        self._threads_view.append_column(gtk.TreeViewColumn("Name", gtk.CellRendererText(), text=0))
81
 
        self._threads_view.connect('cursor-changed', self._on_view_thread)
82
 
        if self.tree is not None:
83
 
            self._threads_view.connect('row-activated', self._on_switch_thread)
84
 
 
85
 
        self._diff = DiffWidget()
86
 
        self._diff.show()
87
 
        hbox.pack_end(self._diff)
88
 
 
89
 
        hbox.show_all()
90
 
        self.vbox.pack_start(hbox)
91
 
 
92
 
        # FIXME: Buttons: combine-thread, revert-loom, record
93
 
        self.set_default_size(500, 350)
94
 
 
95
 
    def _on_view_thread(self, treeview):
96
 
        treeselection = treeview.get_selection()
97
 
        (model, selection) = treeselection.get_selected()
98
 
        if selection is None:
99
 
            return
100
 
        revid, parent_revid = model.get(selection, 1, 3)
101
 
        if parent_revid is None:
102
 
            return
103
 
        self.branch.lock_read()
104
 
        try:
105
 
            (rev_tree, parent_tree) = tuple(self.branch.repository.revision_trees([revid, parent_revid]))
106
 
            self._diff.set_diff(rev_tree, parent_tree)
107
 
        finally:
108
 
            self.branch.unlock()
109
 
 
110
 
    def _on_switch_thread(self, treeview, path, view_column):
111
 
        new_thread = self._threads_store.get_value(self._threads_store.get_iter(path), 0)
112
 
        self.tree.down_thread(new_thread)
113
 
 
114
 
    def _load_threads(self):
115
 
        self._threads_store.clear()
116
 
        
117
 
        self.branch.lock_read()
118
 
        try:
119
 
            threads = self.branch.get_loom_state().get_threads()
120
 
            last_revid = None
121
 
            for name, revid, parent_ids in reversed(threads):
122
 
                self._threads_store.append([name, revid, parent_ids, last_revid])
123
 
                last_revid = revid
124
 
        finally:
125
 
            self.branch.unlock()