Skip to Content

find a controls using its title in gtk or any others

salamo 3alekom

in my graduation project i've stuck in this problem in win32 there's a function called FindWindowEx(....)

by using the window title or button title ... i could get a handle to this widget(using gtk language)

when passing null i could get the controls contained in certain window

for non win32 programmer windows OS treat every thing in terms of window and child window So button,labels, ..... treated as child windows .

the problem is when i need to do that in linux i already do a function which simulate a FindWindow but it could find only the main window not widget inside it by using xlib directly but what about widgets .....

could any one help at least in how gtk ,qt or tk treat widget inside it

i think motif use the same concept used by win32 then what about the others

ofcourse u need to know what is this ??? the app is Gui testing tool but no unit testing which mean the GuiTester is separated from the program under test not like juint or marathon or other stuff

REGARDs

MSameer's picture

In GTK when you click on a bu

In GTK when you click on a button for example, the callback is passed this button as the 1st argument and so...

If you know that you'll need a widget, Then use g_object_set_user_data() so you can get it after that.

If you give me details about your gtk project I can help you more!

Quote "c u next life time then when i come back as a mug of tea :P"

Salamoo 3alekom

Salamoo 3alekom

the first one already done using xlib directly using a combination of two function XQueryTree(),XFetchName() the problem in the second one u know that xlib make no sense to controls inside a window

the step of porting it to linux is optional but actually i want to make it because i don't like using windows in my everyday work the project we worked on excepected to be multiplatform so for OS dependent tasks we should create module for every OS and use the right one at the right time windows modules completed but linux modules far from it

Uniball u r my only hope :'( save me from windows :'(

MSameer's picture

Have a look at any glade gene

Have a look at any glade generated code. in support.c there's a function: GtkWidget* lookup_widget (GtkWidget *widget, const gchar *widget_name); /* * This function returns a widget in a component created by Glade. * Call it with the toplevel widget in the component (i.e. a window/dialog), * or alternatively any widget in the component, and the name of the widget * you want returned. */

I hope that this is what you want.

Quote "c u next life time then when i come back as a mug of tea :P"

Some More insight

As far as *nix widgets go...

I am using XQueryTree() for a UI project. I am still figuring out how to enumerate recursively or what not the whole tree of windows. I have grabbed the "root" window in my main() like so:

	Display *dpy = XOpenDisplay(NULL);
	assert(dpy);
	Screen *scr = DefaultScreenOfDisplay(dpy);

	Window wRootOfScreen = RootWindowOfScreen(scr);

I am next going to check out the source of xwininfo and also wininfo (nice graphical program like xwininfo).

I hope this saves some people some time.

David

One more thing

I forgot to mention that this site was VERY helpful especially his example code!

and the link I found it on...

Back to live

Salamo 3alekom

i finished my graduation project for windows and works and finally i've been graduted , also after that i'm busy these days because of currently i 'm working but the idea raise again to make an automated Gui Testing tool for gtk application there's a lot for windows OS there's silktest,winrunner,rational robot ,....

but no OSS tool , except jemmy for java which is more unit testing tool rather black box testing tool

what i need is recording techniques that could detect every keystroke and mouse clicks .i made it sccuessfully for linux while i'm working in my graduation project , then a way to play back ,also success i found a ways to fake both mouse and key stoke events to make playback

the only problem i face is to make things works on widget level not in cooredinate ,which could be solved by this way ,first detect the widgets of AUT (application under test) then detecting its properties its coordinate then i could use the previously mentioned techinques to perform a widget level recording and playback

Thanks again ya( Abo Sameer )for ur help but glade consider a special case becuase it put the widget in XML format and build it at run time , i hope i'm right

David (Thanks a lot ) But XQuery works with me but it detects only toplevel window it couldn't detect button,textboxes and other widget as far as i know gtk draw every thing unlike Windows OS ,which consider these component as window and u could detect it using Windows API FindWindow ,FindWindowEx mentioned Before

Found it but late

Salamo 3alekom

At last i found it, gnome offer libraries for accessbilties to make interporcesses events they said it like ATK but not need to be in the same process AT-SPI all u need to get it is to install a some set of libraries but the best way is to install gnome accessiblity tools from ur distro this code list controls in gedit it needs to be recusive to get more also don't forget to free memory :-D

#include "stdio.h"
#include "cspi/spi.h"
#include "malloc.h"
int main (int argc,char *argv[]) 
{
	int count=0;
	SPI_init();
	Accessible *accessible=SPI_getDesktop(0);
	int i=0;
	for (i=0;i < Accessible_getChildCount(accessible);i++) {
		Accessible *child=Accessible_getChildAtIndex(accessible,i);
		if (Accessible_isApplication(child)) {
			char* name=Accessible_getName(child);
			if (!strcmp(name,"gedit")) {
				int j=0;
				for (j=0;j < Accessible_getChildCount (child);j++) {
					printf ("%s\n",Accessible_getName(Accessible_getChildAtIndex(child,j)));
				}
			}
			
		}
			
		else
			printf ("Not Found");
	}
	SPI_exit();
	return 0;
}

but i'm late because i discover that redhat begin to build this tool before me :-D it is dogtail :'(

where's my message most of it

where's my message most of it disappear :'(

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.


Dr. Radut | forum