What topic is necessary for gtk4 tutorials for beginners?

I am making a gtk4 tutorial for beginners on github (https://github.com/ToshioCP/Gtk4-tutorial).
I am happy if you give me advice.

I’ve put the following in the tutorial.

  • How to generate and run GtkApplication
  • Widgets and their parent-child relationship
  • Objects and their parent-child relationoship
  • Ui file and GtkBuilder
  • Signals. generating, emitting, connecting handlers
  • Meson build system
  • Menus and actions

In addition, what other topic is necessary for the tutorial for beginners?
I’m not an expert, I’m studying gtk4 at present and My knowledge about gtk4 is limited.
Therefore, your advice from the view of whole gtk4 is welcome.

Any other advice and/or suggestion is also appreciated.

I(m sorry if this topic is not appropriate for gnome discource.

Thank you very much.

10 Likes

Ui file and GtkBuilder would be nice because I do not really cover that in my GTK4 book yet. And maybe you can try to explain if/how Glade can be used with GTK4, as many people seem to like Glade.

And of course it would be nice if you could proof read my book. You may push issues or suggestions to github issue tracker.

[EDIT]

And explaining how users can best install GTK4 when package managers do not yet have GTK4. And how GTK4 can be best installed on Windows and Mac. And how users can debug their apps, how they can use valgrind and debug crashes.

1 Like

Thank you very much for your advice, Stefan.

I’ve already written about Ui files and GtkBuilder in my tutorial.
I would like to write about Glade, but maybe in the future.
Because gtk4 is really new and Glade might not work on gtk4 now, mightn’t it?

I will write how to install gtk4 on ubuntu soon.
However, I don’t know about windows and macos unfortunately.
So, it is impossible for me to write the installation to them.
If someone write them and add them to my tutorial, it is really helpful.

Anyway, thank you very much Stefan.
I will read your book soon.

Toshio

1 Like

GtkColumnView is a new control and will be used widely, maybe it’s a good idea for taking a tutorial for it.

Thank you Andy.

I haven’t used GtkColumnView yet.
I will study it and think about putting it in my tutorial.

Thank your for that work! It seems very helpful! I have put a link in the wiki of my gtk-fortran project.

Thank you Vincent.
I’m very happy to hear that.

A tutorial about drawing in GTK 4 could be useful:
https://blog.gtk.org/2020/04/24/custom-widgets-in-gtk-4-drawing/
I am still using Cairo (“Drawing the old-fashioned way”), but the advice seems now to use GtkSnapshot. They talk also about textures. And there is a gtk_snapshot_append_cairo() function which interests me in my own project because PLplot is offering a Cairo driver.

+1 for Meson.

At the end, we should have a section that build an application from the scratch based on concepts we cover. For example, Image Viewer, Text Editor, To Do, Note taking app, or Markdown Editor. This way, we know how to use concepts cover earlier in tutorial in action.

Hello, Vincent. Thank you for the post again.
I’ve read the blog and Gtk4 API document, and I’m thinking that there are two options for drawing.

  • Use GtkDrawingArea with Cairo.
  • Use GtkGLArea with OpenGL.

The blog describes that Gtk4 uses

void (* snapshot) (GtkWidget *widget, GtkSnapshot *snapshot)

instead of

gboolean (* draw) (GtkWidget *widget, cairo_t *cr)

in GtkWidgetClass.

This virtual function is used to draw the widget itself.
Therefore, it is necessary when you make your own Gtkwidget.

I’m not sure if this is useful for custom drawing in gtk4, but maybe the two options above are the common way.
If my understanding is wrong, please make a correction.

I’m planning to add an example of GtkDrawingArea and Cairo to my tutorial. It will take some time.

I hope you will have a great success in your project.

Toshio

1 Like

Thank you Kiran for the comment.

I agree.
Such applications are important for tutorals.

I’ve put a very simple text editor in the tutorial repository. The location is Gtk4-tutorial/src/tfe5. So, readers can try to compile and execute it if they download the whole tutorial files from the repository. And the list of the source file is in tfe5 source files.

However, it is obscure for readers to find it. I will soon add a link to the body of the tutorial and how to compile and execute the simple editor in section 14.

I’m planning to add another sample application to the tutorial. It is a simple turtle graphics interpreter. It includes custom drawing with GtkDrawingArea and Cairo. And I want to add very simple explanation about lexical analysis and parser generator.

Toshio

1 Like

Are you going to introduce the installation of GTK4 as well?

Thank you for the comment, Michael.

I put the gtk4 installation instruction into the tutorial four days ago (13/Jan/2021).
See Section 2.

The tutorial is under development and unstable.
It is frequently updated recently.
So, It is good for readers to see the repository itself, not the downloaded files.

I’d like to say thank you to all the readers of my tutorial. I want to add some information about it.

If you want to get the tutorial as html or pdf, see Readme_for_developers.md.
The instrution is as follows.

  • Prerequisite: ruby, rake, pandoc and pdflatex
  • Git clone or download zip from the git repository.
  • Change your current directory at the top of the downloaded files.
  • type rake html to generate html files under html directory.
  • type rake pdf to generate pdf files under latex directory.

However, the tutorial is unstable now. I think it is good for readers to see the repository directly at present.

1 Like

Thank you for the advice, Zetrov.

The most “necessary” thing is that you should try to incorporate them into official documents or wikis.

There are “tutorial” at the head of gtk4’s doc, and they are a lot of space to improve. Besides, anyone tries to use GTK may encounter them.

I think it’s very important to improve official documents and wikis. And maybe I could put some part of my tutorial into wikis. However, the tutorial in Gtk4 reference manual is like an introduction so it should be brief and to the point. It is not appropriate to put my whole tutorial into it.

In my experience, beginners who read the reference manual feel dificulties because of the lack of other basic concepts as GObject, GIO, Glib, Cairo and so on. Therefore, My tutorial includes them widely, not limited to gtk4. I don’t know such tutorials in the official gnome website so far. If there is a plan to make a tutorial like that in the official website, I want to make a contribution.

For now, I want to make effort to keep my tutorial corresponds to the latest gtk4 libraries.
Fortunately, I’m not so busy now and I’ll be able to do it for at least a couple of years.

2 Likes

When I am compiling Gdk-pixbuf after I type ninja -C _build I get the following:

ninja: Entering directory `_build’
[1/148] Generating gdk-pixbuf-marshal_c with a custom command
INFO: Reading …/gdk-pixbuf/gdk-pixbuf-marshal.list…
[4/148] Generating gdk-pixbuf-marshal_h with a custom command
INFO: Reading …/gdk-pixbuf/gdk-pixbuf-marshal.list…
[26/148] Generating gdk-pixbuf-csource-man with a custom command
FAILED: docs/gdk-pixbuf-csource.1
/usr/bin/xsltproc --nonet --stringparam man.output.quietly 1 --stringparam funcsynopsis.style ansi --stringparam man.th.extra1.suppress 1 --stringparam man.authors.section.enabled 0 --stringparam man.copyright.section.enabled 0 -o docs/gdk-pixbuf-csource.1 http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl …/docs/gdk-pixbuf-csource.xml
I/O error : Attempt to load network entity http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
warning: failed to load external entity “http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
cannot parse http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
[27/148] Generating gdk-pixbuf-query-loaders-man with a custom command
FAILED: docs/gdk-pixbuf-query-loaders.1
/usr/bin/xsltproc --nonet --stringparam man.output.quietly 1 --stringparam funcsynopsis.style ansi --stringparam man.th.extra1.suppress 1 --stringparam man.authors.section.enabled 0 --stringparam man.copyright.section.enabled 0 -o docs/gdk-pixbuf-query-loaders.1 http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl …/docs/gdk-pixbuf-query-loaders.xml
I/O error : Attempt to load network entity http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
warning: failed to load external entity “http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
cannot parse http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
[31/148] Compiling C object gdk-pixbuf/pixops/libpixops.a.p/pixops.c.o
ninja: build stopped: subcommand failed.

How can I fix this?

I can Open it with my Browser when I click on.

http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl

EDIT:
I managed to fix it with:

sudo apt-get upgrade docbook-xml docbook-xsl

Having beginner focused guide into Gtk would be great!

Being a Gtk “begginer” myself with little experience with C, my biggiest issue was getting familiar with GLib and GObject.

I have bought some books http://www.gtkbook.com/gtkbook/ which is old.

My biggiest issue was with:

  • Extensive usage of preprocessor macros. This is common thing in C but for beginner, it does a little bit too much to understand.
  • Getting familiar with how the type system works (partially because is is hidden behind macros).
  • Getting famaliar with the GObject inheritanc, interfaces and what are the limitations and how class conforms/interface conformance works.
  • What are the opaque boxes and how it works.

I understand, that this is not a strictly Gtk content, but fundamental for understanding how the Gtk works (imo).

1 Like

I used to read it also and was not bad at all.
anyway if you are interested in GTK3 then check this Videos

2 Likes

Dear Mikolas,

I think GObject API reference is the best for you. The reference is difficult but it has detailed explanation about GObject system and it also has a good tutorial. I couldn’t understand the content at the first reading. But I thought it was crucially important and read it again and again.

If you have questions, make your new topic. Then, members can help you a lot.

1 Like

Thanks for the reply :slight_smile:

I have read the reference and I agree that it is difficult to understand on the first glance. That is precisely my point however. Gtk is completely based on GLib and GObject paradigms.
The book I references is beginner focused too. It explains a lot about the basics - being GObject and GLib but it is out of date.

I think that Gtk in itsef is not that complicated at all. There is a lot of content about widget systems and the Gtk itself. However I failed to find anything up to date that would cover the GObject.