jonathan: thuban/Thuban/UI layerproperties.py, NONE, 1.1 rasterlayerproperties.py, NONE, 1.1 baserenderer.py, 1.14, 1.15 classifier.py, 1.69, 1.70 mainwindow.py, 1.141, 1.142 renderer.py, 1.54, 1.55

cvs@intevation.de cvs at intevation.de
Thu Jan 27 15:19:43 CET 2005


Author: jonathan

Update of /thubanrepository/thuban/Thuban/UI
In directory doto:/tmp/cvs-serv16876/Thuban/UI

Modified Files:
	baserenderer.py classifier.py mainwindow.py renderer.py 
Added Files:
	layerproperties.py rasterlayerproperties.py 
Log Message:
Add a new dialog box for raster layers. The dialog box allows
the user to toggle a mask that is generated by ProjectRasterFile
and is used to only draw the real parts of the projected image.


--- NEW FILE: layerproperties.py ---
# Copyright (c) 2005 by Intevation GmbH
# Authors:
# Jonathan Coles <jonathan at intevation.de> 
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with Thuban for details.

"""Base class for Layer Properties dialogs"""

__version__ = "$Revision: 1.1 $"
# $Source: /thubanrepository/thuban/Thuban/UI/layerproperties.py,v $
# $Id: layerproperties.py,v 1.1 2005/01/27 14:19:41 jonathan Exp $

from Thuban import _

from wxPython.wx import *
from Thuban.Model.messages import MAP_LAYERS_REMOVED, LAYER_SHAPESTORE_REPLACED
from dialogs import NonModalNonParentDialog
from messages import MAP_REPLACED

ID_PROPERTY_REVERT = 4002
ID_PROPERTY_TRY = 4008
ID_PROPERTY_TITLE = 4012

class LayerProperties(NonModalNonParentDialog):

    def __init__(self, parent, name, layer):

        NonModalNonParentDialog.__init__(self, parent, name, "")

        self.SetTitle(layer.Title())

        self.parent.Subscribe(MAP_REPLACED, self.map_replaced)
        self.layer = layer
        self.map = parent.Map()

        self.map.Subscribe(MAP_LAYERS_REMOVED, self.map_layers_removed)

        self.layout_recurse = False

    def dialog_layout(self, *args, **kw):

        if self.layout_recurse: return
        self.layout_recurse = True

        panel = wxPanel(self, -1)

        topBox = wxBoxSizer(wxVERTICAL)
        panelBox = wxBoxSizer(wxVERTICAL)

        # Title

        sizer = wxBoxSizer(wxHORIZONTAL)
        sizer.Add(wxStaticText(panel, -1, _("Title: ")),
            0, wxALIGN_LEFT | wxRIGHT | wxALIGN_CENTER_VERTICAL, 4)

        text_title = wxTextCtrl(panel, ID_PROPERTY_TITLE, self.layer.Title())
        text_title.SetInsertionPointEnd()
        sizer.Add(text_title, 1, wxGROW | wxRIGHT, 00)

        panelBox.Add(sizer, 0, wxGROW | wxALL, 4)

        # Type
        panelBox.Add(wxStaticText(panel, -1, 
            _("Layer Type: %s") % self.layer.Type()),
            0, wxALIGN_LEFT | wxALL, 4) 

        # Projection
        proj = self.layer.GetProjection()
        if proj is None:
            text = _("Projection: None")
        else:
            text = _("Projection: %s") % proj.Label()
            
        panelBox.Add(wxStaticText(panel, -1, text), 0, wxALIGN_LEFT | wxALL, 4) 

        self.dialog_layout(panel, panelBox)

        button_try = wxButton(self, ID_PROPERTY_TRY, _("Try"))
        button_revert = wxButton(self, ID_PROPERTY_REVERT, _("Revert"))
        button_ok = wxButton(self, wxID_OK, _("OK"))
        button_close = wxButton(self, wxID_CANCEL, _("Close"))
        button_ok.SetDefault()

        buttonBox = wxBoxSizer(wxHORIZONTAL)
        buttonBox.Add(button_try, 0, wxRIGHT|wxEXPAND, 10)
        buttonBox.Add(button_revert, 0, wxRIGHT|wxEXPAND, 10)
        buttonBox.Add(button_ok, 0, wxRIGHT|wxEXPAND, 10)
        buttonBox.Add(button_close, 0, wxRIGHT|wxEXPAND, 0)

        panel.SetAutoLayout(True)
        panel.SetSizer(panelBox)
        panelBox.Fit(panel) 
        panelBox.SetSizeHints(panel) 

        topBox.Add(panel, 1, wxGROW | wxALL, 4)
        topBox.Add(buttonBox, 0, wxALIGN_RIGHT|wxALL, 10)

        self.SetAutoLayout(True)
        self.SetSizer(topBox)
        topBox.Fit(self)
        topBox.SetSizeHints(self)
        self.Layout()

        ###########

        EVT_TEXT(self, ID_PROPERTY_TITLE, self.OnTitleChanged)
        EVT_BUTTON(self, wxID_OK, self.OnOK)
        EVT_BUTTON(self, ID_PROPERTY_TRY, self.OnTry)
        EVT_BUTTON(self, wxID_CANCEL, self.OnCloseBtn)
        EVT_BUTTON(self, ID_PROPERTY_REVERT, self.OnRevert)

        ######################

        text_title.SetFocus()
        self.haveApplied = False


    def unsubscribe_messages(self):
        """Unsubscribe from all messages."""
        self.parent.Unsubscribe(MAP_REPLACED, self.map_replaced)
        self.map.Unsubscribe(MAP_LAYERS_REMOVED, self.map_layers_removed)

    def map_layers_removed(self):
        """Subscribed to MAP_LAYERS_REMOVED. If this layer was removed,
        Close self.
        """
        if self.layer not in self.map.Layers():
            self.Close()

    def map_replaced(self, *args):
        """Subscribed to the mainwindow's MAP_REPLACED message. Close self."""
        self.Close()

    def OnTry(self, event):
        return

    def OnOK(self, event):
        self.Close()

    def OnClose(self, event):
        self.unsubscribe_messages()
        NonModalNonParentDialog.OnClose(self, event)

    def OnCloseBtn(self, event):
        """Close is similar to Cancel except that any changes that were
        made and applied remain applied.
        """

        self.Close()

    def OnRevert(self, event):
        return

    def SetTitle(self, title):
        """Set the title of the dialog."""
        if title != "":
            title = ": " + title

        NonModalNonParentDialog.SetTitle(self, _("Layer Properties") + title)

    def OnTitleChanged(self, event):
        """Update the dialog title when the user changed the layer name."""
        obj = event.GetEventObject()

        self.layer.SetTitle(obj.GetValue())
        self.SetTitle(self.layer.Title())


--- NEW FILE: rasterlayerproperties.py ---
# Copyright (c) 2005 by Intevation GmbH
# Authors:
# Jonathan Coles <jonathan at intevation.de> 
#
# This program is free software under the GPL (>=v2)
# Read the file COPYING coming with Thuban for details.

"""Raster Layer Properties dialog"""

__version__ = "$Revision: 1.1 $"
# $Source: /thubanrepository/thuban/Thuban/UI/rasterlayerproperties.py,v $
# $Id: rasterlayerproperties.py,v 1.1 2005/01/27 14:19:41 jonathan Exp $

from wxPython.wx import *

from Thuban import _
from Thuban.UI.layerproperties import LayerProperties
from Thuban.Model.resource import has_gdal_support, gdal_support_status

class RasterLayerProperties(LayerProperties):

    def __init__(self, parent, name, layer, *args, **kw):
        LayerProperties.__init__(self, parent, name, layer)

        self.old_state = {}
        self.old_state["use_mask"] = layer.UseMask()

        LayerProperties.dialog_layout(self)

    def dialog_layout(self, panel, panelBox):

        info = self.layer.ImageInfo()

        if info is None:
            panelBox.Add(
                wxStaticText(panel, -1, 
                _("GDAL image information unavailable. See About box for details.")),
                0, wxALIGN_LEFT | wxALL, 4)
            return

        
        # Bounding Box
        bbox = self.layer.LatLongBoundingBox()
        if bbox is None:
            text = _("Extent (lat-lon): None")
        else:
            text = _("Extent (lat-lon): (%g, %g, %g, %g)") % tuple(bbox)

        panelBox.Add(wxStaticText(panel, -1, text), 0, wxALIGN_LEFT|wxALL, 4)

        rasterBox = wxStaticBoxSizer(wxStaticBox(panel, -1, 
                    _("Image Properties")), wxVERTICAL)


        rasterBox.Add(
            wxStaticText(panel, -1, 
            _("Source: %s") % self.layer.GetImageFilename()),
            0, wxALIGN_LEFT | wxALL, 4)

        infoBox = wxBoxSizer(wxHORIZONTAL)

        nBands = info["nBands"]

        self.usePalIndex = nBands == 1
        
        infoBox.Add(
            wxStaticText(panel, -1, _("Driver: %s") % info["Driver"]),
            0, wxALIGN_LEFT | wxRIGHT, 10)
        infoBox.Add(
            wxStaticText(panel, -1, _("Size: %ix%i") % info["Size"]),
            0, wxALIGN_LEFT | wxRIGHT, 10)
        infoBox.Add(
            wxStaticText(panel, -1, _("Number of Bands: %i") % nBands),
            0, wxALIGN_LEFT | wxRIGHT, 0)

        rasterBox.Add(infoBox, 0, wxALIGN_LEFT|wxALL, 4)

        # Mask 

        maskBox = wxBoxSizer(wxHORIZONTAL)

        self.maskCB = wxCheckBox(panel, -1, _("Use Mask"))
        maskBox.Add(self.maskCB, 0, wxRIGHT, 10)

        rasterBox.Add(maskBox, 0, wxALL, 4)
        panelBox.Add(rasterBox, 1, wxGROW | wxALL, 4)

        self.maskCB.SetValue(self.old_state["use_mask"])

    def OnTry(self, event):
        self.set_state()

    def OnOK(self, event):
        if self.set_state(): 
            self.Close()

    def OnRevert(self, event):
        self.maskCB.SetValue(self.old_state["use_mask"])
        self.set_state()

    def set_state(self):
        self.layer.SetUseMask(self.maskCB.GetValue() == 1)
        return True

Index: baserenderer.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/baserenderer.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -d -r1.14 -r1.15
--- baserenderer.py	21 Jan 2005 14:01:25 -0000	1.14
+++ baserenderer.py	27 Jan 2005 14:19:41 -0000	1.15
@@ -458,6 +458,7 @@
         # True  -- warp the image to the size of the whole screen
         # False -- only use the bound box of the layer (currently inaccurate)
         if True: 
+        #if False: 
             pmin = [0,height]
             pmax = [width, 0]
         else:
@@ -465,8 +466,14 @@
             bb = [[[bb[0], bb[1]], [bb[2], bb[3]],],]
             pmin, pmax = self.projected_points(layer, bb)[0]
 
-        fmin = [max(0, pmin[0]) - offx, offy - min(height, pmin[1])]
-        fmax = [min(width, pmax[0]) - offx, offy - max(0, pmax[1])]
+        #print bb
+        #print pmin, pmax
+
+        fmin = [max(0, min(pmin[0], pmax[0])) - offx, 
+                offy - min(height, max(pmin[1], pmax[1]))]
+
+        fmax = [min(width, max(pmin[0], pmax[0])) - offx, 
+                offy - max(0, min(pmin[1], pmax[1]))]
 
         xmin = fmin[0]/self.scale
         ymin = fmin[1]/self.scale
@@ -477,29 +484,31 @@
         height = int(min(height, round(fmax[1] - fmin[1] + 1)))
 
         try:
-            data = [width, height,
-                    ProjectRasterFile(layer.GetImageFilename(),
-                                     in_proj, out_proj,
-                                     (xmin, ymin, xmax, ymax), "",
-                                     (width, height))
-                   ]
+            project_params = (layer.GetImageFilename(), in_proj, out_proj, 
+                              (xmin, ymin, xmax, ymax), "", (width, height),
+                              layer.UseMask())
+
+            data = (width, height, apply(ProjectRasterFile, project_params))
+
         except (IOError, AttributeError, ValueError):
             # Why does this catch AttributeError and ValueError?
             # FIXME: The exception should be communicated to the user
             # better.
             traceback.print_exc()
         else:
-            mask = "#030104"
-            #mask = None
-            self.draw_raster_data(fmin[0]+offx, offy-fmax[1], data, "RAW", mask)
+            self.draw_raster_data(fmin[0]+offx, offy-fmax[1], data, "RAW")
             data = None
 
-    def draw_raster_data(self, x, y, data, format="BMP", mask = None):
+    def draw_raster_data(self, x, y, data, format="BMP"):
         """Draw the raster image in data onto the DC with the top
         left corner at (x,y)
 
-        The raster image data is a list holding the image width, height,
-        and data in the format indicated by the format parameter. 
+        The raster image data is a tuple of the form
+            (width, height, (image_data, mask_data))
+        
+        holding the image width, height, image data, and mask data.
+        mask_data may be None if a mask should not be used. Both kinds 
+        of data are assumed to be in the format specified in format.
 
         The format parameter is a string with the name of the format.
         The following format names should be used:
@@ -509,13 +518,6 @@
           'JPEG' -- JPEG Image
 
         The default format is 'BMP'.
-
-        The mask parameter determines how a mask (if any) is applied
-        to the image. mask can have the following values:
-        
-          o  None -- no mask is used
-          o  Any object accepted by wxBitmap.SetMaskColour()
-          o  A one-bit image the same size as the image data
 
         This method has to be implemented by derived classes. The
         implementation in the derived class should try to support at

Index: classifier.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/classifier.py,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -d -r1.69 -r1.70
--- classifier.py	7 Oct 2004 14:43:45 -0000	1.69
+++ classifier.py	27 Jan 2005 14:19:41 -0000	1.70
@@ -35,13 +35,13 @@
 
 from Thuban.Model.color import Transparent
 
-from Thuban.Model.layer import Layer, RasterLayer
+from Thuban.Model.layer import Layer
 from Thuban.Model.data import SHAPETYPE_ARC, SHAPETYPE_POLYGON, SHAPETYPE_POINT
 
 from Thuban.UI.classgen import ClassGenDialog
 from Thuban.UI.colordialog import ColorDialog
 
-from dialogs import NonModalNonParentDialog
+from Thuban.UI.layerproperties import LayerProperties
 from messages import MAP_REPLACED
 
 ID_CLASS_TABLE = 40011
@@ -684,7 +684,7 @@
 EB_SELECT_FIELD = 1
 EB_GEN_CLASS = 2
 
-class Classifier(NonModalNonParentDialog):
+class Classifier(LayerProperties):
 
     type2string = {None:             _("None"),
                    FIELDTYPE_STRING: _("Text"),
@@ -697,36 +697,28 @@
         group in the classification table.
         """
 
-        NonModalNonParentDialog.__init__(self, parent, name, "")
-
-        self.__SetTitle(layer.Title())
-
-        self.parent.Subscribe(MAP_REPLACED, self.map_replaced)
-        self.layer = layer
-        self.map = parent.Map()
+        LayerProperties.__init__(self, parent, name, layer)
 
-        self.map.Subscribe(MAP_LAYERS_REMOVED, self.map_layers_removed)
         self.layer.Subscribe(LAYER_SHAPESTORE_REPLACED,
                              self.layer_shapestore_replaced)
 
         self.genDlg = None
+        self.group = group
 
-        ############################
-        # Create the controls
-        #
+        LayerProperties.dialog_layout(self)
 
-        panel = wxPanel(self, -1)
+    def dialog_layout(self, panel, panelBox):
 
-        text_title = wxTextCtrl(panel, ID_PROPERTY_TITLE, layer.Title())
-        self.fieldTypeText = wxStaticText(panel, -1, "")
+        if self.layer.HasClassification():
+
+            self.fieldTypeText = wxStaticText(panel, -1, "")
 
-        if layer.HasClassification():
             self.originalClass = self.layer.GetClassification()
             self.originalClassField = self.layer.GetClassificationColumn()
             field = self.originalClassField
             fieldType = self.layer.GetFieldType(field)
 
-            table = layer.ShapeStore().Table()
+            table = self.layer.ShapeStore().Table()
             #
             # make field choice box
             #
@@ -773,37 +765,8 @@
             # calling __SelectField after creating the classGrid fills in the
             # grid with the correct information
             self.fields.SetSelection(self.__cur_field)
-            self.__SelectField(self.__cur_field, group = group)
-
-        button_try = wxButton(self, ID_PROPERTY_TRY, _("Try"))
-        button_revert = wxButton(self, ID_PROPERTY_REVERT, _("Revert"))
-        button_ok = wxButton(self, wxID_OK, _("OK"))
-        button_close = wxButton(self, wxID_CANCEL, _("Close"))
-        button_ok.SetDefault()
-
-        ############################
-        # Layout the controls
-        #
-
-        topBox = wxBoxSizer(wxVERTICAL)
-        panelBox = wxBoxSizer(wxVERTICAL)
-
-        sizer = wxBoxSizer(wxHORIZONTAL)
-        sizer.Add(wxStaticText(panel, -1, _("Title: ")),
-            0, wxALIGN_LEFT | wxALL | wxALIGN_CENTER_VERTICAL, 4)
-        sizer.Add(text_title, 1, wxGROW, 0)
-
-        panelBox.Add(sizer, 0, wxGROW, 4)
-
-        if isinstance(layer, RasterLayer):
-            type = "Image"
-        else:
-            type = layer.ShapeType()
-
-        panelBox.Add(wxStaticText(panel, -1, _("Type: %s") % type),
-            0, wxALIGN_LEFT | wxALL, 4) 
+            self.__SelectField(self.__cur_field, group = self.group)
 
-        if layer.HasClassification():
 
             classBox = wxStaticBoxSizer(
                         wxStaticBox(panel, -1, _("Classification")), wxVERTICAL)
@@ -838,35 +801,7 @@
             panelBox.Add(classBox, 1, wxGROW, 0)
 
 
-        buttonBox = wxBoxSizer(wxHORIZONTAL)
-        buttonBox.Add(button_try, 0, wxRIGHT|wxEXPAND, 10)
-        buttonBox.Add(button_revert, 0, wxRIGHT|wxEXPAND, 10)
-        buttonBox.Add(button_ok, 0, wxRIGHT|wxEXPAND, 10)
-        buttonBox.Add(button_close, 0, wxRIGHT|wxEXPAND, 10)
-
-        panel.SetAutoLayout(True)
-        panel.SetSizer(panelBox)
-        panelBox.Fit(panel) 
-        panelBox.SetSizeHints(panel) 
-
-        topBox.Add(panel, 1, wxGROW | wxALL, 4)
-        topBox.Add(buttonBox, 0, wxALIGN_RIGHT|wxBOTTOM|wxTOP, 10)
-
-        self.SetAutoLayout(True)
-        self.SetSizer(topBox)
-        topBox.Fit(self)
-        topBox.SetSizeHints(self)
-        self.Layout()
-
-        ###########
-
         EVT_CHOICE(self, ID_PROPERTY_SELECT, self._OnFieldSelect)
-        EVT_TEXT(self, ID_PROPERTY_TITLE, self._OnTitleChanged)
-        EVT_BUTTON(self, wxID_OK, self._OnOK)
-        EVT_BUTTON(self, ID_PROPERTY_TRY, self._OnTry)
-        EVT_BUTTON(self, wxID_CANCEL, self._OnCloseBtn)
-        EVT_BUTTON(self, ID_PROPERTY_REVERT, self._OnRevert)
-
         EVT_BUTTON(self, ID_PROPERTY_ADD, self._OnAdd)
         EVT_BUTTON(self, ID_PROPERTY_EDITSYM, self._OnEditSymbol)
         EVT_BUTTON(self, ID_PROPERTY_REMOVE, self._OnRemove)
@@ -874,36 +809,18 @@
         EVT_BUTTON(self, ID_PROPERTY_MOVEUP, self._OnMoveUp)
         EVT_BUTTON(self, ID_PROPERTY_MOVEDOWN, self._OnMoveDown)
 
-        ######################
-
-        text_title.SetFocus()
-        self.haveApplied = False
-
     def unsubscribe_messages(self):
         """Unsubscribe from all messages."""
-        self.parent.Unsubscribe(MAP_REPLACED, self.map_replaced)
-        self.map.Unsubscribe(MAP_LAYERS_REMOVED, self.map_layers_removed)
+        LayerProperties.unsubscribe_messages(self)
         self.layer.Unsubscribe(LAYER_SHAPESTORE_REPLACED,
                                self.layer_shapestore_replaced)
 
-    def map_layers_removed(self, map):
-        """Subscribed to MAP_LAYERS_REMOVED. If this layer was removed,
-        Close self.
-        """
-        if self.layer not in self.map.Layers():
-            self.Close()
-
     def layer_shapestore_replaced(self, *args):
         """Subscribed to the map's LAYER_SHAPESTORE_REPLACED message.
-
         Close self.
         """
         self.Close()
 
-    def map_replaced(self, *args):
-        """Subscribed to the mainwindow's MAP_REPLACED message. Close self."""
-        self.Close()
-
     def EditSymbol(self, row):
         """Open up a dialog where the user can select the properties 
         for a group.
@@ -1025,7 +942,7 @@
         self.__SelectField(index, self.__cur_field)
         self.__cur_field = index
 
-    def _OnTry(self, event):
+    def OnTry(self, event):
         """Put the data from the table into a new Classification and hand
            it to the layer.
         """
@@ -1045,25 +962,13 @@
 
         self.haveApplied = True
 
-    def _OnOK(self, event):
-        self._OnTry(event)
-        self.Close()
-
-    def OnClose(self, event):
-        self.unsubscribe_messages()
-        NonModalNonParentDialog.OnClose(self, event)
-
-    def _OnCloseBtn(self, event):
-        """Close is similar to Cancel except that any changes that were
-        made and applied remain applied, but the currently displayed
-        classification is discarded.
-        """
-
+    def OnOK(self, event):
+        self.OnTry(event)
         self.Close()
 
-    def _OnRevert(self, event):
+    def OnRevert(self, event):
         """The layer's current classification stays the same."""
-        if self.haveApplied:
+        if self.haveApplied and self.layer.HasClassification():
             self.layer.SetClassificationColumn(self.originalClassField)
             self.layer.SetClassification(self.originalClass)
 
@@ -1575,6 +1480,3 @@
     def _OnLeftDClick(self, event):
         self.DoEdit()
 
-from Thuban.UI.mainwindow import layer_properties_dialogs
-layer_properties_dialogs.add(Layer, Classifier)
-layer_properties_dialogs.add(RasterLayer, Classifier)

Index: mainwindow.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/mainwindow.py,v
retrieving revision 1.141
retrieving revision 1.142
diff -u -d -r1.141 -r1.142
--- mainwindow.py	24 Jan 2005 11:19:53 -0000	1.141
+++ mainwindow.py	27 Jan 2005 14:19:41 -0000	1.142
@@ -54,9 +54,15 @@
 
 import projdialog
 
+from Thuban.UI.classifier import Classifier
+from Thuban.UI.rasterlayerproperties import RasterLayerProperties
+from Thuban.Model.layer import RasterLayer
+
 from Thuban.Lib.classmapper import ClassMapper
 
 layer_properties_dialogs = ClassMapper()
+layer_properties_dialogs.add(RasterLayer, RasterLayerProperties)
+layer_properties_dialogs.add(Layer, Classifier)
 
 class MainWindow(DockFrame):
 

Index: renderer.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/renderer.py,v
retrieving revision 1.54
retrieving revision 1.55
diff -u -d -r1.54 -r1.55
--- renderer.py	21 Jan 2005 14:01:25 -0000	1.54
+++ renderer.py	27 Jan 2005 14:19:41 -0000	1.55
@@ -23,7 +23,7 @@
     wxBLACK_PEN, wxBLACK, wxSOLID, wxCROSS_HATCH, wxSWISS, wxNORMAL, \
     wxBitmapFromImage, wxImageFromStream, wxBITMAP_TYPE_BMP, \
     wxBITMAP_TYPE_JPEG, wxBITMAP_TYPE_PNG, wxBITMAP_TYPE_TIF, \
-    wxBITMAP_TYPE_GIF, wxEmptyImage
+    wxBITMAP_TYPE_GIF, wxEmptyImage, wxMask
 
 from wxproj import draw_polygon_shape, draw_polygon_init
 
@@ -104,13 +104,21 @@
         return wxFont(int(round(self.resolution * 10)), wxSWISS, wxNORMAL,
                       wxNORMAL)
 
-    def draw_raster_data(self, x,y, data, format = 'BMP', mask = None):
+    def draw_raster_data(self, x,y, data, format = 'BMP'):
+
+        mask = None
         if format == 'RAW':
             image = wxEmptyImage(data[0], data[1])
-            image.SetData(data[2])
+            image.SetData(data[2][0])
+            if data[2][1] is not None:
+                mask = wxEmptyImage(data[0], data[1])
+                mask.SetData(data[2][1])
         else:
-            stream = cStringIO.StringIO(data[2])
+            stream = cStringIO.StringIO(data[2][0])
             image = wxImageFromStream(stream, raster_format_map[format])
+            if data[2][1] is not None:
+                stream = cStringIO.StringIO(data[2][1])
+                mask = wxImageFromStream(stream, raster_format_map[format])
 
         bitmap = wxBitmapFromImage(image)
 
@@ -120,7 +128,7 @@
             # if we are given a mask object, try to pass it to SetMaskColour,
             # otherwise assume it's a mask image
             try:
-                bitmap.SetMaskColour(mask);
+                bitmap.SetMask(wxMask(wxBitmapFromImage(mask, 1)))
                 self.dc.DrawBitmap(bitmap, int(round(x)), int(round(y)), True)
             except (TypeError):
                 # implement using a mask image





More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)