Skip to content
This repository

Home 

vmagnin edited this page · 30 revisions

The gtk-fortran project aims to offer scientists programming in Fortran a cross-platform library to build Graphical User Interfaces (GUI). Gtk-fortran is a partial GTK+ / Fortran binding 100% written in Fortran, thanks to the ISO_C_BINDING module for interoperability between C and Fortran, which is a part of the Fortran 2003 standard. GTK+ is a free software cross-platform graphical library available for Linux, Unix, Windows and Mac OS X.

gtk-fortran offers currently an interface to more than 8700 GTK+ 2 and GTK+ 3 functions (GTK, GDK, GdkPixbuf, Cairo, Pango, ATK, GLib, GObject, GIO). These interfaces were automatically created by a python script which parses the C header files of the GTK+ libraries. gtk-fortran has already been tested under Linux, Mac OS X, Windows 7, on 32 bits and 64 bits machines, and on Big-endian and Little-endian machines. See the list of Tested functions and the Status page for more informations. gtk-fortran is distributed under GNU GPL 3 license. The wiki documentation is under the GNU Free Documentation License 1.3.

The second phase of the project is now concentrating on testing and writing examples. You can join our small community to share knowledge, skills and code: just create a github account and you will be able to post messages. Every good will is welcome.

julia_pixbuf.f90 example with gtk-fortran on Ubuntu 11.04julia_pixbuf.f90 example with gtk-fortran on Ubuntu 11.04

More Screenshots.

News

  • 07-28-2012: a new branch gtk2_24_glib2_32 has been created (deprecated functions have been deleted in GLib 2.32). gtk-fortran has been compiled and tested with Ubuntu 12.04 which is coming with gfortran 4.6.3, GTK+ 2.24.10 and GLib 2.32.3. The GTK+ 3.4.2 version is now under testing in the test branch.
  • 05-18-2012: NULL, CNULL, FNULL parameters replaced by the corresponding iso_c_binding names (c_null_ptr...) in all the files of the project (master and gtk3 branch).
  • 10-12-2011: gtk-fortran has been compiled and tested with Ubuntu 11.10 which is coming with gfortran 4.6.1, GTK+ 2.24.6 and GTK+ 3.2.0. The repository has been updated.
  • 06-03-2011: jtappin's RPN Scientific calculator is a good example of what can be done with gtk-fortran.
  • 05-19-2011: Added first version of the GTK+ Fortran code sketcher gtkf-sketcher.
  • 05-07-2011: Added tree widget and also table and notebook containers to gtk-hl.f90.
  • 04-24-2011: Added multi column list to gtk-hl.f90, also demo in examples/hl-list_n.f90.
  • 04-19-2011: Added Wiki page documenting gtk-sup.f90 Supplementary routines
  • 04-19-2011: gtk-fortran is now listed on the GTK+ Language Bindings page.

Older news

Installation

First, you need a Fortran compiler with the ISO_C_BINDING module. If your compiler is compliant with the Fortran 2003 standard, this module should be present. Else you can download gfortran, a free software compiler (see the links at the bottom of this page).

To download all the project files, click on Source (top left), then just below Switch branches to "master" if you use GTK+ 2 or "gtk3" for GTK+ 3, then click on the Downloads button on the right, then choose the .tar.gz or .zip archive depending on your system. The only files you absolutely need are gtk.f90 and the *-auto.f90 files. You can copy them in the same directory as your program or in a specific directory.

gtk-sup.f90 and gtk-hl.f90 are needed for list_demo.f90 and the hl-*.f90 files (see gtk_hl:-A-high-level-interface-for-Gtk-Fortran).

The usemodules.py python script can be useful to find which GTK+ functions are used in your programs (see advices to lower compilation time). Python scripts have been tested under Linux with python 2.6.6 and 2.7.2.

Linux

If you use the GNU Fortran compiler, you need gfortran 4.6 or higher. Recent distributions like Fedora 15 and Ubuntu 11.10 come with it. You also need to install the GTK+ development files (Ubuntu example):

sudo apt-get install gfortran libgtk2.0-dev libgtk-3-dev

If your distribution comes with a lower gfortran version, you can download the install file or the 64-bit version, and install it by typing something like:

sudo tar -xzvf gfortran-4.6-20110107-linux-i686.tar.gz -C / 

The path to the compiler is then /usr/local/bin/gfortran

Notes:

  • depending on your installation, you may also need the packages libmpc2 and libmpfr1ldbl.
  • gtk-fortran has also been tested with the compilers:
    • Intel Fortran 12.0.0 on x86-ubuntu-maverick (bdsatish, 02-14-2011).
    • g95 version 0.93, Ubuntu x86_64 (bonanza, 02-17-2011).
    • g95 (2010-06-16 debian version), Ubuntu 10.10, 32 bits (vmagnin).

Windows

All the examples were tested under Windows 7 (32 bits) using gfortran 4.6.0 20110115 (experimental) and the dll of GTK+ 2.22.1, put in the src directory. You can use the test.bat batch file.

You can download the all-in-one GTK+ 2.22 bundle at http://www.gtk.org/download/win32.php. More recent versions of some individual libraries (GTK+ 2.24) can be found at http://ftp.gnome.org/pub/gnome/binaries/win32/gtk+/.

Note that for high-level examples you need GTK+ 2.18 or higher, and 2.24 for gtkbuilder2.f90 and julia_pixbuf.f90.

Mac OS X

The examples were tested under Mac OS X 10.6.7 (Darwin 10.7.0 on x86_64), with the quartz version of GTK2. gtk2 and gfortran 4.6 were built using macports.

Compilation

Linux

See the test.sh bash script to compile all the library and all examples using gfortran (test95.sh for g95).

Windows

See the test.bat script to compile all the library and all examples.

Advices to lower compilation time

Concerning the names of the modules you need, you can generally just look at the beginning of the names of the functions you use: gtk_window_new is in the gtk module, cairo_curve_to is in cairo... Note that all enumerators are currently in the gtk module.

gtk-fortran modules offering interfaces to more than 8000 functions, you should add to your USE statements the ONLY option, e.g.:

use gtk, only: gtk_init, gtk_window_new, GTK_WINDOW_TOPLEVEL, gtk_window_set_title, &
      & gtk_container_set_border_width, g_signal_connect, gtk_hbox_new, gtk_container_add, &
      & gtk_button_new_with_label, gtk_box_pack_start, gtk_widget_show, gtk_main, FALSE, &
      & CNULL, TRUE

The compilation time will be ten times faster than with a simple "use gtk" statement ! To help you, the usemodules.py script can analyze your programs and generate the usemodules.txt file with the USE statements you need. Simply type for example:

python usemodules.py ../examples

But the script does not find all used symbols and you will generally need to complete the USE statements by hand. Note also that the compilation time with gfortran under Windows is ten times longer than under Linux (why ?)

Known issues or limitations

  • Very few GTK+ types are not yet implemented.
  • Macro functions (#define) are not implemented.
  • Structures (struct) are not implemented.
  • gstdio.h and giochannel.h were excluded because some functions are declared twice (UNIX and non UNIX systems for example).
  • 85 functions with optional arguments (variadic fuctions) are not implemented. Some of these functions are also available with an array argument to solve binding problems (for example gtk_list_store_new / gtk_list_store_newv), but not all. See http://live.gnome.org/GObjectIntrospection/WritingBindingableAPIs
  • Some enums are still missing, like GdkPixdataType.
  • All enums are in the gtk module. It would be better either to dispatch them in the right modules or to create an enums module.
  • g_signal_connect: should have been be declared as a function returning a c_long (handler_id).
  • Fortran has no unsigned integers, so problems could occur if you pass great values between Fortran and GTK+. See the tests.f90 file.
  • Missing deallocate in gtk_init() ? (g95 message when the program is quited).

See also the Issues page.

Roadmap

How can I help ?

  • We need people compiling and running the examples under various OS, architectures (32/64 bits...) and with various Fortran compilers. You can signal bugs.
  • You can write new examples or improve existing examples and share them with the community. Note that C examples are available in the applications gtk-demo and gtk3-demo (gtk-3-examples and gtk2.0-examples Ubuntu packages).
  • If you have knowledge about GIR format or XML parsing with python, your help can be precious for future versions.
  • You can simply talk to your colleagues of this new possibility of creating Graphical User Interfaces for their Fortran programs.
  • Put a link on your site to https://github.com/jerryd/gtk-fortran/wiki, and include the "gui" and "graphical user interface" keywords. It will improve the pagerank of the project in search engines.

History

This project is based on Tobias Burnus' post on comp.lang.fortran newsgroup (2nd May 2007 13:10) where he gave a little example of a Fortran 2003 program creating a minimalist GUI (an empty GTK window !) using ISO_C_BINDING. Vincent Magnin posted a message on the 27th December 2010 and got into contact with Jerry DeLisle on the 29th. They launched together the project in January 2011. Other contributors then joined: James Tappin, Jens Hunger...

License

Gtk-fortran is licensed under GNU General Public License version 3.

The gtk-fortran logo uses the GTK+ logo (by Andreas Nilsson) and so is also under GNU Free Documentation License Version 1.2 or later & Creative Commons Attribution-Share Alike 3.0 Unported license. The font is DejaVu Sans, a font under a free license.

FAQ

  • Why GTK+ rather than Qt or wxWidgets ? We chose GTK+ because it is written in C, so the binding is easier than with C++.
  • Is gtk-fortran only useful for GUI ? No because GTK+ includes the crossplatform GLib library which offers a lot of generic functions (regular expressions, random numbers, hash, strings, input/output...)

Useful links

Tools used in this project

Something went wrong with that request. Please try again.