You are here

Add new comment

Tutorial : develop in Vala/GTK+3 under Windows

Little tutorial for the Vala/GTK+3 bundle provided in a previous article...

Objectives : use a high-level programming language, GUI app "Windows & Linux-compatible" without source code hacking.

Let's begin under Windows. We will migrate to Linux in the following tutorial.

1) Install the Vala/GTK+3 bundle

Install : vala-0.12.0_(GTK+-3.4.2)(TARNYKO).exe (44,3 Mb)

Open a command line and type : valac. The following message should be returned :

No source file specified

2) Compile a basic Vala program

Create an empty text file, named test.vala . Open it with Notepad and fill it this way.

public class Post
   	public int id;
   	public string title;
   	public string content;

   	public void display ()
    		print (this.content);

We create a new "Post" class with three properties : id (integer), title and content (strings).
At the very end, a display () method prints the content property to screen. More details soon.

public static void main()
   	Post post001 = new Post ();
   	post001.content = "Welcome to my blog !";
   	post001.display ();

In the main method, we instantiate "Post" under the post001 name ; that is to say, we create a working copy we can use, using the new Post () syntax.

    (we NEVER WORK DIRECTLY with a class but with a class instance !)

Then, we strore a string in the content property and print it with the display () method.

Compile : open a command line, browse to the current folder and type : valac test.vala.
A test.exe executable file will be generated. Run it by typing test. This should return :

Welcome to my blog !

3) Compile a Vala/GTK+3 program

Create a new text file named testGTK.vala . Open it with Notepad and fill it this way.

using Gtk;

Let's use the Gtk library. I permits us to use its classes directly, by typing Window instead of Gtk.Window e.g..

Gtk.init (ref args);

Let's initialize GTK+.

var window = new Window (WindowType.TOPLEVEL);
window.set_default_size (320,200);
window.destroy.connect (Gtk.main_quit);

We instantiate the Window objects with specific WindowTypeTOPLEVEL attribute, then we call two of its methods to define a size of 320x200 and the action to take when it closes (quit).

Gtk.main ();

Let's really display the window with show_all (), then run the main GTK+ loop, waiting for events (click, etc...).

Compile : type valac --pkg gtk+-3.0 testGTK.vala.
Run it and...

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Enter the characters shown in the image.