Re: Template Widgets inside another GtkBuilder file

2015-10-07 Thread Victor Aurélio Santos
So the really question becomes, how to get `g_type_ensure` generated
in output code when subclassing Widgets in Vala ?

2015-10-05 17:54 GMT-03:00 Victor Aurélio Santos :
> Emmanuele,
>
>> In order to do that, you should use `g_type_ensure()` inside the
> instance initialization function of the parent's widget class
>
> Since using Vala, from what I can see in case of using [GtkTemplate]
> the g_type_ensure is generated, but when just subclassing a GtkWidget
> it doesn't exists in the generated .c, am I right ?
>
> And what I can do to g_type_ensure be present in generated .c in the
> second case ?
>
> Thanks.
>
> 2015-10-04 10:40 GMT-03:00 Emmanuele Bassi :
>> Hi;
>>
>> On 3 October 2015 at 02:14, Victor Aurélio Santos
>>  wrote:
>>> How can I do that ?
>>> Just build all together results in this warning:
>>>
 (ajami:3475): Gtk-CRITICAL **: Error building template class 
 'AjamiMainWindow' for an instance of type 'AjamiMainWindow': Invalid 
 object type 'HVMeter' on line 2
>>>
>>> I've asked on SO[1] and got only one answer.
>>>
>>> I stick at "_get_type" workaround/hack but I didn't like it and I
>>> can't do the same thing in Vala (I've not found how to do the same
>>> thing).
>>>
>>> More details can be found on SO question.
>>>
>>> So, what I really want to know is what is the best option to
>>> accomplish this in Vala and in C too.
>>>
>>> [1]: 
>>> http://stackoverflow.com/questions/24235937/custom-gtk-widget-with-template-ui
>>
>> If you have an internal, private widget that you use as a child in a
>> template, you'll need to ensure that the type system knows about the
>> child widget's type before initializing the template that references
>> it.
>>
>> In order to do that, you should use `g_type_ensure()` inside the
>> instance initialization function of the parent's widget class, right
>> before calling `gtk_widget_init_template()`; for instance:
>>
>>   g_type_ensure (hv_meter_get_type ());
>>
>> This is also what GTK+ itself does:
>> https://git.gnome.org/browse/gtk+/tree/gtk/gtkfilechooserwidget.c#n8598
>>
>> Ciao,
>>  Emmanuele.
>>
>> --
>> https://www.bassi.io
>> [@] ebassi [@gmail.com]
>
>
>
> --
> Victor Aurélio Santos



-- 
Victor Aurélio Santos
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Template Widgets inside another GtkBuilder file

2015-10-05 Thread Victor Aurélio Santos
Emmanuele,

> In order to do that, you should use `g_type_ensure()` inside the
instance initialization function of the parent's widget class

Since using Vala, from what I can see in case of using [GtkTemplate]
the g_type_ensure is generated, but when just subclassing a GtkWidget
it doesn't exists in the generated .c, am I right ?

And what I can do to g_type_ensure be present in generated .c in the
second case ?

Thanks.

2015-10-04 10:40 GMT-03:00 Emmanuele Bassi :
> Hi;
>
> On 3 October 2015 at 02:14, Victor Aurélio Santos
>  wrote:
>> How can I do that ?
>> Just build all together results in this warning:
>>
>>> (ajami:3475): Gtk-CRITICAL **: Error building template class 
>>> 'AjamiMainWindow' for an instance of type 'AjamiMainWindow': Invalid object 
>>> type 'HVMeter' on line 2
>>
>> I've asked on SO[1] and got only one answer.
>>
>> I stick at "_get_type" workaround/hack but I didn't like it and I
>> can't do the same thing in Vala (I've not found how to do the same
>> thing).
>>
>> More details can be found on SO question.
>>
>> So, what I really want to know is what is the best option to
>> accomplish this in Vala and in C too.
>>
>> [1]: 
>> http://stackoverflow.com/questions/24235937/custom-gtk-widget-with-template-ui
>
> If you have an internal, private widget that you use as a child in a
> template, you'll need to ensure that the type system knows about the
> child widget's type before initializing the template that references
> it.
>
> In order to do that, you should use `g_type_ensure()` inside the
> instance initialization function of the parent's widget class, right
> before calling `gtk_widget_init_template()`; for instance:
>
>   g_type_ensure (hv_meter_get_type ());
>
> This is also what GTK+ itself does:
> https://git.gnome.org/browse/gtk+/tree/gtk/gtkfilechooserwidget.c#n8598
>
> Ciao,
>  Emmanuele.
>
> --
> https://www.bassi.io
> [@] ebassi [@gmail.com]



-- 
Victor Aurélio Santos
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Template Widgets inside another GtkBuilder file

2015-10-04 Thread Tristan Van Berkom
On Sat, Oct 3, 2015 at 10:14 AM, Victor Aurélio Santos 
 wrote:

How can I do that ?
Just build all together results in this warning:

 (ajami:3475): Gtk-CRITICAL **: Error building template class 
'AjamiMainWindow' for an instance of type 'AjamiMainWindow': Invalid 
object type 'HVMeter' on line 2


I've asked on SO[1] and got only one answer.

I stick at "_get_type" workaround/hack but I didn't like it and I
can't do the same thing in Vala (I've not found how to do the same
thing).



Hello Victor,

The regular way to do this is in fact to compile your app with 
gmodule-export-2.0.pc


I.e. adding `pkg-config --libs gmodule-export-2.0` to your link stage 
(using autotools you
would just add gmodule-export-2.0 to your regular pkg-config m4 macro 
invocations).


This indeed makes your applications global symbols visible so that they 
can be found using dlsym() on unices and other methods on other 
platforms.


Regarding the comment on the SO post, the deriving of the _get_type() 
function by the type name is not considered a heuristic but rather it 
is a standard, which is at least enforced in any code written in the 
last decade or so by way of the G_DEFINE_TYPE() macros (vala generated 
types will also comply with this standard). So, if you have a type 
which is named FooBar, and it's low level GType accessor is not 
correctly named foo_bar_get_type(), it is in fact the 
application/library code declaring the type which is at fault for not 
complying with this.


Granted, one can argument that documentation in this area is weak. Any 
other methods provided in GtkBuilder (such as overridable 
get_type_from_name() virtual methods) are specifically targeted at 
language bindings which need to resolve the type in other ways.


With all that said, it could be plausible to create some tooling 
perhaps which parses your builder files at compile time, perhaps 
generating a resource to be compiled into your app which could be 
automatically inspected at gtk_init() time, to automate the process of 
initializing the required types - and removing the requirement of 
exporting your symbols in the regular way - that's one approach I can 
imagine anyway, perhaps there are others, there would have to be 
interest and someone would of course have to write that code :)


I hope this clarifies the situation a bit more for you.

Best,
   -Tristan



___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Template Widgets inside another GtkBuilder file

2015-10-04 Thread Victor Aurélio Santos
I compiled now with gmodule-export-2.0.pc the symbols get exported:

nm -g build/src/ajami | grep '_get_type'
[...]
00429b30 T hv_meter_get_type

but when I try to launch I get the same error:
(ajami:30289): Gtk-CRITICAL **: Error building template class
'AjamiMainWindow' for an instance of type 'AjamiMainWindow': Invalid
object type 'HVMeter' on line 2

Thanks ;)

2015-10-04 6:56 GMT-03:00 Tristan Van Berkom :
> On Sat, Oct 3, 2015 at 10:14 AM, Victor Aurélio Santos
>  wrote:
>>
>> How can I do that ?
>> Just build all together results in this warning:
>>
>>>  (ajami:3475): Gtk-CRITICAL **: Error building template class
>>> 'AjamiMainWindow' for an instance of type 'AjamiMainWindow': Invalid object
>>> type 'HVMeter' on line 2
>>
>>
>> I've asked on SO[1] and got only one answer.
>>
>> I stick at "_get_type" workaround/hack but I didn't like it and I
>> can't do the same thing in Vala (I've not found how to do the same
>> thing).
>
>
>
> Hello Victor,
>
> The regular way to do this is in fact to compile your app with
> gmodule-export-2.0.pc
>
> I.e. adding `pkg-config --libs gmodule-export-2.0` to your link stage (using
> autotools you
> would just add gmodule-export-2.0 to your regular pkg-config m4 macro
> invocations).
>
> This indeed makes your applications global symbols visible so that they can
> be found using dlsym() on unices and other methods on other platforms.
>
> Regarding the comment on the SO post, the deriving of the _get_type()
> function by the type name is not considered a heuristic but rather it is a
> standard, which is at least enforced in any code written in the last decade
> or so by way of the G_DEFINE_TYPE() macros (vala generated types will also
> comply with this standard). So, if you have a type which is named FooBar,
> and it's low level GType accessor is not correctly named foo_bar_get_type(),
> it is in fact the application/library code declaring the type which is at
> fault for not complying with this.
>
> Granted, one can argument that documentation in this area is weak. Any other
> methods provided in GtkBuilder (such as overridable get_type_from_name()
> virtual methods) are specifically targeted at language bindings which need
> to resolve the type in other ways.
>
> With all that said, it could be plausible to create some tooling perhaps
> which parses your builder files at compile time, perhaps generating a
> resource to be compiled into your app which could be automatically inspected
> at gtk_init() time, to automate the process of initializing the required
> types - and removing the requirement of exporting your symbols in the
> regular way - that's one approach I can imagine anyway, perhaps there are
> others, there would have to be interest and someone would of course have to
> write that code :)
>
> I hope this clarifies the situation a bit more for you.
>
> Best,
>-Tristan
>
>
>



-- 
Victor Aurélio Santos
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Template Widgets inside another GtkBuilder file

2015-10-04 Thread Emmanuele Bassi
Hi;

On 3 October 2015 at 02:14, Victor Aurélio Santos
 wrote:
> How can I do that ?
> Just build all together results in this warning:
>
>> (ajami:3475): Gtk-CRITICAL **: Error building template class 
>> 'AjamiMainWindow' for an instance of type 'AjamiMainWindow': Invalid object 
>> type 'HVMeter' on line 2
>
> I've asked on SO[1] and got only one answer.
>
> I stick at "_get_type" workaround/hack but I didn't like it and I
> can't do the same thing in Vala (I've not found how to do the same
> thing).
>
> More details can be found on SO question.
>
> So, what I really want to know is what is the best option to
> accomplish this in Vala and in C too.
>
> [1]: 
> http://stackoverflow.com/questions/24235937/custom-gtk-widget-with-template-ui

If you have an internal, private widget that you use as a child in a
template, you'll need to ensure that the type system knows about the
child widget's type before initializing the template that references
it.

In order to do that, you should use `g_type_ensure()` inside the
instance initialization function of the parent's widget class, right
before calling `gtk_widget_init_template()`; for instance:

  g_type_ensure (hv_meter_get_type ());

This is also what GTK+ itself does:
https://git.gnome.org/browse/gtk+/tree/gtk/gtkfilechooserwidget.c#n8598

Ciao,
 Emmanuele.

-- 
https://www.bassi.io
[@] ebassi [@gmail.com]
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Template Widgets inside another GtkBuilder file

2015-10-02 Thread Victor Aurélio Santos
How can I do that ?
Just build all together results in this warning:

> (ajami:3475): Gtk-CRITICAL **: Error building template class 
> 'AjamiMainWindow' for an instance of type 'AjamiMainWindow': Invalid object 
> type 'HVMeter' on line 2

I've asked on SO[1] and got only one answer.

I stick at "_get_type" workaround/hack but I didn't like it and I
can't do the same thing in Vala (I've not found how to do the same
thing).

More details can be found on SO question.

So, what I really want to know is what is the best option to
accomplish this in Vala and in C too.

[1]: 
http://stackoverflow.com/questions/24235937/custom-gtk-widget-with-template-ui

-- 
Victor Aurélio Santos
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list