Python - Como hacer grids

 
Vista:

Como hacer grids

Publicado por tronxx (16 intervenciones) el 03/05/2007 17:39:33
Hola amigos, estoy tratando de hacer unos programas mas o menos decentes, entonces quiero instalarle un grid a mi aplicacion, pero no se como hacerle para que se visualicen las lineas de division:

self.liststore = gtk.ListStore(str, str, str)
self.treeview = gtk.TreeView(self.liststore)

# create the TreeViewColumns to display the data
self.tvcolumn = gtk.TreeViewColumn('Codigo')
self.tvcolumn1 = gtk.TreeViewColumn('Nombre')

# add a row with text and a stock item - color strings for
# the background
self.mydb = MySQLdb.connect(host="localhost", user="user", passwd="pwd",db="inven")
vendedores_z = []
cursor = self.mydb.cursor()
sql_z = "select codigo, nombre from vendedor order by codigo"
cursor.execute(sql_z)
result = cursor.fetchall()
for record in result:
self.liststore.append([ record[0], "", record[1] ])
# add columns to treeview
self.treeview.append_column(self.tvcolumn)
self.treeview.append_column(self.tvcolumn1)

# create a CellRenderers to render the data
self.cell = gtk.CellRendererText()
self.cell1 = gtk.CellRendererText()

# add the cells to the columns - 2 in the first
self.tvcolumn.pack_start(self.cell, False)
self.tvcolumn1.pack_start(self.cell1, True)

# set the cell attributes to the appropriate liststore column
self.tvcolumn.set_attributes(self.cell, text=0)
self.tvcolumn1.set_attributes(self.cell1, text=2,
cell_background_set=3)
# Allow sorting on the column
self.tvcolumn.set_sort_column_id(0)
self.treeview.set_reorderable(True)
vbox.pack_start(self.treeview, gtk.FALSE, gtk.FALSE, 0)
vbox.show()

este es mi codigo, pero no se como ponerle las lineas. Si alguien sabe
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Como hacer grids

Publicado por Satanas (1 intervención) el 23/05/2007 19:11:27
Muy sencillo, con esta instrucción haces que aparezcan los grids:

self.treeview.set_grid_lines(True)
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Como hacer grids

Publicado por tronxx (16 intervenciones) el 07/07/2007 00:08:51
Con este codigo agregas un ListStore con un numero variable de columnas
1.
2. def agrega_grd_alm(self):
3. grd_almacs = self.wTree.get_widget("grd_almacs")
4. sql_z = "select clave from almacen order by clave"
5. cursor = mydb.cursor()
6. cursor.execute(sql_z)
7. result = cursor.fetchall()
8. ii_z = 0
9. # First i make a ListStore with only one column
10. lst_alms = gtk.ListStore(str)
11. grd_almacs.set_model(lst_alms)
12. alms_z = []
13. misalms_z = []
14. for record in result:
15. print "Alm:", record[0]
16. # append a new column, every column has the same type str
17. alms_z.append(str)
18. misalms_z.append(record[0])
19. col = gtk.TreeViewColumn(record[0])
20. grd_almacs.append_column(col)
21. cell = gtk.CellRendererText()
22. col.pack_start(cell, False)
23. col.set_attributes(cell, text=ii_z)
24. ii_z = ii_z + 1
25. #Now, i create a new ListStore with a variable number of columns
26. lst_alms = gtk.ListStore(*[str for col in alms_z])
27. #Now i assign the new model to my TreeView
28. grd_almacs.set_model(lst_alms)
29. lst_alms.append( misalms_z )
30.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar