/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: 2008-07-31 00:07:21 UTC
  • mto: (580.2.1 gtk.gloom)
  • mto: This revision was merged to the branch mainline in revision 581.
  • Revision ID: jelmer@samba.org-20080731000721-tbg7rh6302eywkj8
Show threads in loom dialog.

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 import _i18n
 
27
from bzrlib.plugins.gtk.dialog import question_dialog
 
28
from bzrlib.plugins.loom import branch as loom_branch
 
29
 
 
30
class LoomDialog(gtk.Dialog):
 
31
    """Simple Loom browse dialog."""
 
32
 
 
33
    def __init__(self, branch, parent=None):
 
34
        gtk.Dialog.__init__(self, title="Threads",
 
35
                                  parent=parent,
 
36
                                  flags=0,
 
37
                                  buttons=(gtk.STOCK_CLOSE,gtk.RESPONSE_OK))
 
38
        self.branch = branch
 
39
 
 
40
        self._construct()
 
41
 
 
42
    def run(self):
 
43
        try:
 
44
            loom_branch.require_loom_branch(self.branch)
 
45
        except loom_branch.NotALoom:
 
46
            response = question_dialog(
 
47
                _i18n("Upgrade to Loom branch?"),
 
48
                _i18n("Branch is not a loom branch. Upgrade to Loom format?"),
 
49
                parent=self)
 
50
                # Doesn't set a parent for the dialog..
 
51
            if response == gtk.RESPONSE_NO:
 
52
                return
 
53
            assert self.branch.nick is not None
 
54
            loom_branch.loomify(self.branch)
 
55
        return super(LoomDialog, self).run()
 
56
 
 
57
    def _construct(self):
 
58
        self._threads_scroller = gtk.ScrolledWindow()
 
59
        self._threads_scroller.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
 
60
        self._threads_view = gtk.TreeView()
 
61
        self._threads_view.show()
 
62
        self._threads_scroller.add(self._threads_view)
 
63
        self._threads_scroller.set_shadow_type(gtk.SHADOW_IN)
 
64
        self._threads_scroller.show()
 
65
        self.vbox.pack_start(self._threads_scroller)
 
66
 
 
67
        self._threads_store = gtk.ListStore(
 
68
                gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
 
69
        self._threads_view.set_model(self._threads_store)
 
70
        self._threads_view.append_column(gtk.TreeViewColumn("Name", gtk.CellRendererText(), text=0))
 
71
 
 
72
        # Buttons: combine-thread, export-loom, revert-loom, up-thread
 
73
        self.set_default_size(200, 350)
 
74
 
 
75
        self._load_threads()
 
76
 
 
77
    def _load_threads(self):
 
78
        self._threads_store.clear()
 
79
        
 
80
        self.branch.lock_read()
 
81
        try:
 
82
            threads = self.branch.get_loom_state().get_threads()
 
83
            for thread in reversed(threads):
 
84
                self._threads_store.append(thread)
 
85
        finally:
 
86
            self.branch.unlock()