From 155db5b5f22aa5e1ae91ad3d45cbecb8a3415118 Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Thu, 18 Sep 2014 12:54:36 +0200 Subject: [PATCH] Add patches for issue3729 --- issue3991003_40001.diff | 48 ++++++++++ issue4011003_200001.diff | 188 +++++++++++++++++++++++++++++++++++++++ series | 2 + 3 files changed, 238 insertions(+) create mode 100644 issue3991003_40001.diff create mode 100644 issue4011003_200001.diff diff --git a/issue3991003_40001.diff b/issue3991003_40001.diff new file mode 100644 index 0000000..5c112c3 --- /dev/null +++ b/issue3991003_40001.diff @@ -0,0 +1,48 @@ +Index: trytond/trytond/ir/ui/tree.rnc +=================================================================== + +--- a/trytond/trytond/ir/ui/tree.rnc ++++ b/trytond/trytond/ir/ui/tree.rnc +@@ -39,6 +39,7 @@ + | "reference" + | "one2one" + | "binary" ++ | "image" + }? + attlist.field &= + [ a:defaultValue = "0" ] attribute tree_invisible { "0" | "1" }? +@@ -47,6 +48,7 @@ + attlist.field &= attribute icon { text }? + attlist.field &= attribute sum { text }? + attlist.field &= attribute width { text }? ++attlist.field &= attribute height { text }? + attlist.field &= + [ a:defaultValue = "left_to_right" ] attribute orientation { + "left_to_right" + +Index: trytond/trytond/ir/ui/tree.rng +=================================================================== + +--- a/trytond/trytond/ir/ui/tree.rng ++++ b/trytond/trytond/ir/ui/tree.rng +@@ -101,6 +101,7 @@ + reference + one2one + binary ++ image + + + +@@ -142,6 +143,11 @@ + + + ++ ++ ++ ++ ++ + + + left_to_right + diff --git a/issue4011003_200001.diff b/issue4011003_200001.diff new file mode 100644 index 0000000..729e3eb --- /dev/null +++ b/issue4011003_200001.diff @@ -0,0 +1,188 @@ +Index: tryton/tryton/common/cellrendererimage.py +=================================================================== +new file mode 100644 + +--- /dev/null ++++ b/tryton/tryton/common/cellrendererimage.py +@@ -0,0 +1,25 @@ ++#This file is part of Tryton. The COPYRIGHT file at the top level of ++#this repository contains the full copyright notices and license terms. ++import gtk ++import gobject ++ ++ ++class CellRendererImage(gtk.GenericCellRenderer): ++ ++ def __init__(self): ++ self.__gobject_init__() ++ self._renderer = gtk.CellRendererPixbuf() ++ self.pixbuf = None ++ ++ def on_get_size(self, widget, cell_area): ++ return self._renderer.get_size(widget, cell_area) ++ ++ def on_render(self, window, widget, background_area, cell_area, ++ expose_area, flags): ++ self._renderer.set_property('pixbuf', self.pixbuf) ++ ++ return self._renderer.render(window, widget, background_area, ++ cell_area, expose_area, flags) ++ ++ ++gobject.type_register(CellRendererImage) + +Index: tryton/tryton/common/common.py +=================================================================== + +--- a/tryton/tryton/common/common.py ++++ b/tryton/tryton/common/common.py +@@ -1534,3 +1534,25 @@ + if size < 1000: + return '%3.1f%s' % (size, x) + size /= 1000.0 ++ ++ ++def raw_data2pixbuf(data): ++ pixbuf = None ++ for ftype in ('jpeg', 'gif', 'png', 'bmp', 'svg'): ++ try: ++ loader = gtk.gdk.PixbufLoader(ftype) ++ loader.write(data, len(data)) ++ loader.close() ++ pixbuf = loader.get_pixbuf() ++ except glib.GError: ++ continue ++ if pixbuf: ++ break ++ if not pixbuf: ++ no_image = open(os.path.join(PIXMAPS_DIR, 'tryton-noimage.png'), ++ 'rb').read() ++ loader = gtk.gdk.PixbufLoader('png') ++ loader.write(no_image, len(no_image)) ++ loader.close() ++ pixbuf = loader.get_pixbuf() ++ return pixbuf + +Index: tryton/tryton/gui/window/view_form/view/form_gtk/image.py +=================================================================== + +--- a/tryton/tryton/gui/window/view_form/view/form_gtk/image.py ++++ b/tryton/tryton/gui/window/view_form/view/form_gtk/image.py +@@ -1,19 +1,16 @@ + #This file is part of Tryton. The COPYRIGHT file at the top level of + #this repository contains the full copyright notices and license terms. + import gtk +-import glib + import gettext + import os + import tempfile +-from tryton.common import file_selection, Tooltips, file_open, slugify +-from tryton.config import PIXMAPS_DIR ++from tryton.common import (file_selection, Tooltips, file_open, slugify, ++ raw_data2pixbuf) + from interface import WidgetInterface + import urllib + + _ = gettext.gettext + +-NOIMAGE = open(os.path.join(PIXMAPS_DIR, 'tryton-noimage.png'), 'rb').read() +- + + class Image(WidgetInterface): + +@@ -203,28 +200,8 @@ + value = False + else: + value = self.field.get_data(self.record) +- if not value: +- data = NOIMAGE +- else: +- data = value + +- pixbuf = None +- for ftype in ('jpeg', 'gif', 'png', 'bmp', 'svg'): +- try: +- loader = gtk.gdk.PixbufLoader(ftype) +- loader.write(data, len(data)) +- loader.close() +- pixbuf = loader.get_pixbuf() +- except glib.GError: +- continue +- if pixbuf: +- break +- if not pixbuf: +- loader = gtk.gdk.PixbufLoader('png') +- loader.write(NOIMAGE, len(NOIMAGE)) +- loader.close() +- pixbuf = loader.get_pixbuf() +- ++ pixbuf = raw_data2pixbuf(value) + img_height = pixbuf.get_height() + if img_height > self.height: + height = self.height + +Index: tryton/tryton/gui/window/view_form/view/list_gtk/parser.py +=================================================================== + +--- a/tryton/tryton/gui/window/view_form/view/list_gtk/parser.py ++++ b/tryton/tryton/gui/window/view_form/view/list_gtk/parser.py +@@ -30,8 +30,9 @@ + from tryton.common.cellrendererbinary import CellRendererBinary + from tryton.common.cellrendererclickablepixbuf import \ + CellRendererClickablePixbuf ++from tryton.common.cellrendererimage import CellRendererImage + from tryton.translate import date_format +-from tryton.common import RPCExecute, RPCException ++from tryton.common import RPCExecute, RPCException, raw_data2pixbuf + from tryton.common.completion import get_completion, update_completion + from tryton.common.selection import SelectionMixin, PopdownMixin + +@@ -142,8 +143,8 @@ + fields[fname].attrs.get('readonly', False))) + if isinstance(renderer, CellRendererToggle): + renderer.set_property('activatable', not readonly) +- elif isinstance(renderer, +- (gtk.CellRendererProgress, CellRendererButton)): ++ elif isinstance(renderer, (gtk.CellRendererProgress, ++ CellRendererButton, CellRendererImage)): + pass + else: + renderer.set_property('editable', not readonly) +@@ -1042,6 +1043,30 @@ + callback() + + ++class Image(Char): ++ ++ def __init__(self, field_name, model_name, treeview, attrs=None, ++ renderer=None): ++ if renderer is None: ++ renderer = CellRendererImage ++ super(Image, self).__init__(field_name, model_name, treeview, attrs, ++ renderer) ++ self.renderer.set_fixed_size(*[int(attrs.get(a, -1)) ++ for a in ('width', 'height')]) ++ ++ @realized ++ def setter(self, column, cell, store, iter_): ++ record = store.get_value(iter_, 0) ++ field = record[self.field_name] ++ value = field.get_client(record) ++ if isinstance(value, (int, long)): ++ if value > 10 ** 6: ++ value = None ++ else: ++ value = field.get_data(record) ++ cell.pixbuf = raw_data2pixbuf(value) ++ ++ + class Button(object): + + def __init__(self, treeview, screen, attrs=None): +@@ -1106,4 +1131,5 @@ + 'reference': Reference, + 'one2one': O2O, + 'binary': Binary, ++ 'image': Image, + } + diff --git a/series b/series index e991d0d..ebe0711 100644 --- a/series +++ b/series @@ -34,3 +34,5 @@ issue11331003_1_10001.diff issue6521002_1.diff issue8391002_40001.diff issue8381002_20002.diff +issue3991003_40001.diff +issue4011003_200001.diff