/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: Vincent Ladeuil
  • Date: 2008-05-05 18:16:46 UTC
  • mto: (487.1.1 gtk)
  • mto: This revision was merged to the branch mainline in revision 490.
  • Revision ID: v.ladeuil+lp@free.fr-20080505181646-n95l8ltw2u6jtr26
Fix bug #187283 fix replacing _() by _i18n().

* genpot.sh 
Remove duplication. Add the ability to specify the genrated pot
file on command-line for debugging purposes.

* po/olive-gtk.pot:
Regenerated.

* __init__.py, branch.py, branchview/treeview.py, checkout.py,
commit.py, conflicts.py, diff.py, errors.py, initialize.py,
merge.py, nautilus-bzr.py, olive/__init__.py, olive/add.py,
olive/bookmark.py, olive/guifiles.py, olive/info.py,
olive/menu.py, olive/mkdir.py, olive/move.py, olive/remove.py,
olive/rename.py, push.py, revbrowser.py, status.py, tags.py:
Replace all calls to _() by calls to _i18n(), the latter being
defined in __init__.py and imported in the other modules from
there. This fix the problem encountered countless times when
running bzr selftest and getting silly error messages about
boolean not being callables.

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