FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Q&A Simple dui code examples

 
Post new topic   Reply to topic     Forum Index -> gtkD
View previous topic :: View next topic  
Author Message
hauptmech



Joined: 14 Jan 2007
Posts: 20
Location: Wellington, NZ

PostPosted: Thu Jan 18, 2007 3:48 am    Post subject: Q&A Simple dui code examples Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> gtkD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group