Skip to content

Tutorial 3

Vincent Magnin edited this page May 12, 2022 · 3 revisions

A program also usable without GUI

You may need to write an application that can work both with a GTK 4 graphical user interface (GUI) and as a simple command line executable because you want to enjoy your graphical application on your desktop, but you also want to be able to run it on a machine where gtk-fortran is not installed, for example a distant machine via an ssh connection. You may also want to run a long computation without its GUI to reach full speed, as there can be some performance impediment when you draw heavily on screen.

Two applications are demonstrating that feature in our gtk-fortran-extra repository:

  • my_fast_app/: a gtk-fortran application for fast computations (ideally < 1 second). In that case, you can use the GtkApplication API. The activate() GUI callback function will call the scientific computing subroutine and draw the GUI and the graphical result. In the present case, it draws a Lorenz attractor, with three planar views and a text view. The command line version will simply print the x, y, z position of the final point.
  • my_long_app/: a gtk-fortran application for long computations, with a picture that is updated regularly. In that case you can not declare a GtkApplication: you must manage the events of the GLib main loop to keep the GUI reactive during the computation. The application is drawing a Buddhabrot. The command line version will finally save a picture in portable pixmap format (PPM).

These examples are under MIT license (contrarily to the gtk-fortran repository which is under GPL), so you can begin working on your own gtk-fortran application without worrying about license problems. You can pick an app and adapt it to your own needs (see How to start my own project from a gtk-fortran example? for more information).

Screenshots of those examples

Clone this wiki locally