how to process only some GTK events and leave the others in the queue

2008-12-28 Thread Francesco Montorsi

Hi,
   is it possible to process only some specific events from the GTK/GDK event 
queue and leave the others in the queue so they can be processed later by the 
main loop?


I'll try to explain it better: I have a GTK-based app which runs the gtk_main() 
in its void main().
However at a certain point (e.g. upon user click on a GtkButton), I need to 
perform a long computation. I don't want to use a secondary thread; rather I'd 
like to do everything from the main thread. To avoid blocking the GUI of my app 
during the computation, I call from time to time:


while (gtk_events_pending() != 0)
gtk_main_iteration();

to process the pending events in the queue. However now I'd like to process only 
_some_ of the events of the queue, and leave the others in the queue itself.


Is it possible?

Thanks!!
Francesco

--






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


Re: Asyncronous life helper (Was: EggDBus)

2008-12-28 Thread David Zeuthen
On Sat, 2008-12-27 at 20:35 +0100, Alexander Larsson wrote:
 On Sat, 2008-12-27 at 04:21 -0500, Freddie Unpenstein wrote:
  This is a side-topic, raised by developments in handling DBus, but
  something I feel is worth asking... Is there any mechanism for making
  working with asynchronous stuff easier?
  
  Quite often I've had a situation where I've needed to collect several
  pieces of information from various asynchronous sources, and then act
  on them as a group only once some portion of that information is
  available. This is becoming increasingly important as we start working
  with more and more remote DBus services, web services,
  Corba/Orb/whatever-its-presently-called services, and the list goes
  on. Data life cycle and flow management keeps being a problem.
  
  You need to:
  - use a signal to catch data when it becomes available
  - store that data somewhere
  - distribute that data to other places when it becomes available
  - clean up the data when it's no longer needed
  - safely handle data sources failing or disappearing
  - manage re-try timeouts, age invalidation timeouts, etc.
  
  I sort of feel that what's needed, is a GWish which is a higher-level
  GBoxed embodying the whole data life cycle management, and I'm
  wondering whether there are any plans or similar ideas in the works,
  or even just whether anyone else has a working example of tackling a
  similar situation.
  
  My starter concept is this; GWish will
  - hold a piece of data, when it's available
  - can be asked to obtain its data if it doesn't have it
  - can be dependant on other GWish's (dependant data)
  - ask any depedant GWishes for theirs when it is asked
  - invoke a callback when ALL dependant data is available
  - can be given the data to hold at any time (usually by the callback)
  - signal when its data is ready (ie. when its data is set)
  - only ask dependant GWish's when it itself is asked
  - provide a helper function to perform the ask, and then wait
  - allow the data to be invalidated without destroying the GWish
  - be used internally (or at least faked externally) by async
  properties
  - propagate data invalidation (unless blocked by a flag or ignored)
  - allow some dependant data to be flagged as optional
  - allow the data set callback to fail after requesting more data
  - optionally count a dependency as a reference on that GWish
  - use weak references to clean up non-referencing dependencies
  - support relevant timeouts with automatic timeout cleanup
  - optionally destroy itself if a dependancy gets destroyed
  
  An application can then tie together various pieces of required data
  from any source (either GWish-compatible or wrapped in an external
  GWish), even user interaction, by having the final GWish dependant on
  other GWishes, some representing other intermediate shared data, and
  others representing source data, or simply stages of processing to
  ensure certain events occur in order regardless of what order their
  data becomes available.
 
 This sounds quite nice actually. There are many cases where something
 like this would have helped me.
 
 Another possible name for this is GFuture, as such objects are about
 information or other things that'll be availible in the future.

This sounds very similar to how it's handled in ACE

http://www.dre.vanderbilt.edu/Doxygen/Stable/ace/classACE__Future.html

One thing I did in EggDBus as compared to GIO, was to make the async
functions return a pending call id, e.g.

 guint some_async_function (const gchar *stuff,
GCancellable*cancellable,
GAsyncReadyCallback  callback,
gpointer user_data);

so you can write

 foo-pending = some_async_function(stuff, NULL, async_ready, NULL);

and later

 egg_dbus_connection_pending_call_cancel (con, foo-pending);

to cancel. Or you can do

 egg_dbus_connection_pending_call_block (con, foo-pending);

to block. It's not farfetched, I think, to have a GFuture base class so
you can do

 GFuture *future;
 future = g_future_get (foo-pending_call);
 g_object_set_data (future, other-stuff, other_stuff, g_object_unref);

and the GFuture object would be unreffed when the pending call is
finished.

In libgio, all async functions currently don't return anything. I think
we can make them return a pending call id without breaking ABI.

 One major problem about doing things like this in C is that you
 constantly have to define and allocate small structs to keep the data
 you need for the completo operation. If we could somehow make this
 easier that would be a large win. I don't know a great approach to do
 that offhand though. Some form of user data is one possibility, but I'd
 really like it to betype safe and without using strings as API.

If you want type safety you could subclass GFuture and do this

 subclassed_future = my_subclassed_future_new (...);
 g_future_set (foo-pending_call, 

Re: how to process only some GTK events and leave the others in the queue

2008-12-28 Thread Francesco Montorsi

Tristan Van Berkom ha scritto:

On Sun, Dec 28, 2008 at 6:45 AM, Francesco Montorsi

Is it possible?


Hi, for some odd cases you can use:
   http://library.gnome.org/devel/gdk/stable/gdk-Events.html#gdk-event-put

i.e. by pumping the events out of the event queue yourself, and putting the
ones you didnt process back.

Thanks, this can be quite useful!



I doubt this is what you need, I think that removing the while
(gtk_events_pending())
code all together and replacing it with more returns to the event
loop, and shorter
iterations in timeouts and signal callbacks - will probably fix
whatever problems
you are having.
I agree this would be indeed the best thing but actually the situation is 
somewhat more complex of what I described (in reality, it regards a wxWidgets 
application...)


Thanks for the gdk_event_put trick hint!
Francesco


--






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


gtk clipboard word 2003

2008-12-28 Thread ChilliMac

Hello,

I'm developing a python application written in python and using gtk. I 
need to copy a gtk image and paste it into Microsoft Word 2003. Pasting 
to Excel 2003, WordPad, Paint and so on, works perfect, but not to Word 
2003. When i try to paste the image there, just nothing happens.


This is the piece of code, that should do the job:


pm = gtk.gdk.Pixmap(None, swidth, sheight, 24)
cc = pm.cairo_create()
_draw_barcode(cc, barcode, text)
pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, swidth, sheight)
pb = pb.get_from_drawable(pm, pm.get_colormap(), 0, 0, 0, 0, swidth,

sheight)

clipboard = gtk.clipboard_get(gtk.gdk.SELECTION_CLIPBOARD)
clipboard.set_image(pb)


Does anyone know, how pasting pixbufs to Word 2003 works?

Greetings,
ChilliMac


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