GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Apr 25, 2014 2:28 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: pyGTK ListStore Troubles
PostPosted: Mon Jan 30, 2012 3:57 am 
Offline

Joined: Mon Jan 30, 2012 3:54 am
Posts: 3
Hi everyone,

I am having some difficulty with ListStores on pyGTK. Using the following code, anytime I add a new track, the only value that takes is the very first boolean. Any ideas?

Code:
import gtk, gobject

class MusicTreeview():
    def __init__(self, builder):
        self.treeview = builder.get_object('music_treeview')
        self.model = gtk.ListStore(bool, str, str, str, str, str, str)
        self.treeview.set_model(self.model)
       
        cell = gtk.CellRendererToggle()
        col = gtk.TreeViewColumn("", cell, active=0)
        self.treeview.append_column(col)
       
        strColumns = ['#', 'Name', 'Artist', 'Album', 'Length', 'Size']
        for col in strColumns:
            cell = gtk.CellRendererText()
            col = gtk.TreeViewColumn(col, cell)
            self.treeview.append_column(col)
           
        self.AddTrack(True, '1', 'name', 'artist', 'album', '0:00', '0MB')
        self.AddTrack(False, '2', 'name', 'artist', 'album', '0:00', '0MB')
        self.AddTrack(True, '3', 'name', 'artist', 'album', '0:00', '0MB')
       
    def AddTrack(self, syncd, num, name, artist, album, length, size):
        iter = self.model.append()
        self.model.set(iter, 0, syncd, 1, num, 2, name, 3, artist, 4, album, 5, length, 6, size)


Top
 Profile  
 
 Post subject: Re: pyGTK ListStore Troubles
PostPosted: Thu Feb 02, 2012 3:31 pm 
Offline

Joined: Mon Jan 30, 2012 3:54 am
Posts: 3
Anybody? I've hunted around Google for a while and there are largely just single column examples, which doesn't really help.


Top
 Profile  
 
 Post subject: Re: pyGTK ListStore Troubles
PostPosted: Sat Feb 04, 2012 2:52 am 
Offline

Joined: Mon Jan 30, 2012 3:54 am
Posts: 3
Managed to find a guide that was helpful here.

Modifications shown below.

Code:
import gtk

class MusicTreeview():
    def __init__(self, builder):
        self.treeview = builder.get_object('music_treeview')
        self.model = gtk.ListStore(bool, str, str, str, str, str, str)
        self.treeview.set_model(self.model)

        cell_data_funcs = (self.track_selected, self.track_num,
                           self.track_name,     self.track_artist,
                           self.track_album,    self.track_length,
                           self.track_size)
        self.column_names = ['', '#', 'Name', 'Artist', 'Album', 'Length', 'Size']

        self.treeview_columns = [None] * len(self.column_names)

        celltog = gtk.CellRendererToggle()
        self.treeview_columns[0] = gtk.TreeViewColumn(self.column_names[0], celltog)
        self.treeview_columns[0].set_cell_data_func(celltog, self.track_selected)
        self.treeview.append_column(self.treeview_columns[0])

        for n in range(1, len(self.column_names)):
            cell = gtk.CellRendererText()
            self.treeview_columns[n] = gtk.TreeViewColumn(self.column_names[n], cell)
            self.treeview_columns[n].set_cell_data_func(cell, cell_data_funcs[n])
            self.treeview.append_column(self.treeview_columns[n])
       
    def track_selected(self, column, cell, model, iter):
        cell.set_property('active', model.get_value(iter, 0))
        return

    def track_num(self, column, cell, model, iter):
        cell.set_property('text', model.get_value(iter, 1))
        return

    def track_name(self, column, cell, model, iter):
        cell.set_property('text', model.get_value(iter, 2))
        return

    def track_artist(self, column, cell, model, iter):
        cell.set_property('text', model.get_value(iter, 3))
        return

    def track_album(self, column, cell, model, iter):
        cell.set_property('text', model.get_value(iter, 4))
        return

    def track_length(self, column, cell, model, iter):
        cell.set_property('text', model.get_value(iter, 5))
        return

    def track_size(self, column, cell, model, iter):
        cell.set_property('text', model.get_value(iter, 6))
        return

    def AddTrack(self, syncd, num, name, artist, album, length, size):
        self.model.append([syncd, num, name, artist, album, length, size])
        return


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Gunner and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group