Re: [Vala] getting started with vala and glade

2016-08-13 Thread Luc Chante
Hi,

Just to reply to :
"...
- For setting properties on the parent in a constructor what is wrong with
   this.property_name = xyz;
..."
It is not wrong, but the behaviour is not exactly the same.

I get stuck on this before I realize the error.
When you use the constructed() method (to initialize ui by exemple), if you
use "this.something = some_arg", something isn't initialized in the
constructed() method, but it is when you use Object(something: some_arg).

Approximative generated C code for a class "Ns.ClassName" without Object()
call in the constructor :

NsClassName* ns_class_name_construct (GType object_type, type some_arg) {
NsClassName * self = NULL;
...
self = (NsClassName*) g_object_new (object_type, NULL);
...
ns_class_name_set_something (self, some_arg);
...
return self;
}

the constructed() method is called at the end of g_object_new(), so
ns_class_name_set_something() isn't called yet.

Same thing with a the use of Object() :

NsClassName* ns_class_name_construct (GType object_type, type some_arg) {
NsClassName * self = NULL;
...
self = (NsClassName*) g_object_new (object_type, "something", some_arg,
NULL);
...
return self;
}

In this case, when the constructed() method is called something has the
value some_arg.

Regards,
Luc.

Le lun. 27 juin 2016 à 17:30, Al Thomas  a écrit :

>
> --
> *From:* Luc Chante 
> *Sent:* Monday, 27 June 2016, 11:36
> *Subject:* Re: [Vala] getting started with vala and glade
>
>
> I think it would be a good start to use gtk templates.
> So you can use your ui file and create the ApplicationWindow by it's
> constructor (which takes an Application instance).
>
> Join to this mail a really simple example using ui file and gtk templates.
> Tested with msys 2.
>
> This is a great start for a code sample on the wiki, maybe:
> https://wiki.gnome.org/Projects/Vala/GTKTemplateSample
>
> As a code sample I have a couple of doubts about the current coding style:
>
>  - I think the main() method should be on its own, not buried in an object
>
>  - For setting properties on the parent in a constructor what is wrong with
>this.property_name = xyz;
>instead of using Vala specific GObject plumbing like Object(
> property_name: value );
>   Although these low level GObject features exist they add additional
> complexity when
>   initially learning the language and are unnecessary in most cases
>
> So a revised main.vala:
>
> /**
>  * Application
>  */
> public class MyApplication : Gtk.Application
> {
> public MyApplication(string? app_id = null, ApplicationFlags flags =
> ApplicationFlags.FLAGS_NONE)
> {
> if (app_id != null && Application.id_is_valid (app_id) == false) {
> error( "Application ID is not valid");
> }
> this.application_id = app_id;
> this.flags = flags;
> }
>
> public override void activate () {
> var window = new Template.ApplicationWindow (this);
> window.present ();
> }
> }
>
> /**
>  * Application window
>  */
> [GtkTemplate(ui = "/template/window.ui")]
> public class Template.ApplicationWindow : Gtk.ApplicationWindow
> {
> [GtkChild]
> Gtk.Button test_button;
>
> public ApplicationWindow(Gtk.Application application)
> {
> this.application = application;
> }
>
> [GtkCallback]
> public void on_test_button_clicked(Gtk.Button button)
> {
> GLib.message("Button clicked !!!");
> }
> }
>
> /** Application entry point */
> public static int main(string[] args)
> {
> var app = new MyApplication ("my.application");
> return app.run (args);
> }
>
> Finally as a more generic way to compile use:
>
> glib-compile-resources --sourcedir ./ --generate-source --target
> resources.c template.gresource.xml
> valac --pkg gtk+-3.0 --target-glib 2.38 --gresources
> template.gresource.xml resources.c main.vala --output myapp
>
> The Makefile is nice though.
>
> Regards,
>
> Al
>
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] getting started with vala and glade

2016-06-27 Thread Al Thomas

 
  From: Luc Chante 
 Sent: Monday, 27 June 2016, 11:36
 Subject: Re: [Vala] getting started with vala and glade
   
I think it would be a good start to use gtk templates.
So you can use your ui file and create the ApplicationWindow by it's
constructor (which takes an Application instance).

Join to this mail a really simple example using ui file and gtk templates.
Tested with msys 2.


This is a great start for a code sample on the wiki, 
maybe:https://wiki.gnome.org/Projects/Vala/GTKTemplateSample
As a code sample I have a couple of doubts about the current coding style:
 - I think the main() method should be on its own, not buried in an object
 - For setting properties on the parent in a constructor what is wrong with   
this.property_name = xyz;   instead of using Vala specific GObject plumbing 
like Object( property_name: value );  Although these low level GObject features 
exist they add additional complexity when 
  initially learning the language and are unnecessary in most cases
So a revised main.vala:
/**
 * Application
 */
public class MyApplication : Gtk.Application
{
    public MyApplication(string? app_id = null, ApplicationFlags flags = 
ApplicationFlags.FLAGS_NONE)
    {
    if (app_id != null && Application.id_is_valid (app_id) == false) {
        error( "Application ID is not valid");
    }
    this.application_id = app_id;
    this.flags = flags;
    }
 
    public override void activate () {
        var window = new Template.ApplicationWindow (this);
        window.present ();
    }
}
 
/**
 * Application window
 */
[GtkTemplate(ui = "/template/window.ui")]
public class Template.ApplicationWindow : Gtk.ApplicationWindow
{
    [GtkChild]
    Gtk.Button test_button;
 
    public ApplicationWindow(Gtk.Application application)
    {
        this.application = application;
    }
 
    [GtkCallback]
    public void on_test_button_clicked(Gtk.Button button)
    {
        GLib.message("Button clicked !!!");
    }
}
 
/** Application entry point */
public static int main(string[] args)
{
    var app = new MyApplication ("my.application");
    return app.run (args);
}

Finally as a more generic way to compile use:
glib-compile-resources --sourcedir ./ --generate-source --target resources.c 
template.gresource.xmlvalac --pkg gtk+-3.0 --target-glib 2.38 --gresources 
template.gresource.xml resources.c main.vala --output myapp
The Makefile is nice though.
Regards,
Al

   
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] getting started with vala and glade

2016-06-27 Thread Jürg Billeter
On Mon, 2016-06-27 at 00:23 +0200, Luca Bruno wrote:
> It does, it's reference counting. The main there is freeing the
> Thelma object right after run method is called.

Yes, however, the run method returns only when the application is about
to be terminated and thus, it's ok to free the Thelma object at that
point.

Regards,
Jürg
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] getting started with vala and glade

2016-06-26 Thread Al Thomas

 
  From: Chris Bare 
 Subject: [Vala] getting started with vala and glade
   
I have a very simple vala program that is trying to load a glade ui file.
The window appears briefly, but then the program exits without error.
What am I missing?


You need to add the ApplicationWindow to your Application. So add 
"this.add_window( window );":
using Gtk;

public class Thelma : Gtk.Application {
    protected override void activate () {
    var builder = new Builder ();
    builder.set_application( this );
    builder.add_from_file ("test.ui");
    var window = builder.get_object ("mainWindow") as ApplicationWindow;
    window.show_all ();
    this.add_window( window );
    }
}

public int main (string[] args) {
    return new Thelma().run (args);
}
The non Builder version did this with:var window = new Gtk.ApplicationWindow 
(this);
Regards,
Al

   
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] getting started with vala and glade

2016-06-26 Thread Ben Iofel
As OP said, if you run the commented out code it works fine.

On Sun, Jun 26, 2016 at 6:24 PM, Ben Iofel  wrote:

> The run method blocks, so it works fine. I've used this line in my own
> programs
>
> On Sun, Jun 26, 2016 at 6:23 PM, Luca Bruno  wrote:
>
>> It does, it's reference counting. The main there is freeing the Thelma
>> object right after run method is called.
>>
>>
>> Il lunedì 27 giugno 2016, Ben Iofel  ha scritto:
>>
>>> Vala does not have garbage collection, and the main() in the code
>>> example is fine
>>>
>>>
>>
>> --
>> NixOS Linux 
>>
>>
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] getting started with vala and glade

2016-06-26 Thread Luca Bruno
It does, it's reference counting. The main there is freeing the Thelma
object right after run method is called.

Il lunedì 27 giugno 2016, Ben Iofel  ha scritto:

> Vala does not have garbage collection, and the main() in the code example
> is fine
>
>

-- 
NixOS Linux 
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] getting started with vala and glade

2016-06-26 Thread Ben Iofel
Vala does not have garbage collection, and the main() in the code example
is fine

On Sun, Jun 26, 2016 at 3:10 PM, Luca Bruno  wrote:

> Il venerdì 27 maggio 2016, Chris Bare  ha scritto:
>
> > I have a very simple vala program that is trying to load a glade ui file.
> > The window appears briefly, but then the program exits without error.
> > What am I missing?
>
>
> Save the new Thelma() to a variable, otherwise it gets garbaeg collected.
>
>
> --
> NixOS Linux 
> ___
> vala-list mailing list
> vala-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/vala-list
>
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] getting started with vala and glade

2016-06-26 Thread Luca Bruno
Il venerdì 27 maggio 2016, Chris Bare  ha scritto:

> I have a very simple vala program that is trying to load a glade ui file.
> The window appears briefly, but then the program exits without error.
> What am I missing?


Save the new Thelma() to a variable, otherwise it gets garbaeg collected.


-- 
NixOS Linux 
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] getting started with vala and glade

2016-06-26 Thread pelzflorian (Florian Pelz)
Hello,

It seems you are missing a call to gtk_application_add_window. Probably
it’s add_window (window); or similar in Vala.

Regards,
Florian Pelz
___
vala-list mailing list
vala-list@gnome.org
https://mail.gnome.org/mailman/listinfo/vala-list