~vorlon/ubuntu/saucy/gourmet/trunk

« back to all changes in this revision

Viewing changes to src/lib/gtk_extras/treeview_extras.py

  • Committer: Bazaar Package Importer
  • Author(s): Rolf Leggewie
  • Date: 2009-01-12 23:03:28 UTC
  • mfrom: (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090112230328-wnuqqte22uk3981b
Tags: 0.14.3-2
Conflict with python-pysqlite >= 2.5 which when installed crashes 
gourmet at startup. (Closes: #507382) and python-sqlalchemy >= 0.5.
Both restrictions should eventually be relaxed when upstream has
made the code compatible with the newer libs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
from gourmet.gdebug import *
3
3
import gtk
4
4
 
 
5
def print_tree (mod):
 
6
    for row in mod:
 
7
        print [col for col in row]
 
8
        for child in row.iterchildren():
 
9
            print '-> ',[col for col in child]
 
10
        
5
11
def path_next (path, inc=1):
6
12
    """Return the path NEXT rows after PATH. Next can be negative, in
7
13
    which case we get previous paths."""
36
42
        dpath = ()
37
43
    rowdata = get_row(mod, iter)
38
44
    children=harvest_children(mod, iter)
 
45
    if direction != "after":
 
46
        direction = "before"
 
47
    path = mod.get_path(iter)
 
48
    if sibling:
 
49
        dpath = mod.get_path(sibling)
 
50
    elif parent:
 
51
        dpath = mod.get_path(parent)
 
52
    else:
 
53
        dpath = ()
 
54
    rowdata = get_row(mod, iter)
 
55
    children=harvest_children(mod, iter)
39
56
    def insert_new (parent):
40
57
        """A little subroutine to insert our row. We'll call this at the appropriate
41
58
        time depending on the order of source and destination iters"""
56
73
            return mod.insert_after(parent,sibling,rowdata)
57
74
    # if the source is before the destination, we add then remove. otherwise, we remove then add.
58
75
    path_last = path_compare(path,dpath)
59
 
    if path_last:
 
76
    if path_last==1:
 
77
        # Source after destination (remove, then add)
60
78
        remove_children(mod, iter)
61
79
        mod.remove(iter)
62
80
        new=insert_new(parent)
63
81
        insert_children(mod, new, children)
64
82
    elif path_last==0: debug("Moving into my self is nonsensical!",1)
65
83
    else:
 
84
        # Source before destination (add, then remove)
66
85
        new=insert_new(parent)
67
86
        insert_children(mod, new, children)
 
87
        remove_children(mod, iter)
68
88
        mod.remove(iter)
69
 
        remove_children(mod, iter)
70
89
 
71
90
def insert_children (mod, iter, children):
72
91
    for row in children:
312
331
if __name__ == '__main__':
313
332
    vb = gtk.VBox()
314
333
    sw = QuickTree(
315
 
        ['Foo','Bar'],
316
 
        ['Bar','Foo']
 
334
        [['Foo','Bar'],
 
335
        ['Bar','Foo'],
 
336
        ['Foob','Barb'],
 
337
        ['Baz','Bang'],      ]
317
338
        )
318
339
    sw.tv.set_reorderable(True)
319
340
    sw.tv.ss = selectionSaver(sw.tv,0)