Search code examples
pythongtk3glade

Glade GTK3 Python treeview toggles wont toggle


I have an application where the GtkCellRendererToggle does not trigger a callback when I use Glade to build the the application. Specifically, if the toggle button is set to True when I click on it, the callback is executed, but when the button is toggled to False, the callback is not triggered.

I am using Python 3, GTK3 and Glade 3.22.1 I am including the Python source code along with the associated xml. The working example comes from the python gtk3 tutorial: https://python-gtk-3-tutorial.readthedocs.io/en/latest/cellrenderers.html

Blockquote

<object class="GtkTreeView" id="treeview">
      <property name="visible">True</property>
      <property name="can_focus">True</property>
      <property name="model">liststore</property>
      <child internal-child="selection">
          <object class="GtkTreeSelection">
              <property name="mode">none</property>
          </object>
      </child>
      <child>
          <object class="GtkTreeViewColumn" id="togglecolumn">
          <property name="title">Togggle</property>
      <child>
          <object class="GtkCellRendererToggle" id="togglerenderer">
              <signal name="toggled" handler="on_cell_toggled" swapped="no"/>
          </object>
              <attributes>
                  <attribute name="activatable">0</attribute>
                  <attribute name="active">0</attribute>
              </attributes>
      </child>
</object>

/>

Blockquote

builder = Gtk.Builder()
builder.add_from_file("example.glade")
window = builder.get_object("window")
# Load list data.
self.liststore = builder.get_object ("liststore")

builder.connect_signals(self)
window.show()

def on_cell_toggled(self, widget, path):
    self.liststore[path][0] = not self.liststore[path][0]

/>

What you will see is 3 rows of toggle buttons with the first and third checked. If you click on one of the checked boxes, the on_cell_toggle callback is executed, but once it has been toggled to false, it no longer triggers the callback. In the example in the tutorial the toggle works as expected.


Solution

  • You have set the activatable property to the same column as active property:

    <attributes>
        <attribute name="activatable">0</attribute>
         <attribute name="active">0</attribute>
    </attributes>
    

    should be:

    <attributes>
         <attribute name="active">0</attribute>
    </attributes>