[Stoq-devel] [Bug 1988] - Suporte à fotografia no editor de produtos

bugzilla-daemon at async.com.br bugzilla-daemon at async.com.br
Mon Jul 24 18:47:54 BRT 2006


http://bugs.async.com.br/show_bug.cgi?id=1988  





--- Comment #13 from Johan Dahlin <jdahlin at async.com.br>  2006-07-24 18:47 BRT ---
(From update of attachment 3342)
>Index: stoqlib/stoqlib/gui/slaves/image.py

>+_ = stoqlib_gettext
>+
>+class ImageSlave(SlaveDelegate):
>+    """A slave view showing a image inside a gtk.Button. When clicked
>+    it opens a dialog for selecting a new image"""
>+
>+    gladefile = 'ImageHolder'
>+
>+    # Signal emition.
>+    gsignal('pixbuf-selected', gtk.gdk.Pixbuf)
>+
>+    def on_image_button__clicked(self, button):
>+        # generating a list of suported formats extensions
>+        # to 'open' function
>+        formats = gtk.gdk.pixbuf_get_formats()
>+        ext_list = []
>+        for each_format in formats:
>+            ext_list += each_format["extensions"]
>+        for i in range(len(ext_list)):
>+            ext_list[i] = "*." + ext_list[i]
>+

patterns is a better name, instead of ext_list.

I think you can do this in a nested loop:

patterns = []
for format in gtk.gdk.pixbuf_get_formats()
  for extension in format["extensions"]:
     patterns.append('*.' + extension)

which is a bit nicer, no?

>+        pixbuf = gtk.gdk.pixbuf_new_from_file_at_size(filename, 64, 64)
>+        image = gtk.Image()
>+        image.set_from_pixbuf(pixbuf)
>+        self.emit('pixbuf-selected', pixbuf)
>+        self.image_button.set_image(image)

I think you want to emit the signal as the last thing you do in here.

We're still missing the database changes and a proxy button.
You can use the following two routines to save/load from the database

from kiwi.datatypes import converter

pixbuf_converter = converter.get(gtk.gdk.Pixbuf)
str = pixbuf_converter.to_string(pixbuf)

and

pixbuf = pixbuf_converter.from_string(str)

Also check comment 2 on how to add a database field, it should probably be
added to a Product or to a AbstractSellable.


More information about the Stoq-devel mailing list