Hello all, (maybe this topic should go in the developer section...) I was in great need of a way to add Thumbnail pictures in my Product view, and no way to use the widget image to show it (I really wanted to have thumbnails with a clickable link --> open it in a browser) So I just finish to modifie the picture.py in the client directory : client/widget/view/form_gtk/picture.py
class wid_picture(interface.widget_interface): def __init__(self, window, parent, model, attrs={}): interface.widget_interface.__init__(self, window, parent=parent, attrs=attrs) self._value = '' self.height = int(attrs.get('img_height', 100)) self.width = int(attrs.get('img_width', 100)) self.widget = gtk.VBox(spacing=3) self.event = gtk.EventBox() self.tooltips = gtk.Tooltips() self.image = gtk.Image() self.event.add(self.image) self.widget.pack_start(self.event, expand=True, fill=True) self.alignment = gtk.Alignment(xalign=0.5, yalign=0.5) self.hbox = gtk.HBox(spacing=3) #### Create the link button self.button = gtk.Button() img = gtk.Image() img.set_from_stock('gtk-jump-to', gtk.ICON_SIZE_BUTTON) self.button.set_image(img) self.button.set_relief(gtk.RELIEF_NONE) self.button.connect('clicked', self.button_clicked) self.button.set_alignment(0.5, 0.5) self.button.set_property('can-focus', False) self.widget.pack_start(self.button, expand=False, fill=False) #### self.alignment.add(self.hbox) self.widget.pack_start(self.alignment, expand=False, fill=False) self.tooltips.enable() self.update_img() def update_img(self): if not self._value: data = NOIMAGE else: data = urllib.urlopen(self._value).read() pixbuf = None for type in ('jpeg', 'gif', 'png', 'bmp'): loader = gtk.gdk.PixbufLoader(type) try: loader.write(data, len(data)) except: continue pixbuf = loader.get_pixbuf() if pixbuf: break if not pixbuf: loader = gtk.gdk.PixbufLoader('png') loader.write(NOIMAGE, len(NOIMAGE)) pixbuf = loader.get_pixbuf() loader.close() img_height = pixbuf.get_height() if img_height > self.height: height = self.height else: height = img_height img_width = pixbuf.get_width() if img_width > self.width: width = self.width else: width = img_width if (img_width / width) < (img_height / height): width = float(img_width) / float(img_height) * float(height) else: height = float(img_height) / float(img_width) * float(width) scaled = pixbuf.scale_simple(int(width), int(height), gtk.gdk.INTERP_BILINEAR) self.image.set_from_pixbuf(scaled) def display(self, model, model_field): if not model_field: return False self._value = model_field.get(model) super(wid_picture, self).display(model, model_field) self.update_img() def set_value(self, model, model_field): return model_field.set_client(model, self._value or False) def button_clicked(self, widget): tools.launch_browser(self._value) After having this file modified, you'll have to add in the _view.xml a field with widget="picture" and in the .py a fields.char (it will contain the path of the picture). Hope it could be usefull... Eric ps:I will clean the code during this week and add other buttons (eg : add/save/del)[/code] _______________________________________________ Tinyerp-users mailing list http://tiny.be/mailman/listinfo/tinyerp-users
