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

gtkBuilder getObject issue

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



Joined: 19 Jun 2009
Posts: 24

PostPosted: Wed Aug 05, 2009 5:26 pm    Post subject: gtkBuilder getObject issue Reply with quote

G'day,
I am having some issues regarding the following piece of code:
Code:


module gui2.XMLApp;

import gtk.Main;
import gtk.Window;
import gtk.Widget;
import gtk.Builder;

import tango.io.Stdout;

class XMLApp {

   Builder app;

   this(char[][] args) {
      Main.init(args);

      app = new Builder();
      auto err = app.addFromFile("Interface.xml");
      if(err == 0 ) {
         Stderr("Error opening glade file.").newline;
      }

      app.connectSignals(null);

      auto w = cast(Widget)app.getObject("window1");

      if(w !is null) {
         w.show();
         Main.run();
      }
      else { Stderr("Error launching application.").newline; }
   }
}


The XML file involved is a bit long, so I will not post it unless necessary, but I can confirm 'window1' is the id of the main window. However, w is null.
I have tried some case variations and the names of other widgets defined in the xml file, to no avail. w is always null

The xml file has been created using gtkBuilder, so it should be ok.

I have tried app.getObjects, and checked for the returned list length and its ok (13 objects); I can't seem to find what to cast the list elements to not segfault though.

I don't know what else to try; any hints?

Edit: I have discovered that getObject actually returns something, a 'gobject.ObjectG. It's when I cast it to Widget that it nullifies. Is there any way to know what classes is ObjectG castable to? Runtime, I mean.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Thu Aug 06, 2009 2:43 pm    Post subject: Reply with quote

Currently the objects builder.getObject are not castable to other objects.

As a workaround you could use:
Code:
obj.setData("GObject", null);
auto w = new Window(cast(GtkWindow*)obj.getObjectGStruct());


I've tried to implement getObject like glade.getWidget but that hangs the compiler, i think because of the circlic imports.
Back to top
View user's profile Send private message
elkano



Joined: 19 Jun 2009
Posts: 24

PostPosted: Thu Aug 06, 2009 3:54 pm    Post subject: Reply with quote

Thank you, at least there is a workaround.

I hope this issue will be solved in the future. Good luck.
Back to top
View user's profile Send private message
heromyth



Joined: 26 Nov 2006
Posts: 46

PostPosted: Wed Dec 02, 2009 9:28 am    Post subject: Reply with quote

Mike Wey wrote:
Currently the objects builder.getObject are not castable to other objects.

As a workaround you could use:
Code:
obj.setData("GObject", null);
auto w = new Window(cast(GtkWindow*)obj.getObjectGStruct());


I've tried to implement getObject like glade.getWidget but that hangs the compiler, i think because of the circlic imports.


This way seems OK. I have tested with DMD 1.051 successfully.
I just modified the function of "public ObjectG getObject(string name)" in Builder.d. One line changed from
Code:
return new ObjectG(cast(GObject*) p);

to
Code:
return newFromWidget(cast(void*)p );


Of course, some codes in Glade.d like
Code:

private import gobject.Type;
.......
private import gtk.Window;

........
   Widget newFromWidget(void * ptr)
   {
...........
         default: return null;
      }
      
   }

are copied into Builder.d.

I used CMakeD to build all the libs. Sorry for no testing with DSSS.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Wed Dec 02, 2009 2:43 pm    Post subject: Reply with quote

I've tried that before, but the compiler used to hang on the buildable tamplate. It looks like the bug causing this is fixed.
Back to top
View user's profile Send private message
heromyth



Joined: 26 Nov 2006
Posts: 46

PostPosted: Thu Dec 03, 2009 4:53 am    Post subject: Reply with quote

It's so bad. I got failed with DSSS. Maybe the DMD is OK, and there is a little bug in DSSS Laughing
Back to top
View user's profile Send private message
heromyth



Joined: 26 Nov 2006
Posts: 46

PostPosted: Thu Dec 03, 2009 7:56 am    Post subject: Reply with quote

By the way, I noticed that there are some codes in Glade.d like these
Code:

   Widget newFromWidget(void * ptr)
   {
      if (ptr is null) {
         return null;
      }
      
      int* pt =cast(int*)ptr;
      
      int* pt2 =cast(int*) (cast(int*)(*pt));
      uint utype =  cast(uint)(*pt2);
      
      string tname = Type.name(cast(GType)utype);

Can they be changed to these:
Code:

   Widget newFromWidget(GObject* ptr)
   {
      if (ptr is null) {
         return null;
      }

      GTypeInstance* gTypeInstance = cast(GTypeInstance*)(ptr);
      string tname = Type.name(gTypeInstance.gClass.gType);

It's tested and works.

I know there are many macro defines like
Code:

#define G_OBJECT_TYPE_NAME(object) (g_type_name (G_OBJECT_TYPE (object)))

which are still unwrapped into GtkD. What can we do for this? You know this code
Code:

      GTypeInstance* gTypeInstance = cast(GTypeInstance*)(ptr);
      string tname = Type.name(gTypeInstance.gClass.gType);

can finish the job of G_OBJECT_TYPE_NAME(object). However, what should be defined as for this? Type.Name(ObjectG) or something?
Does anyone have a plan?
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Thu Dec 03, 2009 4:20 pm    Post subject: Reply with quote

Type.Name(ObjectG); would be nice.
Back to top
View user's profile Send private message
heromyth



Joined: 26 Nov 2006
Posts: 46

PostPosted: Fri Dec 04, 2009 4:51 am    Post subject: Reply with quote

Mike Wey wrote:
Type.Name(ObjectG); would be nice.


Maybe it should also be added to class ObjectG as a method. For example, we can get the typename of a GTK object like this:

Code:
oneObject.getTypeName()


If it's acceptable, what need to do for me?
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sat Dec 05, 2009 3:36 pm    Post subject: Reply with quote

heromyth wrote:
It's so bad. I got failed with DSSS. Maybe the DMD is OK, and there is a little bug in DSSS Laughing


DSSS still uses an old dmd front end, other tools that still use the old front end might have the same problem, like gdc and ldc. when the other compilers don't hang on the code. it might be worth thinking about dropping DSSS, it already doesn't work with dmd2 on linux. Maybe in favor of cmakeD which i haven't realy looked into yet.

I think the problems are caused by circular imports but I'm not sure. as in builder imports all the widgets, buildable imports builder, some widgets import buildable.

Quote:
Maybe it should also be added to class ObjectG as a method. For example, we can get the typename of a GTK object like this:


I think i would prefer the Type.name overload.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Sat Dec 05, 2009 4:01 pm    Post subject: Reply with quote

I've change Glade.d in svn r731 i noticed that you can't use Type.name(ObjectG) from the newFromWidget function as we a working with the structs at that point. would Type.name(ObjectG) be useful for other things?
Back to top
View user's profile Send private message
heromyth



Joined: 26 Nov 2006
Posts: 46

PostPosted: Mon Dec 07, 2009 4:04 am    Post subject: Reply with quote

Mike Wey wrote:
I've change Glade.d in svn r731

Thanks!
Quote:

i noticed that you can't use Type.name(ObjectG) from the newFromWidget function as we a working with the structs at that point. would Type.name(ObjectG) be useful for other things?


I havn't used it yet. I just think that there should be a better way to get the gobject's type name.

Type.name(ObjectG) is more like gtk+ style, and ObjectG.getTypeName() is more OOP style.
Back to top
View user's profile Send private message
heromyth



Joined: 26 Nov 2006
Posts: 46

PostPosted: Mon Dec 07, 2009 4:11 am    Post subject: Reply with quote

Sorry for this duplicated post!

Last edited by heromyth on Mon Dec 07, 2009 4:13 am; edited 1 time in total
Back to top
View user's profile Send private message
heromyth



Joined: 26 Nov 2006
Posts: 46

PostPosted: Mon Dec 07, 2009 4:11 am    Post subject: Reply with quote

Mike Wey wrote:
heromyth wrote:
It's so bad. I got failed with DSSS. Maybe the DMD is OK, and there is a little bug in DSSS Laughing


DSSS still uses an old dmd front end, other tools that still use the old front end might have the same problem, like gdc and ldc. when the other compilers don't hang on the code. it might be worth thinking about dropping DSSS, it already doesn't work with dmd2 on linux. Maybe in favor of cmakeD which i haven't realy looked into yet.

I think the problems are caused by circular imports but I'm not sure. as in builder imports all the widgets, buildable imports builder, some widgets import buildable.


If using CMakeD, I hope this post can do some help.
I just testd it on Windows XP with CMakeD+CMake 2.6.4. All the things seemed OK.
Back to top
View user's profile Send private message
Mike Wey



Joined: 07 May 2007
Posts: 428

PostPosted: Thu Dec 10, 2009 4:28 pm    Post subject: Reply with quote

Mike Wey wrote:
I think i would prefer the Type.name overload.


added in svn r733
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