File: listdialog.py

package info (click to toggle)
kiwi 1.9.22-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 11,908 kB
  • ctags: 5,549
  • sloc: python: 15,779; ansic: 193; xml: 77; makefile: 57; sh: 17
file content (69 lines) | stat: -rw-r--r-- 1,602 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# A simple example to demonstrate the ListDialog dialog

import gtk

from kiwi.enums import ListType
from kiwi.ui.listdialog import ListDialog
from kiwi.ui.objectlist import Column
from kiwi.ui.widgets.contextmenu import ContextMenu, ContextMenuItem

class Item(object):
    def __init__(self, name):
        self.name = name

    def __repr__(self):
        return self.name

class MyListDialog(ListDialog):

    columns = [Column('name')]
    list_type = ListType.UNEDITABLE


    def __init__(self):
        ListDialog.__init__(self)
        self._create_menu()

    def _create_menu(self):
        menu = ContextMenu()

        item = ContextMenuItem('_Foo', gtk.STOCK_COPY)
        item.connect('activate', self._on_foo_activate)
        item.connect('can-disable', self._on_foo_can_disable)
        menu.append(item)

        item = ContextMenuItem('Bar')
        item.connect('activate', self._on_bar_activate)
        menu.append(item)

        menu.append_separator()

        item = ContextMenuItem(gtk.STOCK_PASTE)
        item.connect('activate', self._on_paste_activate)
        menu.append(item)

        self.listcontainer.list.set_context_menu(menu)
        menu.show_all()

    def _on_foo_activate(self, menu_item):
        print 'foo'

    def _on_foo_can_disable(self, menu_item):
        return True

    def _on_bar_activate(self, menu_item):
        print 'bar'

    def _on_paste_activate(self, menu_item):
        print 'paste'

    def populate(self):
        return [Item('test')]

    def add_item(self):
        return Item("added")

dialog = MyListDialog()
dialog.run()