Walking through the widgets of an application?



Hello,

I am developing a performance benchmark for Gnome applications. One problem that has to be solved is identification of all widgets by their names in the scripts that drive the benchmark (simulate input, measure times etc). E.g. if I want to write a benchmark script that checks for the time certain widgets need to be displayed, I need to refer those widgets somehow in the script and I need a name for that.

A benchmarking application for Motif had a little app that walked down the widget tree of the benchmarked application, created a unique name from the widget path and wrote all the names in a file. This was easy to implement as in Motif/Xt there is only one root widget in an application, every widget has a parent and popups (dialogs, menus) are referred by their parents as well. In turn using a widget name generated this way it was easy to find the corresponding widget pointer.

Looking at gtk I noticed that (please let me know if anything below is incorrect):
- there is no one root widget, there can be several toplevel windows
- a widget has a parent if it has been added to a container with gtk_container_add(), there is no parent specified at creation
- dialogs do not always have parents
- same for menus (I am not sure about this, help is appreciated)
- any other widgets that do not have parents?
- gtk applications have several widget hierarchies rather than only one starting from several toplevel windows

So the approach used for Motif would not work for gtk.

One possible solution could be to override a couple of functions that are used at the creation of widgets and at the creation of widget hierarchies.

gtk_type_new() seems to be used to create widgets. Overriding this in a preload library we could generate names for all the toplevel window created. Then there seem to be a number of routines (gtk_container_add() or gtk_container_foreach()) that can be overridden to walk down the hierarchies of these toplevel windows and generate names for the individual widgets. These names have to be readable as it is much easier to write a benchmarking script using a name like TOPLEVEL1:BUTTON1 than a unique, but unreadable name (generating names that use the full widget path is not always possible by overriding gtk_container_add() since the full hierarchy may not be built yet).

All these names are output in a header file to be used by the benchmarking scripts. Also an array of widget name and widget pointer pairs have to be stored in the benchmarked application (using a preload library) to facilitate lookup of the widget pointers using the names.

I know this is far from a complete solution and I appreciate any feedback related to how much of my understanding about how gtk works is correct and if something like the above schematic solution would work or not.

Laszlo




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]