Tuesday, 16 November 2010

Did you ever wonder...?

how does a certain application do it's widget hierarchy in Gtk? Well lately I did, and therefore I wrote a little class that visualizes the allocation of the widget under your mouse (plus it's container). Add a little hacking with the dynamic linker and you get a small utility to inspect the widgets in (almost) any application. Take a look:

Gtk+ Inspector from Michal Hruby on Vimeo.


Unfortunately it's not perfect - atm it doesn't handle inner GdkWindows very well (as you can see in the video when I hover the GtkScrolledWindow), but maybe it could be easily fixed, I didn't really try as I didn't need that.
Also it doesn't work on just any application, I hooked the instantiation of my highlighting class to gtk_init(), so if your application doesn't call gtk_init(), it won't work (I'm afraid that also applies to all pygtk apps). Still, you can just compile your app with the Inspector class and instantiate it yourself.

Hopefully this will be useful for more people, so to see/grab the code, go to https://code.launchpad.net/~mhr3/+junk/inspector. And once you compile the .so file, run your favourite app using "LD_PRELOAD=./inspector.so [your_app]".

6 comments:

  1. Wouldn't it make sense to integrate such stuff in GtkParasite?

    ReplyDelete
  2. Thats exactly what it reminded me of, gtkparasite.

    ReplyDelete
  3. Honestly I didn't even know about GtkParasite, it does look nice.

    ReplyDelete
  4. GtkParasite also has an window where you can view and edit widget's properties.

    ReplyDelete
  5. Check out GTK_MODULES. (It's also how gtk-parasite works).

    ReplyDelete