Web lists-archives.com

Re: Beginners guide

Hi Emmanuele,

I do agree with you but, From a beginners concept,The concept of Gtk-application and the handling of applications arguments is confusing coming from someone who is still learning from say - standard "C" as they are handled the same way in just about any example on a google search,  

When you combine this with the concept of main loop and instances that need to be created, controlled and destroyed then the complexity may be simple for an experienced programmer, but not to a beginner. 

In other words the original way is easy to understand what is actually going on, but the new way is complex and needs further explanation for a beginner to understand the concept and to be able to write and apply the code correctly.

These needs to be explained by a beginner for a beginner with input from experienced people with good example that explain what the steps are actually doing in the code and why you need to use them.

The beginners guide is a great start for this, thanks to the author, please do not stop.


On Fri, 2018-04-27 at 14:54 +0100, Emmanuele Bassi wrote:

thanks for your contributions: documentation is always welcome.

On 24 April 2018 at 19:39, Jim Reilly <jimreillyindevon@xxxxxxxxx> wrote:
I have put together a guide to help beginners to get started using gtk+3.0 in the hope that it might be useful. I do not have a web site through which I can make it available so I have attached it to this e-mail so that, if anyone thinks it is worth reading, they can make it accessible to others.

It would have been nicer to have some form of text source, in order to provide you with feedback.

In any case, here's a rough list of improvements to the examples and practices, to match the current best practices for GTK development:

> gcc program_name.c ­o program_name `pkg­config –cflags gtk+­3.0 –libs gtk+­3.0`

Be careful that your typesetting program is replacing `--` with `–`. Additionally, this is not really portable: compiler flags should always come first, followed by the sources, and then the linker flags; additionally, you *really* want to encourage developers to enable warnings. A command line you may want to use is:

    gcc -Wall `pkg-config --cflags gtk+-3.0` -o program_name program_name.c `pkg-config --libs gtk+-3.0`

> Basic program

I understand that dropping straight into GtkApplication may be weird, but it is *strongly* recommended to use the GApplication API to create even simple examples. Developers will be tempted to keep using gtk_init()/gtk_main() when porting from older versions of GTK; additionally, Linux applications are made of things like a binary, a desktop file, and a well-known name owned on the session bus. It's important that people write well-behaved applications, if they want to use features like application menus and notifications, or if they want to be ready for the near future when we'll be able to do proper session and resource management. A basic program using GtkApplication is not really any more complicated than a plain binary:

static void
on_activate (GApplication *app)
  GtkWidget *app_window = gtk_application_window_new (app);

  // populate the UI

  gtk_widget_show (app);

main (int argc, char *argv[])
  GtkApplication *app = gtk_application_new ("com.example.MyApp", 0);

  g_signal_connect (app, "activate", G_CALLBACK (on_activate), NULL);

  return g_application_run (G_APPLICATION (app), argc, argv);

And it will take care of handling things like "closing the window will terminate the application" for you, without having to go through delete-event.

> Events

The function declarations for the callbacks return `void`, but they should return `gboolean`, like the example does. You should also use `GDK_EVENT_STOP` and `GDK_EVENT_PROPAGATE` in lieu of `TRUE` and `FALSE`, respectively, to enhance readability.

> Missing content

You should point developers in the direction of GtkBuilder, for constructing your UI with XML (and Glade, if you don't want to hand-edit your UI definitions); menus should also be defined using XML and GtkBuilder, and associated to applications using the GtkApplication, GMenu, and GAction API; this allows creating menus that will automatically work on different platforms, as well as be easier to construct than a pile of GtkMenuItem and GtkMenu widgets.

There are various wiki pages that you may be interested in; see the "How Do I" section: https://wiki.gnome.org/HowDoI/

Thanks again for your work!


gtk-list mailing list
gtk-list mailing list