-
Notifications
You must be signed in to change notification settings - Fork 43
Learning from examples
Once you will have created your first gtk-fortran toy applications, you will need to use more widgets and GTK advanced features. Learning by reading and playing with gtk-fortran and GTK examples is a good way.
Let's have a look at some gtk-fortran examples available in the examples/
and plplot/
directories or the gtk-fortran-extra repository, starting from the simplest ones and moving progressively toward more complex examples.
Take gtkzero_gapp.f90 as a starting point. It just creates an empty GTK window with around 30 lines of Fortran code:
Then have a look at gtkhello.f90 which opens a window with two buttons. You will see how you can create buttons, arrange them in a box container and link them to callback functions.
These two examples are heavily commented in order to help you learn the GTK basics.
If you want to draw progressively a picture pixel by pixel during a long scientific computation, you should first work on the Drawing an image in a PNG file (without GUI) short tutorial to discover the GdkPixbuf library. Then the mandelbrot_pixbuf.f90 will show you how a GdkPixbuf can be drawn on a GtkDrawingArea via Cairo.
The mandelbrot_pixbuf_zoom.f90 is more elaborated as it shows how to manage the mouse and keyboard to zoom in the Mandelbrot set.
The simplest example to learn to make vector graphics is the cairo-basics.f90 example, which just open a window and draws lines, circles, bezier curves and text using the Cairo library. It draws on screen but also in a SVG file and a PDF file:
You can also study the Unknown Pleasures example in the gtk-fortran-extra repository (MIT license).
The cairo-tests.f90
example demonstrates it is possible to mix bitmap and vectorial drawing on the same GtkDrawingArea.
When you will feel ready to work on more complicated graphical user interfaces, the julia_pixbuf.f90 will be a good starting point. It combines bitmap drawing, buttons, combo-boxes, spin buttons, grid layout, text view, tabs, etc.
You can also study the Saville Code example in the gtk-fortran-extra repository (MIT license).
The menubar.f90 and notebooks.f90 examples explore specific widgets and show how to create a menu and how to manage notebooks with tabs.
In the gtk-fortran-extra repository (MIT license), you will find:
-
my_fast_app
: an example for a fast computation (ideally < 1 second). In that case, you can use the GtkApplication API. -
my_long_app
: an example for long computations, with a picture that is updated regularly. In that case you must manage the events of the GLib main loop to keep the GUI reactive during the computation. -
parallel_app/
demonstrates how you can use parallel Fortran 2008 and 2018 features (coarrays, collective routines...) in a gtk-fortran application.
You can also run the gtk4-demo
command (gtk-4-examples
package in Ubuntu) to launch each official GTK example and read directly its C source code.
- Installation
- My first gtk-fortran application
- Drawing an image in a PNG file (without GUI)
- A program also usable without GUI
- Using Glade3 and gtkf-sketcher (GTK 3)
- Using gtk-fortran as a fpm dependency
- Debugging with GtkInspector
- Learning from examples
- Video tutorials
- How to start my own project from a gtk-fortran example
- git basics
- CMake basics
- Alternatives to CMake
- How to migrate to GTK 4
- How to contribute to gtk-fortran
- How to hack the cfwrapper