Re: [gtk-list] Q: automatic function on program startup



Eduardo Perez wrote:
> I need to write a program which shows a window when starting and then
> enters a function (that displays some info in that window), without any
> user interaction. Could anybody tell me if is this possible and how,
> please?
ok you need to be a bit more specific. I assume you know how to make a window,
you could then use, say, a label in the window:

GtkWidget *mylabel;

void myfunc(void)
{
  gtk_label_set(GTK_LABEL(mylabel), "Goodbye");
}

void setup_window() {
  GtkWidget *dialog;

  dialog = gtk_dialog_new();

  mylabel = gtk_label_new("hello");
  gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), mylabel);
  gtk_widget_show(mylabel);
  gtk_widget_show(dialog);

  myfunc();
}

Now this assumes you want to build your window (I'm using a dialog here)
and then immediately run the function to put some text in. But of course
you could wait for:

  * A button to be pressed, using gtk_signal_connect to call myfunc();
  * Some time to elapse, using gtk_timeout_add();
  * Some input to occur, or a connection to be made, using gdk_input_add();
  * Plus plenty of other triggers out there.

I must admit, to move from a procedural language to a event-driven one is a
bit tricky to do, I still get caught, especially with file and socket handling
stuff.

Hope this helps,

  - Craig




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