clear() on TreeView causes select-events

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

clear() on TreeView causes select-events

Gtk+ - Apps Dev mailing list
Hello

I observer an interesting behavior (PyGObject, Gtk3.0, Python3.6,
Debian unstable with XFCE desktop):

An item (row) in a TreeView is selected (highlighted).
Then calling .clear() on the TreeView causes an select-event for each
item (row) below that selected item (row).

Am I right here?
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: clear() on TreeView causes select-events

Reuben Rissler
On 07/03/2018 05:30 PM, c.buhtz--- via gtk-app-devel-list wrote:
> Hello
>
> I observer an interesting behavior (PyGObject, Gtk3.0, Python3.6,
> Debian unstable with XFCE desktop):
>
> An item (row) in a TreeView is selected (highlighted).
> Then calling .clear() on the TreeView causes an select-event for each
> item (row) below that selected item (row).
I have had very similar experiences with liststore.clear() in Python3.5
and Mint 18. To work around this I do:

store = treeview.get_model()  #may not be necessary in your code
treeview.set_model(None)
store.clear()
store.append('my string or etc')
treeview.set_model(store)

Disclaimer > I have no original code. I glean ideas from other people,
and pass them on. Please keep the circle going :)
>
> Am I right here?
> _______________________________________________
> gtk-app-devel-list mailing list
> [hidden email]
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
>

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: clear() on TreeView causes select-events

Gtk+ - Apps Dev mailing list
Dear Reuben,

thanks for your hint.

On 2018-07-03 21:19 Reuben Rissler <[hidden email]> wrote:
> I have had very similar experiences with liststore.clear() in
> Python3.5 and Mint 18. To work around this I do:
>
> store = treeview.get_model()  #may not be necessary in your code
> treeview.set_model(None)
> store.clear()
> store.append('my string or etc')
> treeview.set_model(store)

This works. Disconnecting the "model" from the "view" before doing
clear is the key. But very uncomfortable.

What not worked was to unselect before doing clear. I don't understand
why.

This all sounds to me like a mystic behaviour what could be a bug. But
I am not deep enough into Gtk so I won't open an official report about
this. It is on the core devs and experts in that list to decide if this
is an serious issue or not.

kind
Christian
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: clear() on TreeView causes select-events

Reuben Rissler

>> I have had very similar experiences with liststore.clear() in
>> Python3.5 and Mint 18. To work around this I do:
>>
>> store = treeview.get_model()  #may not be necessary in your code
>> treeview.set_model(None)
>> store.clear()
>> store.append('my string or etc')
>> treeview.set_model(store)
> This works. Disconnecting the "model" from the "view" before doing
> clear is the key. But very uncomfortable.
>
> What not worked was to unselect before doing clear. I don't understand
> why.
>
> This all sounds to me like a mystic behaviour what could be a bug. But
> I am not deep enough into Gtk so I won't open an official report about
> this. It is on the core devs and experts in that list to decide if this
> is an serious issue or not.
>
I agree with you. However, since I found this code on a Gtk website,
specifically for common problems with using Gtk, I assume it is the
recommended way. I don't remember where I found it or I would post a link.

And after you study the MVC pattern, you will see why the whole Treeview
stack works the way it does. Google MVC and Gtk MVC. It is worthwhile
reading if you plan on constructing treeviews. It may not make sense
immediately, but eventually you may see the light like I did.

Reuben

_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Reply | Threaded
Open this post in threaded view
|

Re: clear() on TreeView causes select-events

Gtk+ - Apps Dev mailing list
Dear Reuben,

thanks for your answer.

> And after you study the MVC pattern, you will see why the whole
> Treeview stack works the way it does. Google MVC and Gtk MVC. It is
> worthwhile reading if you plan on constructing treeviews. It may not
> make sense immediately, but eventually you may see the light like I
> did.

This is an often made misunderstanding.
Gtk (and every other GUI-lib) only implements the V (and sometimes the
C) in the MVC-Pattern. Gtk.ListStore is not a model in the meaning of
the MVC pattern!
One advantage of the MVC is that you can replace each layer/component
with another one. This is not possible when all components of the MVC
pattern are impelmented with the same lib (e.g. Gtk).

For example imagine: You want to replace the Gtk-View (Gtk.TreeCtr) with
another GUI-lib, or with a VirtualReality view or just a audio-view
(speak the content of the Tree).
_______________________________________________
gtk-app-devel-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list