2016-11-15 6:27 GMT+01:00 Tristan Van Berkom <tristan.vanberkom@codethink.
co.uk>:

> Hi,
>
> On Tue, 2016-11-15 at 02:09 +0100, pozzugno wrote:
> [...]
> > I have tried to catch "editing_started", "editing_canceled" and
> > "edited"
> > signals of CellRenderer. In "editing_started" callback, I retrieve
> > and
> > save the row and column of the cell the user is going to edit. I
> > also
> > connect a callback to "value_changed" signal of the GtkAdjustment
> > associated to the GtkCellRendererSpin. Moreover I save the starting
> > value so I can restore it if the user will cancel the editing.
> >
> > When the user clicks on +/- buttons, "value_changed" is called (so I
> > can
> > send the request to the remote device).
> >
> > With some tricks, I'm able to restore the original value if the user
> > cancels the editing and to avoid a duplicate request to the remote
> > device when the user confirm the value changed by +/- buttons
> > (actually
> > when the user moves the focus away from the spinbutton, thus
> > terminated
> > the editing).
> >
> > As you know, I'm very new to Gtk programming, so I'm wondering
> > wethere
> > there's a better approach.
>
> Without reading your python code, your approach sounds correct.
>
> If you want to get notifications (callbacks) for live editing of
> editable widgets, you need to handle the editing started signal and
> then handle signals on the editable widget which is created for that
> edit session.
>

>From your words, I can use editable parameter in "editing-started"
callback. It should be a real GtkSpinButton, so I can connect to
"value-changed" signal to know when the user changes the value, through +/-
buttons or associated entry.

It works quite well, but I have two problems yet.

The first: you wrote the editable widget is *created* for that session. So
I suppose it will be destroyed automatically when the edit session ends.
Should I care to disconnect my callbacks before the widget is destroyed? I
think it's not important: when the widget is destroyed, all the connections
are freed without memory leaks.

Second and more important problem. During editing, the table/GtkTreeView
should be in a particular state (I have to avoid refreshing associated
GtkListStore to prevent ending prematurely from editing).
So I have to make some actions when the user is changing the value, but I
can't update GtkListStore otherwise the edit session is ended. My idea is
to use a global editing_in_progress flag that is asserted when the user
starts editing and deasserted when the edit session is ended.
I tried to assert the flag in "editing-started" callback, and to deassert
the flag in "edited" and "editing-canceled" callbacks and it works most of
the time... but not always.

For example, if the user clicks on another application during cell editing,
the "edited" signal is fired (so the flag is deasserted), but the editable
widget (the SpinButton) isn't destroyed. In this state, the ListStore could
be updated because the flag is deasserted, ending prematurely the active
edit session.

I couldn't find a "editing-finished" signal.
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to