Re: Show dialog after hide another

2017-09-09 Thread Eric Cashon via gtk-app-devel-list

Hi Ruben,

You can give the following a try and see if it helps. Basically you don't want 
to bind up the "main" thread with a long running function and freeze your UI. 

Eric

/* 
  gcc -Wall firmware1.c -o firmware1 `pkg-config --cflags --libs gtk+-3.0`
  Tested on Ubuntu16.04 and GTK3.18
*/

#include

/*
  Set some numbers for work to be done in the worker thread. Might need to 
change
  these for a faster cpu but be careful of guint overflow.
*/
#define SET1 10
#define SET2 1

static guint timeout_id=0;
static gint thread_active=0;
static gint load_progress=0;
static GThread *thread=NULL;

static void start_thread(GtkWidget *widget, GtkWidget **widgets);
static gpointer thread_get_firmware(GtkWidget **widgets);
static gboolean thread_join(GtkWidget **widgets);
static gboolean check_progress(GtkWidget *progress);
static void show_dialog(GtkWidget *widget, GtkWidget *window);

int main(int argc, char *argv[])
  {
gtk_init(, );

GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Show Progress");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 100);
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

GtkWidget *progress=gtk_progress_bar_new();
gtk_widget_set_hexpand(progress, TRUE);
gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(progress), TRUE);

GtkWidget *button1=gtk_button_new_with_label("Show Firmware Progress");
gtk_widget_set_hexpand(button1, TRUE);
//Some widgets to pass through the thread function to g_idle_add(). 
GtkWidget *widgets[]={progress, button1};
g_signal_connect(button1, "clicked", G_CALLBACK(start_thread), widgets);

GtkWidget *button2=gtk_button_new_with_label("Show a Dialog");
gtk_widget_set_hexpand(button2, TRUE);
g_signal_connect(button2, "clicked", G_CALLBACK(show_dialog), window);

GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), button1, 0, 0, 1, 1);
gtk_grid_attach(GTK_GRID(grid), progress, 0, 1, 1, 1);
gtk_grid_attach(GTK_GRID(grid), button2, 0, 2, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
   
gtk_widget_show_all(window);

gtk_main();
return 0;   
  }
static void start_thread(GtkWidget *widget, GtkWidget **widgets)
  {  
gtk_widget_set_sensitive(widget, FALSE); 
g_atomic_int_set(_active, 1);

thread=g_thread_new("TestThread", (GThreadFunc)thread_get_firmware, 
widgets);   
timeout_id=g_timeout_add(500, (GSourceFunc)check_progress, widgets[0]); 
  }
static gpointer thread_get_firmware(GtkWidget **widgets)
  {
//No GTK functions called in thread_get_firmware().
guint32 i=0;
gdouble percent=0;

for(i=0;i

Re: Show dialog after hide another

2017-09-09 Thread Stefan Salewski
On Fri, 2017-09-08 at 11:11 +, Rúben Rodrigues wrote:
> Please!!
> 
> Help..

Well, I guess what you want is displaying a message dialog without
prior user actions.

Maybe you can emit a signal to do that? I don't know, have never needed
that.

Maybe you can just modify your first dialog, display another text?

Or, maybe what you really want is something like the GtkAssistant, I
think that one is something that guides a user through a longer
sequence of actions.

Finally, you misses to tell us if you are using mainline GTK3 or a
different version, which OS, and what your great FOSS application on
which you are working is.


___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Show dialog after hide another

2017-09-09 Thread Rúben Rodrigues
Please!!

Help..


Às 17:08 de 06/09/2017, Rúben Rodrigues escreveu:
> Hi guys,
>
>
> I have i problem when trying to hide a dialog and show another at the
> same moment.
>
> I have a dialog that have an OK button that calls this function:
>
> void on_button_Util_Firmware_Update_clicked(GtkButton *button, gpointer
> user_data)
> {
>       GtkLabel    *gLabel_Result;
>       FILE        *fp;
>       gchar        pcTmp[BUFSIZ];
>
>       // Fecha a janela.
> gtk_widget_hide(GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button;
>
>       // Mostra a janela de espera.
>       gtk_widget_show(GTK_WIDGET(gtk_builder_get_object(builder,
> "Setup_Wait_dialog")));
>       sleep(10);
>
>    //**Running something inside
>
> // Esconde a janela de espera.
>       gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object(builder,
> "Setup_Wait_dialog")));
>
> }
>
> As you can see this is a Waiting dialog to show the status of the
> process, but the problem is  that don't show the Setup_Wait_dialog and
> don't hides the first dialog. What's wrong?
>
> Thanks
>
>
> ---
> Este e-mail foi verificado em termos de vírus pelo software antivírus Avast.
> https://www.avast.com/antivirus
>
> ___
> gtk-app-devel-list mailing list
> gtk-app-devel-list@gnome.org
> https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Show dialog after hide another

2017-09-07 Thread Nicola Fontana
Il Wed, 6 Sep 2017 16:08:07 + Rúben Rodrigues  
scrisse:

> ...
> void on_button_Util_Firmware_Update_clicked(GtkButton *button, gpointer 
> user_data)
> {
>      GtkLabel    *gLabel_Result;
>      FILE        *fp;
>      gchar        pcTmp[BUFSIZ];
> 
>      // Fecha a janela.
> gtk_widget_hide(GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button;
> 
>      // Mostra a janela de espera.
>      gtk_widget_show(GTK_WIDGET(gtk_builder_get_object(builder, 
> "Setup_Wait_dialog")));
>      sleep(10);
> ...

Hi Rúben,

this is the normal behavior in a single-threaded application: the
user interface is updated only when you release the CPU so that
the execution returns to the main loop:

https://developer.gnome.org/glib/stable/glib-The-Main-Event-Loop.html#glib-The-Main-Event-Loop.description

The rule of thumb is: never block, i.e. never put a `sleep(10)` or
something equivalent in your code otherwise you'll get what you
requested, in that case an unresponsive interface for 10 seconds.

If you have a heavy process, fork to a working thread or decompose
it in a loop that can be run incrementally with an idle callback.

Ciao.
-- 
Nicola
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Show dialog after hide another

2017-09-06 Thread Rúben Rodrigues
Hi guys,


I have i problem when trying to hide a dialog and show another at the 
same moment.

I have a dialog that have an OK button that calls this function:

void on_button_Util_Firmware_Update_clicked(GtkButton *button, gpointer 
user_data)
{
     GtkLabel    *gLabel_Result;
     FILE        *fp;
     gchar        pcTmp[BUFSIZ];

     // Fecha a janela.
gtk_widget_hide(GTK_WIDGET(gtk_widget_get_toplevel(GTK_WIDGET(button;

     // Mostra a janela de espera.
     gtk_widget_show(GTK_WIDGET(gtk_builder_get_object(builder, 
"Setup_Wait_dialog")));
     sleep(10);

  //**Running something inside

// Esconde a janela de espera.
     gtk_widget_hide(GTK_WIDGET(gtk_builder_get_object(builder, 
"Setup_Wait_dialog")));

}

As you can see this is a Waiting dialog to show the status of the 
process, but the problem is  that don't show the Setup_Wait_dialog and 
don't hides the first dialog. What's wrong?

Thanks


---
Este e-mail foi verificado em termos de vírus pelo software antivírus Avast.
https://www.avast.com/antivirus

___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list