Filippos
Filippos

Reputation: 457

pygtk cellrenderertoggle is not checked

I have the following code:

self.db='checks.db'
self.con = lite.connect(self.db)
self.cur = self.con.cursor()
self.q_oblig_initial='SELECT data_plirotees.rowid as rowid,recdate,bank,amount,dueto,gto,plirstatus FROM data_plirotees WHERE plirstatus=0 ORDER BY dueto ASC'
self.store_oblig = gtk.ListStore(int,str,str,str,str,str,bool)
self.cur.execute(q_oblig)
self.data_oblig=self.cur.fetchall()
for value in self.data_oblig:
    if value[6]==0:
        plir=False
    elif value[6]==1:
        plir=True     
self.store_oblig.append([value[0],datetime.datetime.fromtimestamp(int(value[1])).strftime('%d/%m/%Y'),value[2],"%.2f" %(value[3]),datetime.datetime.fromtimestamp(int(value[4])).strftime('%d/%m/%Y'),value[5],plir])`

which gets data from a sqlite database and puts it in a liststore and,

rendererToggle.connect("toggled", self.on_cell_toggled)
column_toggle = gtk.TreeViewColumn("Καλύφθηκε", rendererToggle, active=1)
column_toggle.set_fixed_width(10)
treeView_oblig.append_column(column_toggle)

which has to show it in a column where true should show a checked toggle/checkbox and false should show un-checked.

Unfortunately this doesn't happen. The checkbox needs not to be active (i don't want it to be able to toggle) but by clicking on the treeview row it opens a new window (where a checkbutton is checked or not accordingly). From that I understand that the true/false value is contained there somewhere but it is not presented visually.

Can someone show me where I'm wrong?

I didn't post the whole program 'cause it would be too big and perhaps misguiding...

Upvotes: 0

Views: 700

Answers (1)

andlabs
andlabs

Reputation: 11578

self.store_oblig = gtk.ListStore(int,str,str,str,str,str,bool)

This line creates a GtkListStore where each column is of a different type. The columns are numbered from left to right, starting at 0:

self.store_oblig = gtk.ListStore(int,str,str,str,str,str,bool)
                   column number 0   1   2   3   4   5   6

You create your GtkTreeViewColumn with this:

column_toggle = gtk.TreeViewColumn("Καλύφθηκε", rendererToggle, active=1)

This says that the column's cell renderer should get the value of its active property from column 1 of the model (in this case, the list store). And the active property expects a bool.

But if you look back above, column 1 isn't a bool, but rather a string! So what you really wanted was active=6, not active=1. (Your code to add to the list store, on the other hand, seems correct.)

This is what the warning Warning: unable to set property 'active' of type 'gboolean' from value of type 'gchararray' gtk.main() is trying to tell you; gchararray is (one of) GLib's internal name(s) for a string.

Upvotes: 1

Related Questions