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 

Multi Page Program (Solved)

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


Joined: 31 Jan 2008
Posts: 5

PostPosted: Sat Feb 16, 2008 9:06 pm    Post subject: Multi Page Program (Solved) Reply with quote

hi, i newby

i´m haven a problem to try to do a multi page dialog.

i can do it forward, but no goback;

it show a mensage erro in debugger:
Quote:
<LabCel.exe:3576>: Gtk-CRITICAL **: gtk_box_pack_start: assertion `GTK_IS_WIDGET <child>´ failed


my .c is
Code: (C)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123

#include <stdlib.h>
#include <gtk/gtk.h>

static void button_forward (GtkWidget *widget, gpointer data);
static void button_back_ (GtkWidget *widget, gpointer data);
typedef struct
{
    GtkWidget *widget;
    GtkWidget *title;
}PageInfo;

gint i=0;

GtkWidget *button_back = NULL;
GtkWidget *button_fwrd = NULL;
GtkWidget *window = NULL;
GtkWidget *button_box = NULL;
GtkWidget *win_page = NULL;
GtkWidget *aula_box = NULL;
GtkWidget *page[8];


int main (int argc, char *argv[])
{



    /* Initialize GTK+ */
   
gtk_init (&argc, &argv);


    /* Create the main window */
   
{
        window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
        gtk_container_set_border_width (GTK_CONTAINER (window), 10);
        gtk_window_set_title (GTK_WINDOW (window), "LabCel 1.0");
        gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
        gtk_widget_set_size_request(window, 200, 200);
        g_signal_connect (window, "destroy", gtk_main_quit, NULL);
    }




    win_page = gtk_vbox_new (FALSE, 10);



    aula_box = gtk_vbox_new (FALSE,0);
    page[0] = gtk_label_new ("MENU");
    page[1] = gtk_label_new ("TESTE1");
    page[2] = gtk_label_new ("TESTE2");
    page[3] = gtk_label_new ("TESTE3");
    page[4] = gtk_label_new ("TESTE4");
    page[5] = gtk_label_new ("TESTE5");
    page[6] = gtk_label_new ("TESTE6");
    page[7] = gtk_label_new ("TESTE7");
    gtk_box_pack_start (GTK_BOX(aula_box),page[0],FALSE,FALSE,2);


    gtk_box_pack_start_defaults (GTK_BOX(win_page), aula_box);





    /* Create a Horizontal box with buttons */

   
button_box = gtk_hbox_new (FALSE, 6);



    button_fwrd = gtk_button_new_with_mnemonic ("_Avancar");
    gtk_box_pack_end (GTK_BOX (button_box), button_fwrd, FALSE,TRUE,0);
    gtk_widget_set_size_request (button_fwrd,58,-1);
    g_signal_connect (G_OBJECT (button_fwrd), "clicked",G_CALLBACK (button_forward),NULL);

    button_back = gtk_button_new_with_mnemonic ("_Voltar");
    gtk_box_pack_end (GTK_BOX (button_box), button_back, FALSE,TRUE,0);
    gtk_widget_set_size_request (button_back,58,-1);
    g_signal_connect (G_OBJECT (button_back), "clicked",G_CALLBACK (button_back_),NULL);

    gtk_box_pack_start(GTK_BOX (win_page), button_box,FALSE, FALSE,0);





    gtk_container_add (GTK_CONTAINER (window),win_page);

    /* Enter the main loop */
   
gtk_widget_show_all (window);
    gtk_main ();

    return 0;
}


static void button_forward (GtkWidget *widget, gpointer data)
{
    if (i<7)
    {
        gtk_container_remove (aula_box,page[i]);
        i++;
        gtk_box_pack_start (GTK_BOX(aula_box),page[i],FALSE,FALSE,2);
        gtk_widget_show_all (aula_box);
    }
}


static void button_back_ (GtkWidget *widget, gpointer data)
{
    if (i>0)
    {
        gtk_widget_hide_all (page[i]);
        //gtk_container_remove (aula_box,page[i]);
       
i--;
        gtk_box_pack_start (GTK_BOX(aula_box),page[i],FALSE,FALSE,2);
        gtk_widget_show_all (aula_box);
    }
}
Back to top
Vene
Familiar Face


Joined: 31 Jan 2008
Posts: 5

PostPosted: Sat Mar 08, 2008 5:05 am    Post subject: Reply with quote

Giving a look at the documentation of the library, I found something very interesting. When gtk_container_remove is used, gtk eliminates the widget of the container and memory because of this, I could not add back in the container button_back when pressed, because the gtk not find it on any side. To solve it we must use a reference to g_object_ref.


maybe this is not news to nobody, and I am speaking shit, but doing what, do you not?
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