LinuxQuestions.org
Support LQ: Use code LQCO20 and save 20% on CrossOver Office
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 10-15-2010, 10:53 PM   #1
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Rep: Reputation: 54
Vala + GTK "Hello World"


Is there any documentation on how to create this in Vala? I am clueless, as there is a HUGE lack of documentation on Vala in general, and even the little documentation there is is only partially written, except for this.

I decided to stick to Vala as my beginner's programming language to study, as it includes the necessary content I need (object-oriented, GNOME/GTK friendly) and I am studying it all I can. I am not posting any code right now; I plan to take other members' advice here and slowly write/test code before it goes into a new project.

Again: Any help is appreciated in creating a "Hello World" GTK window using Vala.
 
Old 10-16-2010, 02:21 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Right choice ! (Because I know nothing about Vala).
 
Old 10-16-2010, 07:39 AM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Distribution: Arch x86_64
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707
I'm not trying to push you, but you can also check out Python (a relatively beginner-friendly language). They have GTK+ bindings for it (and Qt bindings, too).
 
Old 10-16-2010, 07:50 AM   #4
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by MTK358 View Post
I'm not trying to push you, but you can also check out Python (a relatively beginner-friendly language). They have GTK+ bindings for it (and Qt bindings, too).
Python (as well as Perl in this case) are wrong choices - because too many forum participants know them.
 
Old 10-16-2010, 07:53 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Distribution: Arch x86_64
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707
I don't get your point.

And anyway, I was just making a suggestion, the OP may check it out if he wants to and might like it, or not.

Last edited by MTK358; 10-16-2010 at 07:54 AM.
 
Old 10-16-2010, 07:55 AM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by MTK358 View Post
I don't get your point.
 
Old 10-16-2010, 08:03 AM   #7
RockDoctor
Member
 
Registered: Nov 2003
Location: Minnesota, US
Distribution: Fedora, Ubuntu
Posts: 893

Rep: Reputation: 168Reputation: 168
Instead of python, you should have suggested genie. Compiles like vala, even uses the vala precompiler (or whatever it's called), but looks more like python and is even less well-documented than vala.
 
Old 10-16-2010, 11:17 AM   #8
graemef
Senior Member
 
Registered: Nov 2005
Location: Hanoi
Distribution: Fedora 13, Ubuntu 10.04
Posts: 2,352

Rep: Reputation: 129Reputation: 129
I know nothing about Vala but after a quick search I wondered if you had tried this
 
Old 10-16-2010, 11:45 AM   #9
MTK358
LQ 5k Club
 
Registered: Sep 2009
Distribution: Arch x86_64
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707
Quote:
Originally Posted by RockDoctor View Post
Instead of python, you should have suggested genie. Compiles like vala, even uses the vala precompiler (or whatever it's called), but looks more like python and is even less well-documented than vala.
I don't know Vala and never heard of Genie. Mostly because I'm more interested in Qt.
 
Old 10-16-2010, 12:54 PM   #10
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Original Poster
Rep: Reputation: 54
Got everything right here:

Code:
using GLib;
using Gtk;

public class HelloWorld : Object {
    public static int main(string[] args) {
        Gtk.init(ref args);
		
        var window = new Window(WindowType.TOPLEVEL);
        var label = new Label("Hello World");
		
        window.title = "Hello World";
        window.set_default_size(640, 480);
        window.position = WindowPosition.CENTER;
        window.destroy.connect(Gtk.main_quit);
		
        window.add(label);
        window.show_all();
		
        Gtk.main();
        return 0;
    }
}
Except for one problem:

Code:
HelloWorldGtk.vala:2.7-2.9: error: The namespace name `Gtk' could not be found
Is there some library I have to install? I already have libgtk3.0-dev installed.
 
Old 10-16-2010, 01:23 PM   #11
MTK358
LQ 5k Club
 
Registered: Sep 2009
Distribution: Arch x86_64
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707Reputation: 707
I looked at the Vala tutorial, and it said:

Code:
public class ClassName : GLib.Object
 
Old 10-16-2010, 01:24 PM   #12
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,123

Rep: Reputation: 407Reputation: 407Reputation: 407Reputation: 407Reputation: 407
Quote:
Originally Posted by Kenny_Strawn View Post
Got everything right here:

Code:
using GLib;
using Gtk;

public class HelloWorld : Object {
    public static int main(string[] args) {
        Gtk.init(ref args);
		
        var window = new Window(WindowType.TOPLEVEL);
        var label = new Label("Hello World");
		
        window.title = "Hello World";
        window.set_default_size(640, 480);
        window.position = WindowPosition.CENTER;
        window.destroy.connect(Gtk.main_quit);
		
        window.add(label);
        window.show_all();
		
        Gtk.main();
        return 0;
    }
}
Except for one problem:

Code:
HelloWorldGtk.vala:2.7-2.9: error: The namespace name `Gtk' could not be found
Is there some library I have to install? I already have libgtk3.0-dev installed.
I don't think Vala knows about gtk3.
 
Old 10-16-2010, 01:59 PM   #13
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Original Poster
Rep: Reputation: 54
Yeah, I kind of figured that Vala didn't know about GTK3 (yet), however, I do know that some programs (e.g. Mutter) that are part of the GNOME Shell JHBuild moduleset actually depend on Vala and have components written in Vala.

And also: If you type:

Code:
using GLib;
at the beginning of the program, you can just type "Object" since the compiler already knows that it's under GLib if you use GLib.

Last edited by Kenny_Strawn; 10-16-2010 at 02:16 PM.
 
Old 10-16-2010, 02:34 PM   #14
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Original Poster
Rep: Reputation: 54
I think I've found out the problem:

Code:
valac --pkg gtk+-3.0 HelloWorldGtk.vala
Apparently, I have to invoke this boldfaced argument to the compiler manually.
 
Old 10-16-2010, 03:08 PM   #15
Kenny_Strawn
Senior Member
 
Registered: Feb 2010
Location: /usa/ca/orange_county/lake_forest
Distribution: ArchBang, Google Android 2.1 + Motoblur (on Motortola Flipside), Google Chrome OS (on Cr-48)
Posts: 1,791
Blog Entries: 62

Original Poster
Rep: Reputation: 54
Okay, I also have libgtk2.0-dev installed, so I used it instead. I also found conflicting objects, (GLib.Object and Gtk.Object), so I had to specify "GLib.Object". After that, it compiled successfully. The one thing I like about Vala's error messages is that they're easy for newbies to understand, unlike GCC's. At least so far.

Of course, that doesn't mean I might run into some that aren't so.
 
  


Reply

Tags
gtk+ hello world, vala


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
printf( "Hello %s\n", "World" ) megacoder LinuxQuestions.org Member Intro 1 09-29-2010 11:16 AM
"Hello world message is not printing" while loading the modules inside kernel Nishant Desai Linux - Kernel 9 08-31-2009 01:38 PM
Is ".gz" archive file considered "World-Readable"? NightSky Linux - Newbie 4 12-06-2007 05:21 PM
The problem about "cairo" in installing of "GTK" :( zhuqlfeixia Linux - Hardware 1 01-28-2006 03:12 PM
problem "make"ing gtk+ "/usr/bin/env: perl -w" caid Linux - Newbie 8 07-29-2005 04:51 AM


All times are GMT -5. The time now is 06:02 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration