pygtkhelpers-main / examples /

import gtk
from pygtkhelpers.ui.objectlist import Column, ObjectTree

class User(object):
    def __init__(self, name, age, sex, hair='brown', clever=False): = name
        self.age = age
        assert sex in ('m','f') = sex = hair
        self.clever = clever

    def __str__(self):
        return '<User: name=%r age=%r sex=%r hair=%r clever=%r>' % (
                                        , self.age,

listing = ObjectTree([
    Column('name', str, editable=True, searchable=True),
    Column('age', int, editable=True),
    Column('sex', str, expander=True, choices=[
        ('m', 'Male'),
        ('f', 'Female'),
    Column('hair', str, choices=['brown', 'blonde'],
    Column('clever', bool, use_checkbox=True, editable=True),
    Column('age', int, use_spin=True, editable=True),
    Column('age', int, use_progress=True),
    Column('age', int, use_progress=True, progress_text='static_text'),
    Column('age', int, use_progress=True, mapped={'text': 'name'}),

def _on_left_clicked(ol, item, event):
    print 'Left clicked', item

def _on_right_clicked(ol, item, event):
    print 'Right clicked', item
    print ol.model_sort.get_sort_column_id()

def _on_middle_clicked(ol, item, event):
    print 'Middle clicked', item

def _on_double_clicked(ol, item, event):
    print 'Double clicked', item

def _on_expanded(ol, item, msg):
    print msg, item
    return True

listing.connect('item-left-clicked', _on_left_clicked)
listing.connect('item-right-clicked', _on_right_clicked)
listing.connect('item-middle-clicked', _on_middle_clicked)
listing.connect('item-double-clicked', _on_double_clicked)
listing.connect('item-expanded', _on_expanded, 'Expanded')
listing.connect('item-collapsed', _on_expanded, 'Collapsed')

u1 = User("test", 12, 'm', clever=True)
u2 = User('hans', 34, 'm', clever=True)
u3 = User('Zok', 60, 'm')
u4 = User('Mic', 63, 'f')

listing.append(u3, u1)
listing.append(u4, u1)

window = gtk.Window()

window.connect("destroy", gtk.main_quit)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.