hauptmech
Joined: 14 Jan 2007 Posts: 20 Location: Wellington, NZ
|
Posted: Thu Jan 18, 2007 3:48 am Post subject: Q&A Simple dui code examples |
|
|
This code is my naive attempt at a D OOP style version of the gtk tutorial "helloworld.c" program.
It works but one piece is missing. The C code is inserted and commented out approximately where I think the corresponding D code should go. Can someone show me how to implement that line in D?
Assume for this example that I am not using the MainWindow class...
Code: |
module gtk.tut1b;
private import gtk.Widget;
private import gtk.Window;
private import gtk.Button;
private import gtk.Duit;
private import std.stdio;
private import gtk.Image;
private import gdk.gdktypes;
private import gtk.gtktypes;
private import gobject.Signals;
private import gdk.Event;
class Mywindow : Window
{
this(){
super("Duit");
addOnDelete(&delete_event);
addOnDestroy(&destroy_me);
}
gboolean delete_event(Event event, Widget widget)
{
writefln("delete event occurred\n");
return 1;
}
gboolean destroy_me(Event event, Widget widget)
{
Duit.exit(0);
return 0;
}
}
class Mybutton : Button
{
this(){
super("Goodbye C++");
addOnClicked(&hello);
/* This will cause the window to be destroyed by calling
* gtk_widget_destroy(window) when "clicked". Again, the destroy
* signal could come from here, or the window manager. */
// g_signal_connect_swapped (G_OBJECT (button), "clicked",
// G_CALLBACK (gtk_widget_destroy),
// G_OBJECT (window));
}
this(Window win){
super("Goodbye C++");
addOnClicked(&hello);
}
void hello(Button widget)
{
writefln ("Hello World\n");
}
}
void main(char[][] args)
{
Duit.init(args);
Mywindow window = new Mywindow();
Mybutton button = new Mybutton();
//button.addOnClicked(&window.destroy);
window.setBorderWidth = 10;
window.add(button);
button.show();
window.show();
Duit.main();
return 0;
}
|
_________________ -hauptmech |
|