Re: GTK PROGRAM STRUCTURE



My standard method (not necessarily the best, but it works nicely for
me) is to create a class (call it AppGTK) that has all the widgets as
private data members.  The callbacks are static member functions of
the class (solves your problem below).  I then have one global
variable app_gtk.  In each callback, I can then access any of the
widgets using that global variable and since the callbacks are members
of the class, they can legally access all the private data.

HTH,
Dave


> Date: Fri, 09 Mar 2001 10:10:21 -0500
> From: CyborgHead netscape net
> 
> Hi.
>     A quick question, which is more one of style and programming practice. What is the best way to structure a GTK Program. I have written a program which contains many dialog boxes, all which hold buttons, text boxes etc.. I felt that the best way to program this would be to use classes as I am used to object orientated programming however I found that it could not be effectively done.
> 
> Having created an instance of a class , b I tried to call
> 
> gtk_signal_connect_object( GTK_OBJECT( button_setup ), "clicked",
>         GTK_SIGNAL_FUNC( b.setup ), NULL );
> 
> This did not work, I then tried to pass the class as a parameter ie.
> 
> gtk_signal_connect_object( GTK_OBJECT( button_setup ), "clicked",
>         GTK_SIGNAL_FUNC( global_void_function ), b );
> 
> and this did not work.
> Since most of my functions need access to alot of the GtkWidgets I have made nearly all my variables global so they can be accessed by all the functions, but this is crap, and need to improve it cause it is an important project for college. How do you think I should structure the program to have good programming practive and have the variables available to numerous functions.
> 
> Ciaran




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