-
Notifications
You must be signed in to change notification settings - Fork 46
Tutorials
Having built and installed gtk-fortran following the wiki instructions, you know need tutorials to learn programming with gtk-fortran.
- As you have built the gtk-fortran library, we can already suppose you have a quite "recent" Fortran compiler, i.e. implementing the ISO_C_BINDING module (Fortran 2003) and some Fortran 2008 functions. In those tutorials, we will use
gfortran
. - You need
pkg-config
(orpkgconf
) because GTK is composed of many libraries. Such a tool will make easier writing the compilation command. - You need a text editor and a terminal.
- You need to be familiar with Fortran basics. If you are not, the Fortran-lang community offers good tutorials: https://fortran-lang.org/learn/
- Being familiar with the C language is not compulsory but having some knowledge of the C types and especially C pointers and functions prototypes will help you understanding the GTK documentation and the gtk-fortran programming.
- Those tutorials are for GTK 3, but the GTK 4 modifications are also given.
- Tutorial 1: my first gtk-fortran application. You will learn to create a GtkApplication with a window, some widgets and how to draw a bitmap image in Fortran.
You can begin by studying the examples available in the examples/
directory (gtk3 branch), beginning by gtkzero_gapp.f90 (just creates an empty GTK window) and gtkhello.f90 (a window with two buttons). Those simple examples are heavily commented in order to help you learn the GTK basics.
Note that in GTK 4, the recommended way to write a GTK program is using GtkApplication like in the gtkzero_gapp.f90 example: in the gtk3 branch, it's the only example using GtkApplication. Try to follow this example for your own programs in order to ease the porting to GTK 4.
If you want to draw progressively a picture pixel by pixel during a scientific computation, mandelbrot_pixbuf.f90 is a good starting point. You can even simply create a PNG file without creating any GUI, by using the GdkPixbuf library: see pixbuf_without_gui.f90.
- Fortran Tools - Chapter 16: GTK: this document edited by The Fortran Company contains a chapter about programming GTK GUIs using the gtk-fortran High Level interface and shows how to use Glade & GTKBuilder to design a GUI.
- How to use GTK-Fortran with Code::Blocks IDE
Some good blogs to learn GTK:
- The awesome Michael B. YouTube channel offers more than two hundreds video tutorials on GTK 3 (C language) !
- GtkDcoding - Musings of a GtkD Coder
- GTK Glade C Programming Tutorial
Books about GTK are rare. There is especially the Andrew Krause's book: the first one is about GTK 2 (excellent but now obsolete, oriented toward the C language), the second one is the GTK 3 edition but for Python:
- Andrew Krause, Foundations of GTK+ Development, Apress, 2007, ISBN-13: 978-1-59059-793-4, 630pp, $36.99 (eBook). You can download the C examples here. And you can have a look at the book on Google Books.
- David Ashley, Andrew Krause, Foundations of PyGTK Development - GUI Creation with Python, Apress, 2019, ISBN-13: 978-1-4842-4178-3, 563pp, $34.31. You can download the Python examples here. And you can have a look at the book on Google Books.
- The GTK Project
- Concerning designing a GUI, see GNOME Human Interface Guidelines.
- Drawing with GTK:
- Cairo documentation
- The Cairo graphics tutorial in C language.
- Gdk-pixbuf
- The official GTK Discourse Forum.
- The GTK official blog.
- A french GTK forum (developpez.com)
You also need to have some knowledge about the Fortran 2003 ISO_C_BINDING module. The first of these link is a good short introduction to this subject:
- John Reid, Interoperability with C, an introduction to ISO_C_BINDING.
- John Reid, The New Features of Fortran 2003.
- Fortran 2008 Standard Draft (WD 1539-1)
- Richard J. Hanson, Tim Hopkins, Numerical Computing with Modern Fortran. Philadelphia: SIAM, 2013, ISBN 978-1-611973-11-2
- Arjen Markus, Modern Fortran in Practice. 1st ed. Cambridge: Cambridge University Press, 2012. http://dx.doi.org/10.1017/CBO9781139084796.
- Michael Metcalf, John Reid, Malcolm Cohen, fortran 95/2003 explained. Oxford: Oxford University Press, 2004, ISBN 978-0-19-852693-3.
- 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 with other C libraries