Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>gtk.TreeModelSort</code> is just a model (interface for access), it does not actually store anything. In fact, you don't need to invoke it yourself to make your table sortable. The simplest way is to let GTK do the sorting for you, which means that you have to store C data and not Python objects in your table. So, change your <code>make_list()</code> method to </p> <pre><code>listmodel = gtk.ListStore(str) </code></pre> <p>instead of <code>object</code>. Then you just have to tell the <code>gtk.TreeView</code> that clicking on the first column header should sort according to the first column in the <code>gtk.ListStore</code> by putting</p> <pre><code>self.tvcolumn[0].set_sort_column_id(0) </code></pre> <p>into your constructor. To sort by file size you'd add an extra colum consisting of <code>int</code> in the list store and use that as sort column id etc.</p> <p><strong>Edit</strong>: Ok let me spell the last thing out: </p> <pre><code>listmodel = gtk.ListStore(str, int) for f in files: file_size = os.stat(os.path.join(self.dirname, f)).st_size listmodel.append([f, file_size]) </code></pre> <p>puts the file size in the second column of the store. Then, to sort by file size you can just add </p> <pre><code>self.tvcolumn[1].set_sort_column_id(1) </code></pre> <p>In general, I would recommend to restructure your code that everything is stored in the <code>ListStore</code> once at the beginning. That way, you can code the cell rendering much easier by just tying each view column to a store column.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload