Hello All,
I am trying to understand how to format numerical data in a Treeview.
All is well when using "{0:0.2g}".format for my Entry widgets. I would
like to format my Treeviews similarly. This is easy, I know, but I
haven't found the magical link on Google or in the PyGTK API docs yet.
The information I am displaying in the Treeview is being pulled from a
MySQL database. Below are the code snippets showing how I create the
Treemodel and load the Treemodel. Since I am loading my model "by row",
I can't apply the formatting to the individual fields. My intuition
tells me this is likely the only way I can accomplish what I want. But,
before I re-write my code, I wanted to ask if it is possible to do what
I want at all and what is the best way to do it.
Thanks in advance for any help the community may offer.
Andrew
<----- Snippet showing how I create the model and the tree ----->
from lxml import etree
# Retrieve the column datatype from the format file.
path = "/root/tree[@name='%s']/column/datatype" % name
datatype =
etree.parse(_conf.RELIAFREE_FORMAT_FILE[fmt_idx]).xpath(path)
# Create a list of GObject datatypes to pass to the model.
types = []
for i in range(len(position)):
types.append(datatype[i].text)
gobject_types = []
gobject_types = [gobject.type_from_name(types[ix])
for ix in range(len(types))]
if(fmt_idx == 2):
gobject_types.append(gtk.gdk.Pixbuf)
model = gtk.TreeStore(*gobject_types)
treeview = gtk.TreeView(model)
< ----- Snippet showing how I get the information from the database and
load the tree model. ----->
query = "SELECT * FROM tbl_system \
WHERE fld_revision_id=%d" % \
self.revision_id
results = self._app.MySQL.execute_query(query, self._app.ProgCnx)
for i in range(len(results)):
if(results[i][60] == 1):
icon = _conf.ICON_DIR + '32x32/important.png'
elif(results[i][63] == 0):
icon = _conf.ICON_DIR + '32x32/assembly.png'
else:
icon = _conf.ICON_DIR + '32x32/part.png'
icon = gtk.gdk.pixbuf_new_from_file_at_size(icon, 16, 16)
data_ = results[i] + (icon, )
row = self.model.append(piter, data_)
_______________________________________________
pygtk mailing list [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://faq.pygtk.org/