WARNING: This server is unstable and will be retired in the next days.
If you want to keep this forum available, please request immediately a migration
on the Nabble Support forum.
Forums that don't receive any migration request will be deleted forever.
Thanks for your suggestions and the sample code.
I have managed to make it work.
Just one more problem. If I have more then one button, say, in a nxn, it
seems that if one callback is open, I have to close it to open a new one
i.e. only one callback window will open at a time.
One easy solution that I got is to declare nxn child_window, like
GtkWidget *child_window1 = NULL;
GtkWidget *child_window2 = NULL;
and put an unique child_window to each button like
button = gtk_button_new_with_label("main");
gtk_table_attach_defaults(GTK_TABLE(table), button, 0, 1, 0, 1);
gtk_widget_modify_bg( button, GTK_STATE_NORMAL, &colorBlue );
when this is very easy, but tedious and (IMHO) NOT the correct way of
doing this thing.
Can you please show how to get this done?
On Fri, 2012-05-18 at 20:18 +0200, David Nečas wrote:
> On Fri, May 18, 2012 at 09:12:45PM +0530, Rudra Banerjee wrote:
> > Here is a minimal example of a program, where if i click the button, a
> > pop up window appears. I am posting both the call back function and the
> > main routine (table.c).
> > I am facing 2 problem.
> Unfortunately, you are facing much more problems.
> For start
> gtk_container_add(GTK_CONTAINER(window1), vbox1);
> is called with an unitialised variable window1 (i.e. no window1 is ever
> created). This leads to a CRITICAL message to console and/or crash.
> And if window1 existed then vbox1 would be packed into two different
> containers (window1 and window) which is not possible. So I'm ignoring
> that part altogether.
> The callback should look like
> callback_it(GtkWidget *button, gpointer user_data)
> where in user_data the callback receives the last argument you passed to
> g_signal_connect(). It is rarely useful to pass a constant such as
> "Call" there.
> The callback is *not* another main() function; it should *not* call
> gtk_init() again, etc. Please read the signals section in the Gtk+
> http://developer.gnome.org/gtk-tutorial/2.90/x159.html >
> There are several other highly suspicious things:
> - redeclaration of global variables (such as window) inside a function;
> are you aware this creates a new local variable window that has nothing
> to do with the global one?
> - inclusion of .c files instead of separate compilation + linking them
> - calling gtk_widget_show() on individual widgets and then again showing
> everything using gtk_widget_show_all()
> - not terminating the Gtk+ main loop when the main window is destroyed;
> this is usually the first thing to set up in a Gtk+ program, see
> http://developer.gnome.org/gtk-tutorial/2.90/c39.html#SEC-HELLOWORLD >
> > 1) The problem is evry time I click the button "main", a new window
> > appears(obviously). What I want to achive is, if the window is already
> > present, it should not open again; rather it should focus that window. I
> > believe, this can be achived by gtk_window_present(may be I am wrong).
> > But I don't know how to use it.
> You use it just by calling gtk_window_present() on the window object.
> To that meaningfully you need not only to keep the window object around
> but also get notified when the window is destroyed. Either by
> connecting to the "destroy" signal or, if you just want to set a pointer
> to NULL once it is gone, by using g_object_add_weak_pointer().
> > 2) In the callback function, I have C_1 and C_2. What I want to achive
> > is C<sub>1</sub> etc via pango(or any other).
> For simple things you can sometimes just use UTF-8. But generally, you
> need to use Pango markup. If the widget does not have function to set
> the markup it has a function to obtain the label widget so that you can
> use gtk_label_set_markup() on that.
> See the attached code with main problems fixed (and merged to one file).
> Please go through the Gtk+ tutorial farther that you perhaps have done.