[prev in list] [next in list] [prev in thread] [next in thread]
List: gtk-app-devel
Subject: Re: Problem to open a new window using libglade
From: patrick <thunar24 () gmail ! com>
Date: 2007-03-05 16:03:33
Message-ID: cece49b10703050803qc9f94d5q801b2c41c785685c () mail ! gmail ! com
[Download RAW message or body]
Great! Thank you very much, this works.
But how can I make something during gtk_dialog_run?
I'd like to do somthing like this.
g_timeout_add(1000, update_pbar, dialog);
result = gtk_dialog_run(GTK_DIALOG(dialog));
...my process which progressbar should show
g_spawn...
progress = 0.2
....other work
gtk_widget_destroy(dialog);
dialog = NULL;
update_pbar (gpointer dialog)
{
...
gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(probar), progress);
...
}
Thank you
2007/3/2, Karl H. Beckers <karl.h.beckers@gmx.net>:
> Well,
>
> there's prolly several ways of doing it, but smth. along the following
> lines should work:
>
> GladeXML *gxml = glade_xml_new (GLADE_FILE, "dialog1", NULL);
> GtkWidget *dialog = glade_xml_get_widget(gxml, "dialog1");
> g_assert(dialog);
> GtkResponseType result;
>
> // register function to be executed in intervals
> g_timeout_add(1000, update_pbar, dialog);
> result = gtk_dialog_run(GTK_DIALOG(dialog));
>
> if (result == GTK_RESPONSE_OK)
> {
> }
>
> gtk_widget_destroy(dialog);
> dialog = NULL;
>
> then you need the timeout function:
>
> gboolean
> update_pbar (gpointer dialog)
> {
> // stop executing and unregister this function if dialog has
> // been set to NULL
> if (!dialog) return 0;
> // if dialog has not been displayed yet, don't bother updating
> // the progress bar
> if (!GTK_WIDGET_VISIBLE(GTK_WIDGET(dialog))) return 1;
>
> ...
> do whatever needs to be done to update the progressbar here
>
> return 1;
> }
>
> HTH,
>
> Karl.
>
>
>
> Am Freitag, den 02.03.2007, 23:32 +0100 schrieb patrick:
> > Thanks for your answer.
> >
> > > if I'm not completely mistaken here, this has nothing to do with glade.
> > > The thing just is, that you need to return to the main loop from the
> > > callback for the widgets to be drawn properly.
> > > That is prolly why you put in your gtk_main_iteration though I doubt
> > > there is a guaranteed way to make this work.
> > I think this is my problem.
> > So I made a new dialog:
> >
> > GladeXML *gxml = glade_xml_new (GLADE_FILE, "dialog1", NULL);
> > GtkWidget *dialog = glade_xml_get_widget(gxml, "dialog1");
> > GtkResponseType result;
> >
> > result = gtk_dialog_run(GTK_DIALOG(dialog));
> >
> > if (result == GTK_RESPONSE_OK)
> > {
> > }
> > gtk_widget_destroy(dialog);
> >
> > The window (dialog) now appears, but I want a "progress window", with
> > a progressbar and a label for the description. But how can I make
> > somthing while the dialog is visible so that I can show the progress
> > to the user?
> >
> > Thanks for the help.
> >
> >
> > 2007/3/2, Karl H. Beckers <karl.h.beckers@gmx.net>:
> > > Am Freitag, den 02.03.2007, 11:33 -0500 schrieb
> > > gtk-app-devel-list-request@gnome.org:
> > > > >>> void
> > > > >>> on_button1_clicked(GtkButton *button, gpointer data)
> > > > >>> {
> > > > >>> /* the button was clicked */
> > > > >>> //Print out to console
> > > > >>> g_print("Beginn break\n");
> > > > >>>
> > > > >>> //Create the new "progress" window
> > > > >>> GladeXML *gxml_progress = NULL;
> > > > >>> gxml_progress = glade_xml_new (GLADE_FILE, "window2", NULL);
> > > > >>>
> > > > >>> //show the window
> > > > >>> GtkWidget *window2 = glade_xml_get_widget(gxml_progress,
> > > > "window2");
> > > > >>> gtk_widget_show_all(window2);
> > > > >>>
> > > > >>> while (gtk_events_pending())
> > > > >>> gtk_main_iteration();
> > > > >>>
> > > > >>> //Make 5 sec. break
> > > > >>> g_usleep(5000000);
> > > > >>> g_print("End break\n");
> > > > >>> }
> > >
> > > Hi there,
> > >
> > > if I'm not completely mistaken here, this has nothing to do with glade.
> > > The thing just is, that you need to return to the main loop from the
> > > callback for the widgets to be drawn properly.
> > > That is prolly why you put in your gtk_main_iteration though I doubt
> > > there is a guaranteed way to make this work.
> > >
> > > So the complicated version would probably involve having hooking up a
> > > callback to the configure event for the second window that starts smth.
> > > and then automatically deregisters itself after the first run.
> > >
> > > The other thing I've found to work is use a GTK_DIALOG rather than a
> > > generic window and then do smth. along the lines of:
> > >
> > > result = gtk_dialog_run (GTK_DIALOG (dialog));
> > >
> > > if (result == GTK_RESPONSE_OK) {
> > > got_file_name =
> > > gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
> > >
> > > xml = NULL;
> > > xml = glade_get_widget_tree (GTK_WIDGET (xvc_pref_main_window));
> > > g_assert (xml);
> > >
> > > w = NULL;
> > > w = glade_xml_get_widget (xml, "xvc_pref_sf_filename_entry");
> > > g_assert (w);
> > >
> > > gtk_entry_set_text (GTK_ENTRY (w), strdup (got_file_name));
> > > }
> > >
> > > gtk_widget_destroy (dialog);
> > >
> > > Of course, if you're not really interested in the user's input you can
> > > just ignore the result.
> > >
> > > HTH,
> > >
> > > Karl.
> > >
> > >
> > >
> >
>
>
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic