Non-blocking dialog

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Non-blocking dialog

Jim Heald-2
Hello there!

I'm writing a GTK+ application in C. In my application I'm running two commands that take a bit of time; in order to not make it appear that the program has just frozen, I am wanting to do the following:

1) run the dialog, which has a spinner widget
2) add to the dialog area a message that says what the first command does
3) run the first command
4) add a message saying that the second command is running
5) run the second command
6) add a done message
7) allow the user to click "Ok" to close (or maybe delay for a second and close)

Additionally, I am creating this dialog within a callback (as it is supposed to appear when the user clicks the "Next" button in the main application).
 
However, my problem is that the dialog only appears after everything has been executed and the callback finishes execution. Here's what I'm running:

{
...
    diag = create_progress_spinner_dialog(window, &box); 
    /*gtk_widget_set_can_focus(diag, TRUE);*/
    /*gtk_window_set_modal(GTK_WINDOW(diag), TRUE);*/
    /*gtk_window_set_transient_for(GTK_WINDOW(diag), GTK_WINDOW(window));*/
    /*gtk_widget_show_all(diag);*/

    gtk_box_pack_start(GTK_BOX(box), gtk_label_new("Formatting..."), TRUE, TRUE, 10);
    gtk_widget_show_all(diag);
    format_target_device(info->target_device, fs_choice);

    gtk_box_pack_start(GTK_BOX(box), gtk_label_new("Mounting..."), TRUE, TRUE, 10);
    gtk_widget_show_all(diag);
    mount_target_device(info->target_device);

    gtk_box_pack_start(GTK_BOX(box), gtk_label_new("Done!"), TRUE, TRUE, 20);
    gtk_widget_show_all(diag);

    gtk_notebook_next_page(GTK_NOTEBOOK(globals->notebook));

    push_stack(globals->pages, 1);
    set_next_hb_title(globals);
}

As you can see by the comments, I tried quite a few things with no success. However, if I put the gtk_dialog_run in there and it will appear but it obviously blocks execution which isn't helpful to me. I'm really not sure where to go from here; any help would be greatly appreciated.

Thanks!
--
Jim

---------------------------------------------------
James Heald
Computer Science Undergraduate
California Polytechnic State University
(510) 303-1458

_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
LRN
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Non-blocking dialog

LRN
On 8/9/2017 11:58 PM, Jim Heald wrote:

> Hello there!
>
> I'm writing a GTK+ application in C. In my application I'm running two commands
> that take a bit of time; in order to not make it appear that the program has
> just frozen, I am wanting to do the following:
>
> 1) run the dialog, which has a spinner widget
> 2) add to the dialog area a message that says what the first command does
> 3) run the first command
> 4) add a message saying that the second command is running
> 5) run the second command
> 6) add a done message
> 7) allow the user to click "Ok" to close (or maybe delay for a second and close)
>
> Additionally, I am creating this dialog within a callback (as it is supposed to
> appear when the user clicks the "Next" button in the main application).
>  
> However, my problem is that the dialog only appears after everything has been
> executed and the callback finishes execution.
I don't know how idiomatic this is, but for some time i've been considering the
idea of ditching most dialog windows and using overlays to convey simple
messages. You can even make them modal (though you'll probably have to manually
disable/reenable other widgets to simulate "modality").

_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list

0x8DADE9276759BA74.asc (3K) Download Attachment
signature.asc (836 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Non-blocking dialog

Timm Bäder
In reply to this post by Jim Heald-2
On 09.08, Jim Heald wrote:

> Hello there!
>
> I'm writing a GTK+ application in C. In my application I'm running two
> commands that take a bit of time; in order to not make it appear that the
> program has just frozen, I am wanting to do the following:
>
> 1) run the dialog, which has a spinner widget
> 2) add to the dialog area a message that says what the first command does
> 3) run the first command
> 4) add a message saying that the second command is running
> 5) run the second command
> 6) add a done message
> 7) allow the user to click "Ok" to close (or maybe delay for a second and
> close)

Your "commands" here are blocking the main thread, thus GTK+ can't
update any widget, not even show a window. It's the typical "don't block
the main thread" problem and the solution is to run your commands in
another thread and push update messages (e.g. for a progressbar if you
need that) to the main thread using g_idle_add.

_______________________________________________
gtk-list mailing list
[hidden email]
https://mail.gnome.org/mailman/listinfo/gtk-list
Loading...