GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Onload event

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
flyjason
Familiar Face


Joined: 04 Mar 2007
Posts: 19

PostPosted: Sun Jun 10, 2007 8:55 am    Post subject: Onload event Reply with quote

Hello,

A simple question it seems but I don't know the answer : (

In VBasic there is the "Onload" event for a window...that is a sub or module that handles task(s) to be done when the window is called up or loaded for the first time. I would like to know what is the corresponding signal in gtk+.

Thanks
Back to top
Micah Carrick
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 481
Location: Portland, OR USA

PostPosted: Mon Jun 11, 2007 7:15 am    Post subject: Reply with quote

You probably have a lot more "signals" in GTK than you had "events" in VB. When the program first starts--assuming you're using C or C++, your main() function could be compared to using a "Sub Main" in VB. As for when the window or "Form" is loaded in GTK+, it depends.

If you want code to execute every time you show your window to the user, you could connect a callback to the "show" signal. Perhaps you just want to execute some code when the window is initially "realized" or when it's been "mapped" but not necessarily shown. Each of these states have a corresponding signal which you can attach to a callback singnal. You should read more about widget lifecycles to understand the concepts of realized, mapped, reference counting, etc.

Here's a quick snippet which you can build from and experiment with:



Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/* compile using:
cc -Wall -g `pkg-config --cflags --libs gtk+-2.0`  -o example main.c 
*/

#include <gtk/gtk.h>

void on_window_map (GtkWidget*, gpointer);
void on_window_realize (GtkWidget*, gpointer);
void on_window_show (GtkWidget*, gpointer);
               
int
main (int argc, char *argv[])
{
       
        GtkWidget *window;
       
        /* initialize the GTK+ library */
        gtk_init (&argc, &argv);

        /* create main window */
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_window_set_title (GTK_WINDOW (window), "Example");
        gtk_container_set_border_width (GTK_CONTAINER (window), 10);
        gtk_widget_set_size_request (window, 200, 100);
       
        /* connect signals */
        g_signal_connect (G_OBJECT(window), "destroy",
                        G_CALLBACK (gtk_main_quit), NULL);
        g_signal_connect (G_OBJECT(window), "realize",
                        G_CALLBACK (on_window_realize), NULL);
        g_signal_connect (G_OBJECT(window), "map",
                        G_CALLBACK (on_window_map), NULL); 
        g_signal_connect (G_OBJECT(window), "show",
                        G_CALLBACK (on_window_show), NULL);       
               
        /* show the main window, hide it, then show it again */
        gtk_widget_show (window);
        gtk_widget_hide (window);
        gtk_widget_show (window);
       
        gtk_main ();
       
        return 0;     
}

void
on_window_map (GtkWidget *w,gpointer user_data)
{
        g_print("Window was mapped.\n");
}

void
on_window_realize (GtkWidget *w,gpointer user_data)
{
        g_print("Window was realized.\n");
}

void
on_window_show (GtkWidget *w,gpointer user_data)
{
        g_print("Window was shown.\n");
}

Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP