[GtkD] How to connect to notify::active signal?

Geert via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Sep 8 06:40:12 PDT 2016


On Saturday, 4 May 2013 at 09:59:12 UTC, Mike Wey wrote:
> On 05/04/2013 05:20 AM, Alexandr Druzhinin wrote:
>> 04.05.2013 1:18, Mike Wey пишет:
>>> On 05/03/2013 06:30 PM, Alexandr Druzhinin wrote:
>>>> I need to connect to "notify::active" signal for Switch 
>>>> widget to
>>>> process changing of its state. The guides say I shouldn't 
>>>> use onActivate
>>>> signal, but "notify:active". But I didn't find a way to do 
>>>> it. Can
>>>> somebody help with it?
>>>
>>> Are you referring to gtk.Switch ?
>>>
>> yes, gtk.Switch
>> if I connect to activate signal by means addOnActivate nothing 
>> works.
>> Documentation says I should use "notify::active" event (it 
>> belongs to
>> ObjectG, as I understand?), but I cannot find a way to connect 
>> to this
>> signal by means of GtkD.
>
> You can use addOnNotify it currently doesn't allow you to 
> specify the property for witch you want to receive the signal 
> (it probably should).
>
> For now you could do:
>
> Switch sw = new Switch();
> sw.addOnNotify(&notify);
>
> void notify(ParamSpec param, ObjectG obj)
> {
> 	if(param.getName() == "active")
> 	{
> 		//Do stuff
> 	}
> }



Hi!

I would like to share a small example of this:



module gtkd_switch;
// Compile: ldc -w  main.d  `pkg-config --cflags --libs gtkd-3`

import std.stdio;
import gtk.Builder;
import gtk.Main, gtk.Window, gtk.Switch, gtk.Widget;
import gobject.ObjectG ,gobject.ParamSpec;


void on_swt_change(ParamSpec param, ObjectG obj, Switch 
*obj_switch){
     bool state = obj_switch.getActive();
     writefln("Changed! %b", state);
}

void main(string[] args) {
     Main.init(args);

     Builder g = new Builder();
     g.addFromFile("vista.glade");

     // Widgets from glade file "vista.glade":
     Window w = cast(Window)g.getObject("window1");
     w.setDefaultSize(320, 80);
     w.setTitle("Gtkd Switch addOnNotify");
     Switch swt = cast(Switch)g.getObject("swt_test");

     // Actions:
     w.addOnHide( delegate void(Widget aux){ Main.quit(); } );
     swt.addOnNotify(delegate void (ParamSpec, 
ObjectG){on_swt_change(ParamSpec, ObjectG, &swt);}, "active");

     w.showAll();
     Main.run();
}







More information about the Digitalmars-d-learn mailing list