Greetings community!
I’m working on a small app - it’s just a GtkColumnView based app. I have it working mostly based on this code snippet.
One thing I have done though is set it up so that if you click on a GtkInscription widget it will replace with a GtkEntry one so that you can edit it on the fly. Then it will replace it back with a GtInscription with the new value.
This all works fine.
However, if while one gtkentry widget is focused and awaiting input, it allows me to click on another GtkInscription widget and replace that as well. I would like to change the behavior so that it only has one GtkEntry focused and active and not allow it to click on a widget on the same or another column.
Here is a snippet:
def _pt_hdrcol_on_factory_bind(self, factory, list_item, what):
""" list_item is a GtkColumnViewColumn, and we get here from reacting to a "bind" signal defined by a factory attached to the GtkColumnView """
cell = list_item.get_child()
if cell:
pt_col_hdr = list_item.get_item()
cell.set_text(str(pt_col_hdr.get_property(what)))
controller = Gtk.GestureClick() # capture clicks
controller.connect("pressed", self._pt_hdrcol_on_label_clicked, list_item, what)
cell.add_controller(controller)
def _pt_hdrcol_on_label_clicked(self, controller, n_press, x, y, list_item, attribute_name):
entry = Gtk.Entry()
cell = list_item.get_child()
entry.set_text(cell.get_text())
list_item.set_child(entry)
# Connect entry events
entry.connect("activate", self._pt_hdrcol_entry_activate, list_item, attribute_name)
def _pt_hdrcol_entry_activate(self, entry, list_item, attribute_name):
data = list_item.get_item()
new_value = entry.get_text()
data._data[attribute_name] = new_value
# delete the GtkEntry widget after getting the value.
list_item.set_child(None)
# create the replacement widget and copy it over
label = Gtk.Inscription()
label.set_min_chars(15)
label.set_text(new_value)
label.set_xalign(0.0)
list_item.set_child(label)
def _pt_hdrcol_on_factory_unbind(self, factory, list_item, what):
""" clean up after myself and unbind the widget """
cell = list_item.get_child()
# this code is only for dealing with the GtkLabel or Inscription
if cell._binding and hasattr(list_item, '_click_controller'):
controller = list_item._click_controller
cell.remove_controller(controller)
del list_item._click_controller
if cell._binding:
cell._binding.unbind()
cell._binding = None
def _pt_hdrcol_on_factory_unbind(self, factory, list_item, what):
cell = list_item.get_child()
# this code is only for dealing with the GtkLabel or Inscription
if cell._binding and hasattr(list_item, '_click_controller'):
controller = list_item._click_controller
cell.remove_controller(controller)
del list_item._click_controller
if cell._binding:
cell._binding.unbind()
cell._binding = None