Hi,

sounds like a good idea.

While I dont know enough python C extension syntax, I can provide the code
for the gtk part. Pseudo code is like this:

def GtkImage.set_from_file(self, arg):

GdkPixbufLoader *loader;
int readcnt;
char buf[4096];

if type(arg) != type(file):
  return native_gtk_image_set_from_file(self.underlying, arg.char*)

loader = gdk_pixbuf_loader_new()

do: 
  readcnt,buf = arg.read(sizeof(buf))
  if readcnt > 0:
    gdk_pixbuf_loader_write(loader, buf, readcnt)
while readcnt > 0
if readcnt == -1:
  g_object_unref(loader)
  raise error

gdk_pixbuf_loader_close(loader)
pixbuf = gdk_pixbuf_loader_get_pixbuf(loader)
if pixbuf:
  g_object_ref(pixbuf)
else:
   g_object_unref(loader)
   raise error

g_object_unref(loader)
self.set_from_pixbuf(pixbuf)

Someone else please put in the stuff I dont know know to implement, which
is:

- if type(arg) != type(file)
  Dont know if that is checked that easily or if rather every python object
that has a read method should work. if so, it should be checked if the read
method is present in the arg object

- arg.read
  This is supposed to call the read method and store the result in buf and
readcount. Should probably also handle exceptions gracefully:

- handle (and pass to caller) python exceptions correctly (or are they just
fired after the interpreter returns to interpreting? - note that the read
call also needs to be interpreted so that could intercept the exception from
the previous read if not having the exception serve as a break condition for
the loop)

cheers,
  Danny

> I think that some methods like gtk.Image.set_from_file() should > accept
as argument not only the filename as string but also a 
> file object.

> In this way should be possible to use file-like objects as
> StringIO, when for example you have an in Image represented 
> in a string and you don't want to write it to a file and 
> then read it again.


-- 
10 GB Mailbox, 100 FreeSMS http://www.gmx.net/de/go/topmail
+++ GMX - die erste Adresse f�r Mail, Message, More +++
_______________________________________________
pygtk mailing list   [email protected]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to