Fake a signal
Submitted by neocruze on Sat, 03/01/2008 - 19:20.
can we fake a signal occurrence.............
i mean button clicked signal occurs even when nobody clicks anything ........
or
fake a signal occurrence......
even when actual click or event never happened .........
- neocruze's blog
- Login or register to post comments









Recent blog posts
- Nirmitsu Technologies Launches NU2000, NU2100 and NU4000
- Gtk and Embedded Devices - part 1
- gtk extra plot...
- GtkSheet with freeze panes
- Fake a signal
- Query::Setting Color of submenu Widgets
- how to color the combo box entry
- Multiline Text Editing Widget
- Setting Color of submenu Widgets
- GtkFB (Gtk+) for the Linux Framebuffer
Re: Fake a signal
these functions can be used
gtk_signal_emit (GTK_OBJECT(button), EVENTNAME,
args);
void gtk_signal_emit_by_name (GtkObject *object,
const gchar *name,
...);
here emit function takes Event value defined and
arguments for that particular signal handler.
emit_by_name function is suitable for you
where u can specify events like "clicked" etc.
This will emit a fake signal and you can goto your
button handler function registered using gtk_signal_connect
This functions avoid using your own signal handling loop
which i mentioned previously.
use gtk_signal_emit_by_name.
GtkGakaxu
www.gtkhelp.com
Gtk help team
Re: Re: Fake a signal
On March 2nd, 2008 neocruze says:
well i am trying but no success till now..........
this is the signal that i have to fake ......
g_signal_connect (G_OBJECT (button), "clicked",G_CALLBACK (hello), NULL);
to call function name hello
i tried this ...
gtk_signal_emit_by_name(GTK_OBJECT(button),"clicked",G_CALLBACK (hello), NULL);
it compiled well but on runtime i got this.....
(no:4543): Gtk-CRITICAL **: gtk_signal_emit_by_name: assertion `GTK_IS_OBJECT (object)' failed
so what should i add in
gtk_signal_emit_by_name
.....
Hi friend, for
Hi friend,
for gtk_signal_emit_by_name you should
pass callback's argument list
not callback itself
below i attached my tested sample
code for this fake signal.
When you click button 1
signal handler of button 2 is called.
see below code
/* Sample code from www.gtkhelp.com
* Gtk Help Team
*
*
*
*
*
*
*
*
*
*
*
*
*/
#include
#include
//Button2 callback
void
hello (GtkWidget * button, gpointer data)
{
printf ("hello B2 clicked\n");
}
//Button 1 callback
//this will generate a fake signal for button2
void
b1_clicked (GtkWidget * button, gpointer data)
{
GtkWidget *b = (GtkWidget *) data;
printf ("in b1\n");
//argument list is the arguments given to callback function
gtk_signal_emit_by_name (G_OBJECT (b), "clicked", b, NULL);
}
//main code
main (int argc, char **argv)
{
GtkWidget *button1, *button2, *fixed;
GtkWidget *window;
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size (window, 400, 400);
gtk_window_set_title (GTK_WINDOW (window), "TEST");
fixed = gtk_fixed_new ();
gtk_widget_show (fixed);
gtk_container_add (GTK_CONTAINER (window), fixed);
button1 = gtk_button_new_with_label ("B1");
button2 = gtk_button_new_with_label ("B2");
gtk_fixed_put (fixed, button1, 10, 5);
gtk_fixed_put (fixed, button2, 50, 5);
//button2
g_signal_connect (G_OBJECT (button2), "clicked", G_CALLBACK (hello), NULL);
//button1
g_signal_connect (G_OBJECT (button1), "clicked", G_CALLBACK (b1_clicked),
button2);
gtk_widget_show_all (window);
gtk_main ();
}
Re: Re: Fake a signal
.
yes you can
you may have to call different
functions with while(1) loop
instead of gtk_main
code snippet i will update soon.