dabo Commit
Revision 2236
Date: 2006-06-23 10:23:25 -0700 (Fri, 23 Jun 2006)
Author: ed

Changed:
U   trunk/dabo/db/dCursorMixin.py
U   trunk/dabo/ui/uiwx/dImage.py

Log:
Added preliminary support for BLOBs. This has been tested with MySQL; other 
backend dbapi adapters will also have to be checked for the manner in which 
they return BLOB data.

Updated dImage to handle the sort of direct byte stream that is returned from 
an image stored as a BLOB in a database. You can now set the DataSource and 
DataField of a dImage control to the table and column containing the blob, and 
it will properly display it.


Diff:
Modified: trunk/dabo/db/dCursorMixin.py
===================================================================
--- trunk/dabo/db/dCursorMixin.py       2006-06-23 16:37:51 UTC (rev 2235)
+++ trunk/dabo/db/dCursorMixin.py       2006-06-23 17:23:25 UTC (rev 2236)
@@ -4,6 +4,7 @@
 import random
 import sys
 import re
+import array
 # Make sure that the user's installation supports Decimal.
 _USE_DECIMAL = True
 try:
@@ -267,6 +268,9 @@
                                                                                
        break
                                                                else:
                                                                        raise 
UnicodeDecodeError, e
+                                               elif isinstance(val, 
array.array):
+                                                       # Usually blob data
+                                                       row[fld] = 
val.tostring()
 
                        # Convert to DataSet 
                        self._records = DataSet(self._records)
@@ -2386,9 +2390,6 @@
 #              print "FETCH", ft-et
                return DataSet(tmpres)
                
-#              
-#              dabo.trace()
-#              
 #              res = []
 #              if tmpres:
 #                      # There will be no description if there are no records.

Modified: trunk/dabo/ui/uiwx/dImage.py
===================================================================
--- trunk/dabo/ui/uiwx/dImage.py        2006-06-23 16:37:51 UTC (rev 2235)
+++ trunk/dabo/ui/uiwx/dImage.py        2006-06-23 17:23:25 UTC (rev 2236)
@@ -4,11 +4,12 @@
        dabo.ui.loadUI("wx")
 import dabo.dEvents as dEvents
 from dabo.dLocalize import _
-import dControlMixin as dcm
+#import dControlMixin as dcm
+import dDataControlMixin as dcm
 from dabo.ui import makeDynamicProperty
 
 
-class dImage(wx.StaticBitmap, dcm.dControlMixin):
+class dImage(wx.StaticBitmap, dcm.dDataControlMixin):
        """ Create a simple bitmap to display images."""
        def __init__(self, parent, properties=None, attProperties=None, 
                        *args, **kwargs):
@@ -26,7 +27,7 @@
                bmp = wx.EmptyBitmap(1, 1)
                picName = self._extractKey((kwargs, properties, attProperties), 
"Picture", "")
        
-               dcm.dControlMixin.__init__(self, preClass, parent, properties, 
+               dcm.dDataControlMixin.__init__(self, preClass, parent, 
properties, 
                                bitmap=bmp, *args, **kwargs)
                
                # Display the picture, if any. This will also initialize the 
@@ -184,6 +185,29 @@
                        dabo.errorLog.write(_("ScaleMode must be either 'Clip', 
'Proportional' or 'Stretch'.") )
 
 
+       def _getValue(self):
+               return self.__image
+
+       def _setValue(self, val):
+               if self._constructed():
+                       try:
+                               isFile = os.path.exists(val)
+                       except TypeError:
+                               isFile = False
+                       if not isFile:
+                               # Probably an image stream
+                               try:
+                                       img = dabo.ui.imageFromData(val)
+                               except:
+                                       # No dice, so just bail
+                                       img = ""
+                               self._setPic(img)
+                       else:
+                               self._setPic(val)
+               else:
+                       self._properties["Value"] = val
+
+
        def _getImg(self):
                if self.__image is None:
                        self.__image = wx.NullImage
@@ -192,7 +216,6 @@
        
        Bitmap = property(_getBmp, _setBmp, None,
                        _("The bitmap representation of the displayed image.  
(wx.Bitmap)") )
-       DynamicBitmap = makeDynamicProperty(Bitmap)
 
        BitmapHeight = property(_getBitmapHeight, None, None,
                        _("Height of the actual displayed bitmap  (int)"))
@@ -202,7 +225,6 @@
        
        Picture = property(_getPic, _setPic, None,
                        _("The file used as the source for the displayed image. 
 (str)") )
-       DynamicPicture = makeDynamicProperty(Picture)
                        
        ScaleMode = property(_getScaleMode, _setScaleMode, None,
                        _("""Determines how the image responds to sizing. Can 
be one
@@ -212,11 +234,18 @@
                                        its original proportions. (default)
                                Stretch: the image resizes to the Height/Width 
of the control.
                        """) )
-       DynamicScaleMode = makeDynamicProperty(ScaleMode)
+       
+       Value = property(_getValue, _setValue, None,
+                       _("Image content for this control  (binary img data)")) 
 
        _Image = property(_getImg, None, None, 
                        _("Underlying image handler object  (wx.Image)") )
 
+
+       DynamicBitmap = makeDynamicProperty(Bitmap)
+       DynamicPicture = makeDynamicProperty(Picture)
+       DynamicScaleMode = makeDynamicProperty(ScaleMode)
+
        
 if __name__ == "__main__":
        class ImgForm(dabo.ui.dForm):




_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-dev

Reply via email to