Link Gtk.ListStore to the real data

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

Link Gtk.ListStore to the real data

c.buhtz
I am looking for an elegant and pythonic way to connect the model of a
Gtk.ListStore (the content container for a Gtk.TreeView) to the real
data.

Thinking the C-way I would store a pointer as a hidden column linking to
the data structure in each entry of Gtk.ListStore. But I don't see a
way to do this.

The data is just one or more lists of dictionaries. The point is that
the Gtk.ListStore can represent on complete data list or only a
selection of some entries of multiple data lists. It is important to
know that the entries doesn't have a unique key. A data list could look
like this:

data_list = [
    {
        'title': 'A title',
        'read_status': False
    },
    {
        'title': ....
    }]

Imagine news or mail messages. The font is bold if 'read_status' is
False and otherwise. When I click on an entry in the Gtk.TreeView the
font is modified from bold to normal. But the entry in the data list
should know this also! But how does the Gtk.TreeView or the
Gtk.ListStore entry know the real data?

How do you solve such problems?

I could create unique keys for each data list entry and store this keys
in a hidden column in the Gtk.ListStore. But this would blow up the
(real) code and would cause some other problems I need to deal with.
What is about pythons id() function? Or is there any other solution?
_______________________________________________
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: Link Gtk.ListStore to the real data

c.buhtz
I opened a question on StackOverflow about this and created a (not so)
minimal working example for it there.
https://stackoverflow.com/q/50643938/4865723
_______________________________________________
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: Link Gtk.ListStore to the real data

c.buhtz
In reply to this post by c.buhtz
Does no one has an idea?
Am I the only one facing such problems?

https://stackoverflow.com/q/50643938/4865723

On 2018-05-31 23:59 <[hidden email]> wrote:

> I am looking for an elegant and pythonic way to connect the model of a
> Gtk.ListStore (the content container for a Gtk.TreeView) to the real
> data.
>
> Thinking the C-way I would store a pointer as a hidden column linking
> to the data structure in each entry of Gtk.ListStore. But I don't see
> a way to do this.
>
> The data is just one or more lists of dictionaries. The point is that
> the Gtk.ListStore can represent on complete data list or only a
> selection of some entries of multiple data lists. It is important to
> know that the entries doesn't have a unique key. A data list could
> look like this:
>
> data_list = [
>     {
>         'title': 'A title',
>         'read_status': False
>     },
>     {
>         'title': ....
>     }]
>
> Imagine news or mail messages. The font is bold if 'read_status' is
> False and otherwise. When I click on an entry in the Gtk.TreeView the
> font is modified from bold to normal. But the entry in the data list
> should know this also! But how does the Gtk.TreeView or the
> Gtk.ListStore entry know the real data?
>
> How do you solve such problems?
>
> I could create unique keys for each data list entry and store this
> keys in a hidden column in the Gtk.ListStore. But this would blow up
> the (real) code and would cause some other problems I need to deal
> with. What is about pythons id() function? Or is there any other
> solution? _______________________________________________
> 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: Link Gtk.ListStore to the real data

'-'
Hello. Can you make the data_list a field on your class? It's a list with indices, right? Then, on the iter you get from your selection, use gtk_tree_model_get_path and gtk_tree_path_get_indices. Finally get the item from your data_list by that index.

On June 2, 2018 3:09:25 PM GMT+03:00, [hidden email] wrote:

>Does no one has an idea?
>Am I the only one facing such problems?
>
>https://stackoverflow.com/q/50643938/4865723
>
>On 2018-05-31 23:59 <[hidden email]> wrote:
>> I am looking for an elegant and pythonic way to connect the model of
>a
>> Gtk.ListStore (the content container for a Gtk.TreeView) to the real
>> data.
>>
>> Thinking the C-way I would store a pointer as a hidden column linking
>> to the data structure in each entry of Gtk.ListStore. But I don't see
>> a way to do this.
>>
>> The data is just one or more lists of dictionaries. The point is that
>> the Gtk.ListStore can represent on complete data list or only a
>> selection of some entries of multiple data lists. It is important to
>> know that the entries doesn't have a unique key. A data list could
>> look like this:
>>
>> data_list = [
>>     {
>>         'title': 'A title',
>>         'read_status': False
>>     },
>>     {
>>         'title': ....
>>     }]
>>
>> Imagine news or mail messages. The font is bold if 'read_status' is
>> False and otherwise. When I click on an entry in the Gtk.TreeView the
>> font is modified from bold to normal. But the entry in the data list
>> should know this also! But how does the Gtk.TreeView or the
>> Gtk.ListStore entry know the real data?
>>
>> How do you solve such problems?
>>
>> I could create unique keys for each data list entry and store this
>> keys in a hidden column in the Gtk.ListStore. But this would blow up
>> the (real) code and would cause some other problems I need to deal
>> with. What is about pythons id() function? Or is there any other
>> solution? _______________________________________________
>> 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

--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
_______________________________________________
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: Link Gtk.ListStore to the real data

Gtk+ - Apps Dev mailing list
In reply to this post by c.buhtz

Try a relational database. Sqlite is an easy one to use. It can sort and save data to multiple tables. Use the list model and treeview to retrieve and view the data. That way the columns can be set up dynamically along with the renderer. Use SQL to update the database.

Eric
_______________________________________________
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: Link Gtk.ListStore to the real data

c.buhtz
In reply to this post by '-'
On 2018-06-02 20:07 '-' <[hidden email]> wrote:
> Can you make the data_list a field on your class? It's a list
> with indices, right? Then, on the iter you get from your selection,
> use gtk_tree_model_get_path and gtk_tree_path_get_indices. Finally
> get the item from your data_list by that index.

You mean e. g. if the first row in the view is selected then it must be
the first item in the 'data_list'?

In that case I have to take care about that the order of the data
items is the same then in the view. This is impossible because
 - the view can modify the ordering based on the columns
 - the view use more then one data_list at the same time.
_______________________________________________
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: Link Gtk.ListStore to the real data

'-'
Swap items in your data_list in response to rows-reordered signal on the model? As for data_list, in your example you have multiple sources but the data_list is only one, so working on it makes sense. Could you try applying these suggestions to your example so we can see what doesn't work?

On June 3, 2018 12:47:30 AM GMT+03:00, [hidden email] wrote:

>On 2018-06-02 20:07 '-' <[hidden email]> wrote:
>> Can you make the data_list a field on your class? It's a list
>> with indices, right? Then, on the iter you get from your selection,
>> use gtk_tree_model_get_path and gtk_tree_path_get_indices. Finally
>> get the item from your data_list by that index.
>
>You mean e. g. if the first row in the view is selected then it must be
>the first item in the 'data_list'?
>
>In that case I have to take care about that the order of the data
>items is the same then in the view. This is impossible because
> - the view can modify the ordering based on the columns
> - the view use more then one data_list at the same time.
>_______________________________________________
>gtk-app-devel-list mailing list
>[hidden email]
>https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
_______________________________________________
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: Link Gtk.ListStore to the real data

Lucky B.C
In reply to this post by c.buhtz
Well, what you want is a way to catch/handle the data that always changes
and you want to show it on screen in anytime, right? There's no good
solutions for that, I mean you must make an algorithm to do that by
yourself. Why? Don't always lets Gtk or QT or something else stores our
data because the users often do what we will not know. Remember Gtk is a
tool to render what you want to the user on the screen.

My recommendation you can use Json/Xml or something else for
storing/getting the data.

On Fri, Jun 1, 2018 at 4:59 AM, <[hidden email]> wrote:

> I am looking for an elegant and pythonic way to connect the model of a
> Gtk.ListStore (the content container for a Gtk.TreeView) to the real
> data.
>
> Thinking the C-way I would store a pointer as a hidden column linking to
> the data structure in each entry of Gtk.ListStore. But I don't see a
> way to do this.
>
> The data is just one or more lists of dictionaries. The point is that
> the Gtk.ListStore can represent on complete data list or only a
> selection of some entries of multiple data lists. It is important to
> know that the entries doesn't have a unique key. A data list could look
> like this:
>
> data_list = [
>     {
>         'title': 'A title',
>         'read_status': False
>     },
>     {
>         'title': ....
>     }]
>
> Imagine news or mail messages. The font is bold if 'read_status' is
> False and otherwise. When I click on an entry in the Gtk.TreeView the
> font is modified from bold to normal. But the entry in the data list
> should know this also! But how does the Gtk.TreeView or the
> Gtk.ListStore entry know the real data?
>
> How do you solve such problems?
>
> I could create unique keys for each data list entry and store this keys
> in a hidden column in the Gtk.ListStore. But this would blow up the
> (real) code and would cause some other problems I need to deal with.
> What is about pythons id() function? Or is there any other solution?
> _______________________________________________
> 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