On Ubuntu Linux, I can use the Glade application to create a Hello World dialog. Now how do I get the D programming language to display it?
sudo apt-get install glade
, but more information about installing on the various other platforms is here.Note that the tools palette in Glade shows a Window widget and an ApplicationWindow widget. Since we're not drawing any menus, ensure you're using the Window widget instead of the ApplicationWidget. If you fail to do that, you'll get warnings when running the application, talking about some missing menu calls.
Save it as hello.glade.
<object class="GtkWindow" id="window1">
Write down on a piece of paper that id attribute.
import gtk.Builder;
import gtk.Main;
import gtk.Widget;
import gtk.Window;
import std.stdio;
int main (string[] args)
{
Main.init(args);
Builder b = new Builder();
b.addFromFile("hello.glade");
Window w = cast(Window)b.getObject("window1");
w.addOnHide( delegate void(Widget aux){ Main.quit(); } );
w.showAll();
Main.run();
return 0;
}
# dmd hello.d `pkg-config --cflags --libs gtkd3`
# ./hello
export NO_AT_BRIDGE=1
Now when you open the command prompt and run your compiled D command "hello" again, it will not show that error.
If you get errors regarding menus, then you used an ApplicationWindow widget instead of a Window widget, and will need to switch that in Glade.
The way I do it is to click on a widget in Glade, click Signals, find the event I want to add, such as clicked, and then in the Handler column, type in a function. For example, on a button1, I would type onButton1Clicked. Save the file.
Now, in your D source code, right after you create your Window object, add this code:
b.connectSignals(null);
...where b is your Builder variable.
extern(C) void onButton1Clicked()
{
writeln("got here");
Main.quit();
}
Note that in this case, the extern(C) is required.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With