Re: Beginners guide



Hi;

thanks for your contributions: documentation is always welcome.

On 24 April 2018 at 19:39, Jim Reilly <jimreillyindevon gmail com> 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);
}

int
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!

Ciao,
 Emmanuele.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]