Add patches for issue3729

This commit is contained in:
Sergi Almacellas Abellana 2014-09-18 12:54:36 +02:00
parent 16abada580
commit 155db5b5f2
3 changed files with 238 additions and 0 deletions

48
issue3991003_40001.diff Normal file
View File

@ -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 @@
<value>reference</value>
<value>one2one</value>
<value>binary</value>
+ <value>image</value>
</choice>
</attribute>
</optional>
@@ -142,6 +143,11 @@
</define>
<define name="attlist.field" combine="interleave">
<optional>
+ <attribute name="height"/>
+ </optional>
+ </define>
+ <define name="attlist.field" combine="interleave">
+ <optional>
<attribute name="orientation" a:defaultValue="left_to_right">
<choice>
<value>left_to_right</value>

188
issue4011003_200001.diff Normal file
View File

@ -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,
}

2
series
View File

@ -34,3 +34,5 @@ issue11331003_1_10001.diff
issue6521002_1.diff
issue8391002_40001.diff
issue8381002_20002.diff
issue3991003_40001.diff
issue4011003_200001.diff