Re: Editable SpinButton on a TreeView: detect *every* changes

2016-11-15 Thread Pozz Pozz
2016-11-15 6:27 GMT+01:00 Tristan Van Berkom :

> 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


Re: Editable SpinButton on a TreeView: detect *every* changes

2016-11-14 Thread Tristan Van Berkom
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.

Cheers,
    -Tristan

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Editable SpinButton on a TreeView: detect *every* changes

2016-11-14 Thread pozzugno

Il 14/11/2016 18:19, Pozz Pozz ha scritto:
I created with success a TreeView based on a ListStore. One column has 
a SpinButton (actually a GtkCellRendererSpin).


Now I want to detect when the user *is* changing the value, i.e. every 
time he clicks on + or - buttons.


If I connect the "edited" signal, my callack will be called only when 
the spin button is "unfocused". I lost every clicks.



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.


Here it is my code in Python:

def on_cellspin_table_editing_started(self, renderer, editable, path):
print("editing_started")
self.index_of_table = int(path)
for column_idx, column in 
zip(range(len(self.tv_calib.get_columns())), self.tv_calib.get_columns()):

if column.get_cells()[0] is renderer:
self.table_column = column_idx
break
self.table_adj = editable.get_adjustment()
self.start_value = 
self.liststore[self.index_of_table][self.table_column]

self.table_editing = True
self.table_adj.connect("value-changed", self.on_adj_value_changed)

def on_cellspin_table_edited(self, renderer, path, new_text):
print("edited")
self.table_editing = False
self.table_adj.disconnect_by_func(self.on_adj_value_changed)
new_value = int(new_text)
if int(self.table_adj.get_value()) != new_value:
self.set_value(self.index_of_table, new_value)

def on_cellspin_table_editing_canceled(self, renderer):
print("editing_canceled")
self.table_editing = False
self.table_adj.disconnect_by_func(self.on_adj_value_changed)
if self.start_value != int(self.table_adj.get_value()):
self.set_value(self.index_of_table, self.table_column, 
self.start_value)


def on_adj_value_changed(self, adj):
print("value_changed")
self.set_value(self.index_of_table, self.table_column, 
int(adj.get_value()))


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Editable SpinButton on a TreeView: detect *every* changes

2016-11-14 Thread Pozz Pozz
I created with success a TreeView based on a ListStore. One column has a
SpinButton (actually a GtkCellRendererSpin).

Now I want to detect when the user *is* changing the value, i.e. every time
he clicks on + or - buttons.

If I connect the "edited" signal, my callack will be called only when the
spin button is "unfocused". I lost every clicks.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list