Vala Getting Started

What is Vala?

Vala is a new programming language that allows modern programming techniques to be used to write applications that run on the GNOME runtime libraries, particularly GLib and GObject. This platform has long provided a very complete programming environment, with such features as a dynamic type system and assisted memory management.

https://wiki.gnome.org/Projects/Vala/ValaOnLinux

To install the most recent version of Vala you should add the Vala Team PPA to your software sources:

$ sudo add-apt-repository ppa:vala-team

On some older versions of Ubuntu you may need to install the add-apt-repository tool first:

$ sudo apt-get install software-properties-common

Then you can install the latest version:

$ sudo apt-get update
$ sudo apt-get install valac

Getting Started:creating and distributing apps for elementary OS.

https://elementary.io/docs/code/getting-started/#what-we-will-and-wont-cover

The Basic Setup
- Creating an account on GitHub and importing an SSH key
- Setting up the Git revision control system
- Getting and using the elementary developer “SDK”

Development Libraries
$ sudo apt install elementary-sdk

Hello World

The first app we’ll create will be a basic and generic “Hello World”.

Setting Up
1. Create your root folder called “gtk-hello”
2. Create a folder inside that one called “src”. This folder will contain all of our source code.

Create a new file in Scratch and save it as “gtk-hello.vala” inside your “src” folder

int main(string[] args){
   Gtk.init(ref args);
   //Gtk.Window
   var window = new Gtk.Window();
   window.title = "Hello World!";
   window.set_border_width (12);
   window.set_position (Gtk.WindowPosition.CENTER)
   window.set_default_size (350, 70);
   window.destroy.connect (Gtk.main_quit);

   //Gtk.Button
   var button_hello = new Gtk.Button.with_label ("Click me!");
   button_hello.clicked.connect (() => {
      button_hello.label = "Hello World!";
      button_hello.set_sensitive (false);
   });

   window.add (button_hello);
   window.show_all();

   Gtk.main();
   return 0;
}

Compiling and Running your code

$ cd ~/Projects/gtk-hello/src

$ valac --pkg gtk+-3.0 gtk-hello.vala
$ ./gtk-hello

Pushing to GitHub

  1. First we need to create a new repository on GitHub. Visit the new repository page and create a new repository for your code.

  2. Open Terminal and make sure you’re in your project’s root directory “~Projects/gtk-hello”, then issue the following commands

$ git init
$ git add src/gtk-hello.vala
$ git commit -m "Create initial structure. Create window with button."
$ git remote add origin git@github.com:yourusername/yourrepositoryname.git
$ git push -u origin master

Remember to replace yourusername with your GitHub username and yourrepositoryname with the name of the new repository you created.

Leave a Reply