ToshioCP / Gtk4-tutorial

GTK 4 tutorial for beginners
https://toshiocp.github.io/Gtk4-tutorial/
572 stars 50 forks source link

GtkListView with editable text examples for our books #33

Closed StefanSalewski closed 1 year ago

StefanSalewski commented 2 years ago

Dear Mr. Toshio,

some weeks ago I created my first GtkColumnView example. I will use that for my SDT tool, and additional use it for a section of my GTK4 book. But I think before introducing ColumnView in my book, I should introduce GtkListView. The whole GtkListView and GtkColumnView stuff is unfortunately not that easy, and the official introductions are not that great and incomplete. I think your GtkListView introduction is currently the best what we have -- as it provides complete examples with and without the use of XML UI files.

One related question: For my own GtkColumnView Nim code, I needed editable text. One way to get editable text is to use the GtkText widget, connect the activate signal to the GtkText widgets, and use ID numbers assigned in the "bind" callback to store the edited text where we need it. I think for a GtkListView editable entries are rarely needed, but still I wonder how we could change your examples (preferable the fist one, without use of UI files) to use editable text and to save the edits in the model. Is there some property binding available, or would you have to use the activate signal of the GtkEntry widget to store the edited strings somehow?

I can currently not remember if your GtkListView example allows adding new rows dynamically, and to delete rows. I think your example does not support that currently, but it would be really useful. Reordering rows by drag and drop would be nice as well, but not that important. I have never used drag and drop myself in Nim before, but maybe it is time to learn it. I found a Python example recently (https://discourse.gnome.org/t/reorder-rows-in-a-list-gtk4/8422/4), so it seems to work.

Unfortunately I will have not much free time in the next months to work on my GTK4 or Nim book, or on the SDT tool. But I will try to continue next year. This summer I unfortunately spent my full holiday on my old tiny chess engine. Maybe wasted time, but the old code which I created seven years ago was just too ugly, and I feel better with the new version :-) And from time to time it is just fun to play some chess against the computer, even when the current GTK GUI is very restricted.

Best regards,

Stefan Salewski

ToshioCP commented 2 years ago

Dear Dr. Salewski

Thank you for posting the issue.

How to embed GtkText into GtkListView.

I did it in my program tcsv before. It is in the GitHub repository tcsv. But I've almost forgotten what I did because I made it more than a year ago. One thing I remember is I used GtkSignalListItemFactory, not GtkBuilderListItemFactory. Because GtkSignalListItemFactory is more flexible than GtkBuilderListItemFactory. I think that it is very difficult (or impossible) to use GtkBuilderListItemFactory for GtkText.

If you see 'tcsv' source (tcsvrecdialog.c and tcsvrecdialog.ui), you will probably find my solution.

But tcsv is a developing version program. And it might include bugs. It is possible that there's a better solution to embed GtkText into GtkListView.

Adding or deleting rows is the matter of the list connecting to the GtkListView. So, if you add items to or remove from the list, GtkListView reflects that.

That's all I can say at present. If I find more information, I'll write it in this issue or email you.

Toshio Sekiya

ToshioCP commented 1 year ago

The technique how to embed GtkText into GtkListView or GtkColumnView is written in section 30 (new section). And adding or removing items in a list is also included in the sample program (listeditor.c). In addition, it explains how to reflect the changes in the list to the GtkListView (or GtkColumnView) dynamically.

Another repository tcsv is thoroughly updated and you can see how to program things above, too.

So, I think this issue has been solved and is closed.

Toshio Sekiya