[GRASS-SVN] r67011 - in grass/trunk: gui/wxpython/core gui/wxpython/psmap lib/python/imaging scripts/wxpyimgview
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Dec 2 19:13:56 PST 2015
Author: annakrat
Date: 2015-12-02 19:13:56 -0800 (Wed, 02 Dec 2015)
New Revision: 67011
Modified:
grass/trunk/gui/wxpython/core/utils.py
grass/trunk/gui/wxpython/psmap/dialogs.py
grass/trunk/gui/wxpython/psmap/frame.py
grass/trunk/gui/wxpython/psmap/utils.py
grass/trunk/lib/python/imaging/images2gif.py
grass/trunk/lib/python/imaging/images2swf.py
grass/trunk/scripts/wxpyimgview/wxpyimgview_gui.py
Log:
replace PIL obsolete function tostring to tobytes
Modified: grass/trunk/gui/wxpython/core/utils.py
===================================================================
--- grass/trunk/gui/wxpython/core/utils.py 2015-12-02 21:30:59 UTC (rev 67010)
+++ grass/trunk/gui/wxpython/core/utils.py 2015-12-03 03:13:56 UTC (rev 67011)
@@ -1021,19 +1021,22 @@
"""
import wx
hasAlpha = pilImage.mode[-1] == 'A'
- if copyAlpha and hasAlpha : # Make sure there is an alpha layer copy.
+ if copyAlpha and hasAlpha: # Make sure there is an alpha layer copy.
wxImage = wx.EmptyImage(*pilImage.size)
pilImageCopyRGBA = pilImage.copy()
pilImageCopyRGB = pilImageCopyRGBA.convert('RGB') # RGBA --> RGB
- pilImageRgbData = pilImageCopyRGB.tostring()
+ fn = getattr(pilImageCopyRGB, "tobytes", getattr(pilImageCopyRGB, "tostring"))
+ pilImageRgbData = fn()
wxImage.SetData(pilImageRgbData)
- wxImage.SetAlphaData(pilImageCopyRGBA.tostring()[3::4]) # Create layer and insert alpha values.
+ fn = getattr(pilImageCopyRGBA, "tobytes", getattr(pilImageCopyRGBA, "tostring"))
+ wxImage.SetAlphaData(fn()[3::4]) # Create layer and insert alpha values.
- else : # The resulting image will not have alpha.
+ else: # The resulting image will not have alpha.
wxImage = wx.EmptyImage(*pilImage.size)
pilImageCopy = pilImage.copy()
pilImageCopyRGB = pilImageCopy.convert('RGB') # Discard any alpha from the PIL image.
- pilImageRgbData = pilImageCopyRGB.tostring()
+ fn = getattr(pilImageCopyRGB, "tobytes", getattr(pilImageCopyRGB, "tostring"))
+ pilImageRgbData = fn()
wxImage.SetData(pilImageRgbData)
return wxImage
Modified: grass/trunk/gui/wxpython/psmap/dialogs.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/dialogs.py 2015-12-02 21:30:59 UTC (rev 67010)
+++ grass/trunk/gui/wxpython/psmap/dialogs.py 2015-12-03 03:13:56 UTC (rev 67011)
@@ -52,7 +52,7 @@
import grass.script as grass
from core import globalvar
-from core.utils import _
+from core.utils import _, PilImageToWxImage
from dbmgr.vinfo import VectorDBInfo
from gui_core.gselect import Select
from core.gcmd import RunCommand, GError, GMessage
Modified: grass/trunk/gui/wxpython/psmap/frame.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/frame.py 2015-12-02 21:30:59 UTC (rev 67010)
+++ grass/trunk/gui/wxpython/psmap/frame.py 2015-12-03 03:13:56 UTC (rev 67011)
@@ -35,7 +35,7 @@
from psmap.toolbars import PsMapToolbar
from core.gcmd import RunCommand, GError, GMessage
from core.settings import UserSettings
-from core.utils import _
+from core.utils import _, PilImageToWxImage
from gui_core.forms import GUI
from gui_core.dialogs import HyperlinkDialog
from gui_core.ghelp import ShowAboutDialog
Modified: grass/trunk/gui/wxpython/psmap/utils.py
===================================================================
--- grass/trunk/gui/wxpython/psmap/utils.py 2015-12-02 21:30:59 UTC (rev 67010)
+++ grass/trunk/gui/wxpython/psmap/utils.py 2015-12-03 03:13:56 UTC (rev 67011)
@@ -362,30 +362,8 @@
return rasterType
else:
return None
-
-def PilImageToWxImage(pilImage, copyAlpha = True):
- """Convert PIL image to wx.Image
-
- Based on http://wiki.wxpython.org/WorkingWithImages
- """
- hasAlpha = pilImage.mode[-1] == 'A'
- if copyAlpha and hasAlpha : # Make sure there is an alpha layer copy.
- wxImage = wx.EmptyImage( *pilImage.size )
- pilImageCopyRGBA = pilImage.copy()
- pilImageCopyRGB = pilImageCopyRGBA.convert('RGB') # RGBA --> RGB
- pilImageRgbData = pilImageCopyRGB.tostring()
- wxImage.SetData(pilImageRgbData)
- wxImage.SetAlphaData(pilImageCopyRGBA.tostring()[3::4]) # Create layer and insert alpha values.
- else : # The resulting image will not have alpha.
- wxImage = wx.EmptyImage(*pilImage.size)
- pilImageCopy = pilImage.copy()
- pilImageCopyRGB = pilImageCopy.convert('RGB') # Discard any alpha from the PIL image.
- pilImageRgbData = pilImageCopyRGB.tostring()
- wxImage.SetData(pilImageRgbData)
- return wxImage
-
def BBoxAfterRotation(w, h, angle):
"""Compute bounding box or rotated rectangle
Modified: grass/trunk/lib/python/imaging/images2gif.py
===================================================================
--- grass/trunk/lib/python/imaging/images2gif.py 2015-12-02 21:30:59 UTC (rev 67010)
+++ grass/trunk/lib/python/imaging/images2gif.py 2015-12-03 03:13:56 UTC (rev 67011)
@@ -744,7 +744,7 @@
# Initialize
self.setconstants(samplefac, colors)
- self.pixels = np.fromstring(image.tostring(), np.uint32)
+ self.pixels = np.fromstring(getattr(image, "tobytes", getattr(image, "tostring"))(), np.uint32)
self.setUpArrays()
self.learn()
Modified: grass/trunk/lib/python/imaging/images2swf.py
===================================================================
--- grass/trunk/lib/python/imaging/images2swf.py 2015-12-02 21:30:59 UTC (rev 67010)
+++ grass/trunk/lib/python/imaging/images2swf.py 2015-12-03 03:13:56 UTC (rev 67011)
@@ -167,7 +167,8 @@
return self._len # self.data.shape[0]
def __repr__(self):
- return self.data[:self._len].tostring().decode('ascii')
+ fn = getattr(self.data[:self._len], "tobytes", getattr(self.data[:self._len], "tostring"))
+ return fn().decode('ascii')
def _checkSize(self):
# check length... grow if necessary
Modified: grass/trunk/scripts/wxpyimgview/wxpyimgview_gui.py
===================================================================
--- grass/trunk/scripts/wxpyimgview/wxpyimgview_gui.py 2015-12-02 21:30:59 UTC (rev 67010)
+++ grass/trunk/scripts/wxpyimgview/wxpyimgview_gui.py 2015-12-03 03:13:56 UTC (rev 67011)
@@ -78,7 +78,8 @@
dc = wx.PaintDC(self)
data = app.imgbuf.reshape((app.i_height, app.i_width, 4))
data = data[::,::,2::-1]
- image = wx.ImageFromData(app.i_width, app.i_height, data.tostring())
+ fn = getattr(data, "tobytes", getattr(data, "tostring"))
+ image = wx.ImageFromData(app.i_width, app.i_height, fn())
dc.DrawBitmap(wx.BitmapFromImage(image), x0, y0, False)
def redraw(self, ev):
More information about the grass-commit
mailing list