-
Notifications
You must be signed in to change notification settings - Fork 0
/
simpleTreeView.py
62 lines (44 loc) · 1.63 KB
/
simpleTreeView.py
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
from gi.repository import Gtk
from gi.repository import Pango
import sys
list_of_dvd = [("The Usual Suspects", "111"),
("Gilda", "111"),
("The Godfather", "111"),
("Pulp Fiction", "111"),
("Once Upon a Time in the West", "111"),
("Rear Window", "111")]
class MyWindow(Gtk.ApplicationWindow):
def __init__(self, app):
Gtk.Window.__init__(self, title="My DVDs", application=app)
self.set_default_size(250, 100)
self.set_border_width(10)
# the data are stored in the model
# create a liststore with one column
self.listmodel = Gtk.ListStore(str,str)
for lista in list_of_dvd:
self.listmodel.append(list(lista))
# a treeview to see the data stored in the model
view = Gtk.TreeView(model=self.listmodel)
# cellrenderer for the first column
cell = Gtk.CellRendererText()
cell2= Gtk.CellRendererText()
col = Gtk.TreeViewColumn("Title", cell, text=0)
view.append_column(col)
col2 = Gtk.TreeViewColumn("Descrip", cell2, text=1)
view.append_column(col2)
# a grid to attach the widgets
grid = Gtk.Grid()
grid.attach(view, 0, 0, 4, 1)
# add the grid to the window
self.add(grid)
class MyApplication(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(self)
def do_activate(self):
win = MyWindow(self)
win.show_all()
def do_startup(self):
Gtk.Application.do_startup(self)
app = MyApplication()
exit_status = app.run(sys.argv)
sys.exit(exit_status)