Re: Updating GUI during long operation

2013-04-27 Thread Kip Warner
On Fri, 2013-04-26 at 20:22 -0700, Simon Feltman wrote:

> To clarify, Python threading is probably the wrong tool for CPU bou d
> operations unless those operations free up the GIL.

This might be, but ideally this is really something the designers of the
various interpreters should be more concerned with than the user of the
language. But I understand what you are saying.


> Unless the GDK/GTK calls within the callback scheduled by
> GObject.idle_add are explicitly surrounded with
> Gdk.threads_enter/leave() along with a call Gdk.threads_init() at
> program start, then chances are the problems you ran into are related
> to GDK/GTK calls not being thread safe and the callback not holding
> the GDK global lock. As Nicola mentioned, Gdk.threads_add_idle does
> this for you. Also note that Gdk.threads_enter/leave are essentially
> no-ops unless Gdk.threads_init is called.

It makes sense since Gdk.threads_add_idle() is higher level than a
GObject interface.

> My confusion regarding these APIs stems from some of them being marked
> as deprecated since version 3.6 (Gdk.threads_init and
> Gdk.threads_enter/leave). In this case it is unclear whether or not
> Gdk.threads_init is still necessary when using Gdk.threads_add_idle
> with GTK+ >= 3.6.

I think the safe thing to do if one isn't absolutely certain of the
specific runtime version the user will be relying on and the
documentation is still ambiguous or inconsistent, depending on where you
are looking, is to just call both GObject.threads_init() and
Gdk.threads_init() for good measure.

Thanks for your help, Simon.

-- 
Kip Warner -- Software Engineer
OpenPGP encrypted/signed mail preferred
http://www.thevertigo.com
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: gtk_widget_set_size_request delayed until next allocation change

2013-04-27 Thread jjacky

On 04/27/13 02:35, Sandro Mani wrote:
> Hello,
> 
> I have a GtkDrawingArea inside a GtkViewport, and I have a callback
> connected to the "size-allocate" signal of the GtkViewport which resizes
> the GtkDrawingArea by calling gtk_widget_set_size_request on the latter,
> see sample source code below.
> 
> I however notice that the GtkDrawingArea allocates the requested size
> only the _next_ time the allocation of the GtkViewport changes, and
> hence the allocation of the GtkDrawingArea is the one requested for the
> previous allocation of the GtkViewport.
> 
> The issue is best visible when maximizing and unmaximizing the window:
> when maximizing, the size of the GtkDrawingArea is still the one for the
> unmaximized state, and when unmaximizing again, the size of the
> GtkDrawingArea is the one for the maximized state.
> 
> Question: Is this a mistake in my code or a Gtk bug? I'm using
> gtk3-3.8.1-1.fc20.x86_64

Seems you could fix it by setting GTK_RESIZE_IMMEDIATE as resize mode on
the viewport, although it seems to be deprecated.

I'm not sure what's the proper/recommended way to go it instead, but
instead of calling gtk_widget_queue_resize() and the
gtk_main_iteration() loop in resize_drawarea() you could call
gtk_container_resize_children() (on the viewport).
Although, since it triggers a new size-allocate, it might be a good idea
to block your handler to avoid it getting triggered again.

-j

> Thanks for any inputs.
> 
> Sandro
> 
> -- Sample code: --
> // gcc alloc.c -o alloc $(pkg-config --cflags --libs gtk+-3.0)
> #include 
> #include 
> 
> void resize_drawarea (GtkWidget* viewport, GdkRectangle* rect, gpointer
> data)
> {
>   gtk_widget_set_size_request (GTK_WIDGET (data), rect->width / 2,
> rect->height / 2);
>   gtk_widget_queue_resize (GTK_WIDGET (data));
>   printf("set_size_request(%d, %d)\n", rect->width /2, rect->height / 2);
>   // Wait for size_request
>   while (gtk_events_pending ()) {
> gtk_main_iteration ();
>   }
>   int w = gtk_widget_get_allocated_width (GTK_WIDGET (data));
>   int h = gtk_widget_get_allocated_height (GTK_WIDGET (data));
>   printf("allocation = %d x %d\n\n", w, h);
> }
> 
> int main(int argc, char* argv[])
> {
>   gtk_init (&argc, &argv);
>   GtkWidget* window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>   GtkWidget* viewport = gtk_viewport_new (NULL, NULL);
>   GtkWidget* drawarea = gtk_drawing_area_new ();
> 
>   gtk_container_add (GTK_CONTAINER (window), viewport);
>   gtk_container_add (GTK_CONTAINER (viewport), drawarea);
> 
>   gtk_widget_set_halign (drawarea, GTK_ALIGN_CENTER);
>   gtk_widget_set_valign (drawarea, GTK_ALIGN_CENTER);
>   GdkRGBA black = {0., 0., 0., 1.};
>   gtk_widget_override_background_color (drawarea, GTK_STATE_FLAG_NORMAL,
> &black);
>   gtk_window_set_default_size (GTK_WINDOW (window), 640, 480);
> 
>   g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
>   g_signal_connect (viewport, "size-allocate", G_CALLBACK
> (resize_drawarea), drawarea);
> 
>   gtk_widget_show_all (window);
>   gtk_main ();
>   return 0;
> }
> 
> ___
> 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