Re: GTK+ 3.6 threading?

2012-10-24 Thread Dmitrijs Ledkovs
On 24 October 2012 04:34, Ardhan Madras ard...@rocksis.net wrote:

 Hi,

  Now that from GTK+ 3.6, thread functions are deprecated.  Is there any
  new rules to do threading with the gtk+ 3.6 version?

 Are you talking about Glib? yes, there are many changes since 2.32
 (for now stable version is 2.34), from high level view, the changes
 such as new thread creation functions, thread reference counting
 functions, thread synchronization tools, etc. and many other functions
 and macros has been removed.


Comparing:
http://developer.gnome.org/gdk3/3.4/api-index-deprecated.html
http://developer.gnome.org/gdk3/stable/api-index-deprecated.html

I can see that gdk_threads were recently removed. But there is no
guide on how to move away from those.

Regards,

Dmitrijs.

 In 2.32 and above to create a thread you will use the new
 g_thread_new() or the g_thread_try_new() (previously with
 g_thread_create()), to create synchronization tools for example a
 rwlock then you call g_rwlock_init (previously g_rwlock_new() or
 G_STATIC_RWLOCK_INIT), call g_thread_unref() after you finish with the
 thread.

  I tried */g_main_context_invoke/*, but seems it did not work. I can't
  update GUI from that GSourceFunc. Maybe is my mistaken use...

 I don't understand why you call g_main_context_invoke() here but If
 you want to call GTK+ functions from your thread, the safe method is
 to wrap the functions to a GSourceFunc and call it with g_idle_add()
 or g_idle_add_full() (from your thread function).

 Regards.


 On Tue, Oct 23, 2012 at 9:43 AM, Weitian Leung just_fa...@live.com wrote:
  Hi,
  Now that from GTK+ 3.6, thread functions are deprecated.  Is there any
  new rules to do threading with the gtk+ 3.6 version?
  Just for an example, I want to download many files in background, and
  show the progress in GUI, how should I do it?
  I tried */g_main_context_invoke/*, but seems it did not work. I can't
  update GUI from that GSourceFunc. Maybe is my mistaken use...
  Anyone know how? Or just give me some examples.
 
  Sorry for my bad English.
  Thanks.
 
  --
  Weitian
 
  ___
  gtk-app-devel-list mailing list
  gtk-app-devel-list@gnome.org
  https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



 --
 Please do not send me any propriety format such as Microsoft Offices:
 Word, Excel, Power Point, etc. Please use standard non-propriety
 format such as plain text, HTML, PDF or OpenOffices format.

 ROCKSIS | Indonesia
 ___
 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: GTK+ 3.6 threading?

2012-10-24 Thread Osmo Antero
Hello,
What if the GSourceFunc blocks for a longer time, eg. for 3 seconds time.
Does it freeze the GUI because it runs within the main-loop?

One possible approach:
My audio-recorder uses a message queue (g_async_queue_new()) to receive
data from various modules and threads.
Ref:
http://bazaar.launchpad.net/~osmoma/audio-recorder/trunk/view/head:/src/rec-manager.c
(notice: this solution is too slow to update a progressbar or levelbar may
times a second).

This message queue is checked continuously by a thread which then updates
the GUI, starts/stops/pauses recording etc.
See the rec_manager_init() function.

Various parts of the program can send messages to the GUI/app by calling:

void rec_manager_send_command(RecorderCommand *cmd) {
// Push command to the queue
g_async_queue_push(g_cmd_queue, (gpointer)cmd);
}

void rec_manager_init() {
LOG_DEBUG(Init rec-manager.c.\n);

// Create a message queue
// Ref: http://www.gtk.org/api/2.6/glib/glib-Asynchronous-Queues.html
g_cmd_queue = g_async_queue_new();

// Message thread within GTK's main loop
// Ref: http://developer.gnome.org/glib/2.31/glib-The-Main-Event-Loop.html
g_thread_id =  g_timeout_add_full(G_PRIORITY_DEFAULT, 200,
rec_manager_command_thread, NULL, NULL);

// Init recorder.c
rec_module_init();
}

Audio-recorder
https://launchpad.net/audio-recorder

Kindly
  Moma Antero


On Wed, Oct 24, 2012 at 4:34 AM, Ardhan Madras ard...@rocksis.net wrote:

 Hi,

  Now that from GTK+ 3.6, thread functions are deprecated.  Is there
any
  new rules to do threading with the gtk+ 3.6 version?

 Are you talking about Glib? yes, there are many changes since 2.32
 (for now stable version is 2.34), from high level view, the changes
 such as new thread creation functions, thread reference counting
 functions, thread synchronization tools, etc. and many other functions
 and macros has been removed.

 In 2.32 and above to create a thread you will use the new
 g_thread_new() or the g_thread_try_new() (previously with
 g_thread_create()), to create synchronization tools for example a
 rwlock then you call g_rwlock_init (previously g_rwlock_new() or
 G_STATIC_RWLOCK_INIT), call g_thread_unref() after you finish with the
 thread.

  I tried */g_main_context_invoke/*, but seems it did not work. I
can't
  update GUI from that GSourceFunc. Maybe is my mistaken use...

 I don't understand why you call g_main_context_invoke() here but If
 you want to call GTK+ functions from your thread, the safe method is
 to wrap the functions to a GSourceFunc and call it with g_idle_add()
 or g_idle_add_full() (from your thread function).

 Regards.


 On Tue, Oct 23, 2012 at 9:43 AM, Weitian Leung just_fa...@live.com
wrote:
  Hi,
  Now that from GTK+ 3.6, thread functions are deprecated.  Is there
any
  new rules to do threading with the gtk+ 3.6 version?
  Just for an example, I want to download many files in background,
and
  show the progress in GUI, how should I do it?
  I tried */g_main_context_invoke/*, but seems it did not work. I
can't
  update GUI from that GSourceFunc. Maybe is my mistaken use...
  Anyone know how? Or just give me some examples.
 
  Sorry for my bad English.
  Thanks.
 
  --
  Weitian
 
  ___
  gtk-app-devel-list mailing list
  gtk-app-devel-list@gnome.org
  https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list



 --
 Please do not send me any propriety format such as Microsoft Offices:
 Word, Excel, Power Point, etc. Please use standard non-propriety
 format such as plain text, HTML, PDF or OpenOffices format.

 ROCKSIS | Indonesia
 ___
 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: GTK+ 3.6 threading?

2012-10-24 Thread Emmanuele Bassi
hi;

On 24 October 2012 10:17, Dmitrijs Ledkovs dmitrij.led...@ubuntu.com wrote:
 On 24 October 2012 04:34, Ardhan Madras ard...@rocksis.net wrote:
 I can see that gdk_threads were recently removed. But there is no
 guide on how to move away from those.

you should probably read this thread:

https://mail.gnome.org/archives/gtk-list/2012-September/msg8.html

in short: you can only use GTK and GDK functions (except the ones that
start with gdk_threads_*) from the same thread that called gtk_main();
if you use another thread, schedule your UI updates through the main
loop.

ciao,
 Emmanuele.

-- 
W: http://www.emmanuelebassi.name
B: http://blogs.gnome.org/ebassi/
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Clarification on recent deprecations

2012-10-24 Thread David Buchan
Based on recent discussion on threads/idles/timeouts, I wonder if I 
could get confirmation that what I'm doing to remove deprecated stuff is 
correct.

Current Situation:

Ubuntu 10.04

libgtk2.0-dev
3.7.0.is.3.6.7-0ubuntu1

Makefile contains:

CCFLAGS = `pkg-config --cflags gtk+-2.0 gmodule-2.0`
LIBS    = `pkg-config --libs   gtk+-2.0 gmodule-2.0`

I use glade to create the user interface file.

Code contains:

g_thread_init()
gtk_init()
gtk_builder_add_from_file()
g_slice_new()
g_object_unref ()   [to destroy builder]
gtk_main()
g_timeout_add()
G_LOCK_DEFINE_STATIC
g_idle_add()
g_thread_create()
G_LOCK()
G_UNLOCK()

I will go to:

Ubuntu 12.10

libgtk-3-dev
glade 3.14.0-0ubuntu1

Makefile to contain:

LIBS    = `pkg-config --libs   gtk+-3.0 gmodule-2.0`
CCFLAGS = `pkg-config --cflags gtk+-3.0 gmodule-2.0`

Do
 I need to change the link to gmodule-2.0? To be honest, I really don't 
understand what it's for. Is there a good explanation somewhere?

I use glade to create the user interface file.

In my code, I will only replace g_thread_create() with g_thread_new().

Have
 I got it right? My main concern is that the idle function, timeout 
function, and thread calls listed above are still ok, with the one 
change to use g_thread_new().

g_timeout_add() is called from the main iteration.
g_thread_create() is only called from the main iteration.
g_idle_add() is only called from child threads created with g_thread_create() 
calls in the main iteration.
G_LOCK and G_UNLOCK are called from the child threads mentioned immediately 
above.
G_LOCK_DEFINE_STATIC was called in the main iteration.

There's one other update on dialogs which is clear to me already.

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


Re: Clarification on recent deprecations

2012-10-24 Thread Michael Cronenworth
David Buchan wrote:
 Do
  I need to change the link to gmodule-2.0? To be honest, I really don't 
 understand what it's for. Is there a good explanation somewhere?

You can always find your pc files in:

/usr/lib{64}/pkgconfig

Example:
/usr/lib64/pkgconfig/gmodule-2.0.pc

Inside the file will contain the flags that are passed to the compiler.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


GtkHBox child replacement

2012-10-24 Thread Piotr Sipika
Greetings.

I'm working on a small application which, in its window, contains a
single HBox. The HBox contains two children: an icon and a label.

During execution the backend is supposed to update the icon and the text
in the label.

I can reference the icon and label children of the HBox by calling
gtk_container_get_children() on the HBox and getting items 0 and 1,
respectively.

While updating the text inside the label is easy (via
gtk_label_set_text()), what's the best way to update the icon child,
assuming it's a GtkImage and I have an updated GdkPixbuf for a new icon?

Thanks!

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


Re: GtkHBox child replacement

2012-10-24 Thread Michael Cronenworth
Piotr Sipika wrote:
 While updating the text inside the label is easy (via
 gtk_label_set_text()), what's the best way to update the icon child,
 assuming it's a GtkImage and I have an updated GdkPixbuf for a new icon?

You want to call gtk_image_set_from_pixbuf(). Don't forget to call
g_object_unref() on the new GdkPixbuf after each update.
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list


Re: [Solved] Re: [gobject-introspection] callback without GDestroyNotify

2012-10-24 Thread Mohan R
On Tue, 2012-10-23 at 19:43 +0100, Emmanuele Bassi wrote:
 hi;
 
 don't use the G namespace for you code unless you plan on submitting
 it for inclusion in GLib. 
 
 If you're writing a gtweet library, then the namespace ought to be
 Gtweet. 
 
 ciao, 
 Emmanuele. 

Of course I'm going to submit to gnome. But I'm trying to get it
introspection ready and create a small application before submitting.
Without introspection writing a webapi library is useless.

Introspection solves one of the biggest pain which is converting json to
a c struct. Now I can directly export json responses from twitter to
gjs/seed.

Reason for another twitter library? (1) for my learning purpose (2)
twitter-glib is not compatible with current twitter-api, (3) I didn't
dig more about libsocialweb, but in my point of view, one-thing-fit-all
is not the right way for twitter because twitter-api is not stable, they
change things whenever they like.

Code is in github (https://github.com/mohan43u/tweetpts/tree/gtweet) but
its not ready. I don't know gnome will accept this one when I submit.
But, I'm doing this for my personal learning. Introspection is very
exciting.

Thanks,
Mohan R

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


Re: [Solved] Re: [gobject-introspection] callback without GDestroyNotify

2012-10-24 Thread Alexander Larsson
On ons, 2012-10-24 at 11:34 +0530, Mohan R wrote:
 On Tue, 2012-10-23 at 19:43 +0100, Emmanuele Bassi wrote:
  hi;
  
  don't use the G namespace for you code unless you plan on submitting
  it for inclusion in GLib. 
  
  If you're writing a gtweet library, then the namespace ought to be
  Gtweet. 
  
  ciao, 
  Emmanuele. 
 
 Of course I'm going to submit to gnome. But I'm trying to get it
 introspection ready and create a small application before submitting.
 Without introspection writing a webapi library is useless.

Writing a library is one thing, but using a prefix like g_ in
g_tweet_object_samplestream implies that this is part of glib. You need
to use a different prefix, like gtweet_ or you risk conflicts with
later symbols added to glib.



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


Re: [Solved] Re: [gobject-introspection] callback without GDestroyNotify

2012-10-24 Thread Emmanuele Bassi
hi;

On 24 October 2012 07:04, Mohan R mohan...@gmail.com wrote:
 On Tue, 2012-10-23 at 19:43 +0100, Emmanuele Bassi wrote:
 hi;

 don't use the G namespace for you code unless you plan on submitting
 it for inclusion in GLib.

 If you're writing a gtweet library, then the namespace ought to be
 Gtweet.

 ciao,
 Emmanuele.

 Of course I'm going to submit to gnome.

that's not what I wrote, but I apologize if I came across as a bit too terse.

you should not be using the g_*/G* namespace unless you're
contributing code to GLib (glib, gobject, gio) — not GNOME.

using the g_* namespace from other components may very well lead to
symbol collision.

ciao,
 Emmanuele.

-- 
W: http://www.emmanuelebassi.name
B: http://blogs.gnome.org/ebassi/
___
gtk-devel-list mailing list
gtk-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-devel-list


Re: [Solved] Re: [gobject-introspection] callback without GDestroyNotify

2012-10-24 Thread Mohan R
On Wed, 2012-10-24 at 10:42 +0100, Emmanuele Bassi wrote:

 you should not be using the g_*/G* namespace unless you're
 contributing code to GLib (glib, gobject, gio) — not GNOME.
 
 using the g_* namespace from other components may very well lead to
 symbol collision.

Sorry, I was confused. So, I have to change g_tweet_ to gtweet_ and use
'gtweet' as my namespace instead of 'g'.

Actually, while creating GTweetObject class, I did just what you said
(using gtweet_object_get_type() instead of g_tweet_object_get_type()).
but somehow ended-up doing g_tweet while fixing issues thrown by
g-ir-scanner. It started working after I changed by namespace to 'g'
instead of 'gtweet'. May be because I was wrong in annotations and
unfamiliarity with g-ir-scanner. I'll fix it.

Thanks you for pointing out.

Thanks,
Mohan R

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