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

void
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+
tutorial

    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
  together
- 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

etc.

> 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.

Yeti

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to