When creating new programs, I either use existing ones or when starting from scratch, a base template.
The following is the base template of writing a Seed program using GTK as the Graphical User interface. The code is the minimum required for a GTK application to work.
When the program is run, an empty window is produced.
A breakdown of the program is as follows:
var Gtk = imports.gi.Gtk; Gtk.init(null, null);
This imports the GTK library and initialises the object for use.
var window = new Gtk.Window();
This creates a variable called window that is set to gtk.Window. gtk.Window is the top level window which is used in most programs that have a GUI. There are others like gtk.Dialog which creates a dialog.
This connects the hide signal to a callback, in this case the function Gtk.main_quit which terminates the program, to the window. The hide signal is emitted when when the destroy button (usually x icon on top right hand side of title decoration is clicked on) or Alt + F4 is pressed.
Signals and callbacks will be explained in later post.
This 'shows' the window on the screen. This command is required when the program is first run so that you can see the window but will be used later on if you were to hide the window for some reason, say to display a prompt dialog, then to reshow it.
This ‘runs’ the window that was just created. It creates an infinite loop until something is done i.e. the close button is clicked on the window or it is terminated by user via the signal created before this line.