[prev in list] [next in list] [prev in thread] [next in thread] 

List:       gtk
Subject:    Re: Beginners guide
From:       Emmanuele Bassi <ebassi () gmail ! com>
Date:       2018-04-27 13:54:46
Message-ID: CALnHYQFVc7ozJ2SrM0NzFP+aTOyzFZ65cBhNNFBi9xLg7dKR-w () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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.

-- 
https://www.bassi.io
[@] ebassi [@gmail.com]

[Attachment #5 (text/html)]

<div dir="ltr"><div>Hi;<br><br></div>thanks for your contributions: documentation is \
always welcome.<br><div class="gmail_extra"><br><div class="gmail_quote">On 24 April \
2018 at 19:39, Jim Reilly <span dir="ltr">&lt;<a \
href="mailto:jimreillyindevon@gmail.com" \
target="_blank">jimreillyindevon@gmail.com</a>&gt;</span> wrote:<br><blockquote \
class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid \
rgb(204,204,204);padding-left:1ex">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.<br> <br></blockquote><div><br></div><div>It would have been nicer to have \
some form of text source, in order to provide you with feedback.<br><br></div><div>In \
any case, here&#39;s a rough list of improvements to the examples and practices, to \
match the current best practices for GTK development:<br><br>&gt; gcc program_name.c  \
­o program_name `pkg ­config –cflags gtk+ ­3.0 –libs gtk+ \
­3.0`<br><br></div><div>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:<br><br></div><div>      gcc -Wall `pkg-config --cflags gtk+-3.0` -o \
program_name program_name.c `pkg-config --libs \
gtk+-3.0`<br></div></div><br></div><div class="gmail_extra">&gt; Basic \
program<br><br></div><div class="gmail_extra">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&#39;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&#39;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:<br><br>```<br></div><div \
class="gmail_extra">static void<br></div><div class="gmail_extra">on_activate \
(GApplication *app)<br>{<br></div><div class="gmail_extra">   GtkWidget *app_window = \
gtk_application_window_new (app);<br><br></div><div class="gmail_extra">   // \
populate the UI<br></div><div class="gmail_extra"><br></div><div class="gmail_extra"> \
gtk_widget_show (app);<br></div><div class="gmail_extra">}<br><br></div><div \
class="gmail_extra">int<br></div><div class="gmail_extra">main (int argc, char \
*argv[])<br>{<br></div><div class="gmail_extra">   GtkApplication *app = \
gtk_application_new (&quot;com.example.MyApp&quot;, 0);<br><br></div><div \
class="gmail_extra">   g_signal_connect (app, &quot;activate&quot;, G_CALLBACK \
(on_activate), NULL);<br><br></div><div class="gmail_extra">   return \
g_application_run (G_APPLICATION (app), argc, argv);<br></div><div \
class="gmail_extra">}<br>```<br><br></div><div class="gmail_extra">And it will take \
care of handling things like &quot;closing the window will terminate the \
application&quot; for you, without having to go through delete-event.<br \
clear="all"></div><div class="gmail_extra"><br></div><div class="gmail_extra">&gt; \
Events<br><br></div><div class="gmail_extra">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.<br><br></div><div \
class="gmail_extra">&gt; Missing content<br></div><div \
class="gmail_extra"><br></div><div class="gmail_extra">You should point developers in \
the direction of GtkBuilder, for constructing your UI with XML (and Glade, if you \
don&#39;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.<br></div><div class="gmail_extra"><br></div><div class="gmail_extra">There \
are various wiki pages that you may be interested in; see the &quot;How Do I&quot; \
section: <a href="https://wiki.gnome.org/HowDoI/">https://wiki.gnome.org/HowDoI/</a><br></div><div \
class="gmail_extra"><br></div><div class="gmail_extra">Thanks again for your \
work!<br><br></div><div class="gmail_extra">Ciao,<br></div><div class="gmail_extra">  \
Emmanuele.<br></div><div class="gmail_extra"><br>-- <br><div \
class="gmail_signature"><a href="https://www.bassi.io" \
target="_blank">https://www.bassi.io</a><br>[@] ebassi [@<a href="http://gmail.com" \
target="_blank">gmail.com</a>]</div> </div></div>



_______________________________________________
gtk-list mailing list
gtk-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-list


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic