1 import gtk
2
3 janela = gtk.Window(gtk.WINDOW_TOPLEVEL)
4 janela.set_title("TreeView com Combo")
5 janela.connect("delete_event", gtk.main_quit)
6
7 modelo= gtk.ListStore(str)
8 modelo.append(['Cartucho de Impressora'])
9 modelo.append(['Computador 486 Semi-Novo'])
10 modelo.append(['Computador Top de Linha'])
11 modelo.append(['Monitor 21"'])
12 modelo.append(['Mouse Ps2'])
13 modelo.append(['Teclado ABNT2'])
14 modelo.append(['Impressora LX-300L'])
15
16 combo= gtk.CellRendererCombo()
17 combo.set_property("model", modelo)
18 combo.set_property('text-column', 0)
19 combo.set_property('editable', True)
20
21 barra = gtk.CellRendererProgress()
22
23 tGrade= gtk.TreeView()
24 mgrade= gtk.ListStore(str, str, str, str, str, int)
25 tGrade.set_model(mgrade)
26 coluna1= gtk.TreeViewColumn("Ordem", gtk.CellRendererText(), text= 0)
27 coluna2= gtk.TreeViewColumn("Produto", combo, text=1)
28 coluna3= gtk.TreeViewColumn("Valor", gtk.CellRendererText(), text= 2)
29 coluna4= gtk.TreeViewColumn("Qtd", gtk.CellRendererText(), text= 3)
30 coluna5= gtk.TreeViewColumn("Total", gtk.CellRendererText(), text= 4)
31 coluna6= gtk.TreeViewColumn("Ok", barra, value=5)
32 coluna1.set_resizable(True)
33 coluna2.set_resizable(True)
34 coluna3.set_resizable(True)
35 coluna4.set_resizable(True)
36 coluna5.set_resizable(True)
37 coluna2.set_expand(True)
38 coluna1.set_sort_column_id(0)
39 coluna2.set_sort_column_id(1)
40 coluna3.set_sort_column_id(2)
41 coluna4.set_sort_column_id(3)
42 coluna5.set_sort_column_id(4)
43 tGrade.append_column(coluna1)
44 tGrade.append_column(coluna2)
45 tGrade.append_column(coluna3)
46 tGrade.append_column(coluna4)
47 tGrade.append_column(coluna5)
48 tGrade.append_column(coluna6)
49
50 msg = '(escolha um produto)'
51 mgrade.append(['Qualquer', msg, '5.00', '2', '10.00', 10])
52 mgrade.append(['Outro', msg,'15.00', '22', '110.00', 30])
53
54 def on__combo__edited(renderer, path, new_text, model):
55 coluna_produto = 1
56 model[path][coluna_produto] = new_text
57
58 combo.connect("edited", on__combo__edited, mgrade)
59
60 janela.add(tGrade)
61 janela.show_all()
62 gtk.main()