[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r9504 - in trunk/gnue-forms/src: GFObjects input/displayHandlers
From: |
johannes |
Subject: |
[gnue] r9504 - in trunk/gnue-forms/src: GFObjects input/displayHandlers uidrivers/wx26 uidrivers/wx26/widgets |
Date: |
Mon, 23 Apr 2007 09:05:49 -0500 (CDT) |
Author: johannes
Date: 2007-04-23 09:05:48 -0500 (Mon, 23 Apr 2007)
New Revision: 9504
Modified:
trunk/gnue-forms/src/GFObjects/GFField.py
trunk/gnue-forms/src/input/displayHandlers/Image.py
trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
trunk/gnue-forms/src/uidrivers/wx26/widgets/image.py
Log:
Images are working on wxMSW and OSX again (although not scrollable).
ListBoxes without values does not crash on wxMSW
issue163: testing
Modified: trunk/gnue-forms/src/GFObjects/GFField.py
===================================================================
--- trunk/gnue-forms/src/GFObjects/GFField.py 2007-04-19 10:31:40 UTC (rev
9503)
+++ trunk/gnue-forms/src/GFObjects/GFField.py 2007-04-23 14:05:48 UTC (rev
9504)
@@ -550,11 +550,15 @@
if dpSep.startswith('"') and dpSep.endswith('"') and len(dpSep) > 2:
dpSep = dpSep[1:-1]
- array = resultSet.getArray ([self.fk_key] + self._fk_descr)
+ array = resultSet.getArray([self.fk_key] + self._fk_descr)
+ if not array and self.required:
+ gDebug(1, "WARNING: empty item added the choices of a required " \
+ "field")
+ self.__lookup_list = [u""]
for line in array:
key = line[0]
- descr = dpSep.join (["%s" % i for i in line[1:]])
+ descr = dpSep.join(["%s" % i for i in line[1:]])
self.__lookup_list.append(descr)
self.__lookup_dict[key] = descr
Modified: trunk/gnue-forms/src/input/displayHandlers/Image.py
===================================================================
--- trunk/gnue-forms/src/input/displayHandlers/Image.py 2007-04-19 10:31:40 UTC
(rev 9503)
+++ trunk/gnue-forms/src/input/displayHandlers/Image.py 2007-04-23 14:05:48 UTC
(rev 9504)
@@ -66,7 +66,7 @@
# upon urlopen which doesn't provide seek. We'll use the
# StringIO function to get around that so that urls can
# still be used
- urlFile = openResource(value)
+ urlFile = openResource(value, 'rb')
fileObject = cStringIO.StringIO(urlFile.read())
image = PILImage.open(fileObject)
@@ -74,4 +74,5 @@
image = PILImage.new("RGB", (1, 1, ))
else:
image = PILImage.new("RGB", (1, 1, ))
+
return image
Modified: trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py 2007-04-19 10:31:40 UTC
(rev 9503)
+++ trunk/gnue-forms/src/uidrivers/wx26/UIdriver.py 2007-04-23 14:05:48 UTC
(rev 9504)
@@ -71,6 +71,7 @@
self.name = "wx 2.6"
self.app = wx.GetApp () or wx.App ()
+ wx.InitAllImageHandlers()
wx.lib.colourdb.updateColourDB()
(self.best_sizes, self.cellWidth, self.cellHeight) = self.__getSizes ()
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2007-04-19
10:31:40 UTC (rev 9503)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/entry.py 2007-04-23
14:05:48 UTC (rev 9504)
@@ -437,8 +437,14 @@
# TODO: We must allow setting the value to None, too, to be
# able to move the cursor to the empty position at the start.
# Must be tested under windows and Mac OS X.
- if not widget.SetStringSelection(value, True):
+ #
+ # On wxMSW SetStringSelection() does not work properly with
+ # empty values.
+ index = widget.FindString(value)
+ if index == -1:
widget.SetSelection(wx.NOT_FOUND)
+ else:
+ widget.SetSelection(index)
elif isinstance(widget, wx.CheckBox):
if value is None:
Modified: trunk/gnue-forms/src/uidrivers/wx26/widgets/image.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx26/widgets/image.py 2007-04-19
10:31:40 UTC (rev 9503)
+++ trunk/gnue-forms/src/uidrivers/wx26/widgets/image.py 2007-04-23
14:05:48 UTC (rev 9504)
@@ -24,10 +24,10 @@
import wx
try:
- from PIL import Image as PILImage
+ from PIL import Image as PILImage
except:
- PILImage = None
+ PILImage = None
from gnue.common.definitions import GParser
from gnue.forms.uidrivers.wx26.widgets import _base
@@ -45,9 +45,139 @@
# =============================================================================
-# Wrap an UI layer around a wx image
+# ImageViewer
# =============================================================================
+class ImageViewer(wx.Window):
+ """
+ An implementation of a wx widget used for displaying images
+ """
+
+ # -------------------------------------------------------------------------
+ # Constructor
+ # -------------------------------------------------------------------------
+
+ def __init__(self, parent, size=wx.DefaultSize, fit='auto'):
+
+ wx.Window.__init__(self, parent, -1, wx.DefaultPosition, size)
+ self.win = parent
+ self.image = None
+ self.back_color = 'WHITE'
+ self.border_color = 'BLACK'
+ self.fit = fit
+
+ self.image_sizex = size[0]
+ self.image_sizey = size[1]
+
+ self.Bind(wx.EVT_PAINT, self.OnPaint)
+
+
+ # -------------------------------------------------------------------------
+ # Draw the current image
+ # -------------------------------------------------------------------------
+
+ def OnPaint(self, event):
+ dc = wx.PaintDC(self)
+ self.DrawImage(dc)
+
+
+ # -------------------------------------------------------------------------
+ # Change the current image
+ # -------------------------------------------------------------------------
+
+ def SetValue(self, value):
+
+ image = wx.EmptyImage(value.size[0], value.size[1])
+ image.SetData(value.convert("RGB").tostring())
+ self.image = image
+ self.Refresh()
+
+
+ # -------------------------------------------------------------------------
+ # Draw a border around the widget
+ # -------------------------------------------------------------------------
+
+ def DrawBorder(self, dc):
+
+ brush = wx.Brush(wx.NamedColour(self.back_color), wx.SOLID)
+ dc.SetBrush(brush)
+ dc.SetPen(wx.Pen(wx.NamedColour(self.border_color), 1))
+ dc.DrawRectangle(0, 0, self.image_sizex, self.image_sizey)
+
+
+ # -------------------------------------------------------------------------
+ # Draw the image to the device context
+ # -------------------------------------------------------------------------
+
+ def DrawImage(self, dc):
+ try:
+ image = self.image
+ except:
+ return
+
+ self.DrawBorder(dc)
+
+ if image is None:
+ return
+
+ bmp = image.ConvertToBitmap()
+
+ # Dimensions of the image file
+ iwidth = bmp.GetWidth()
+ iheight = bmp.GetHeight()
+ scrx = self.image_sizex
+ scry = self.image_sizey
+
+ fit = self.fit
+ if fit == "auto":
+ if float(scrx) / iwidth < float(scry) / iwidth:
+ fit = "width"
+ else:
+ fit = "height"
+
+ if fit == 'width':
+ prop = float(self.image_sizex-10) / iwidth
+ iwidth = self.image_sizex - 10
+ diffx = 5
+ iheight = abs(int(iheight * prop))
+ diffy = (self.image_sizey - iheight)/2
+
+ if iheight >= self.image_sizey - 10:
+ diffy = 5
+ iheight = self.image_sizey - 10
+
+ elif fit == 'height':
+ prop = float(self.image_sizey-10) / iheight
+ iheight = self.image_sizey - 10
+ diffy = 5
+
+ iwidth = abs(int(iwidth * prop))
+ diffx = (self.image_sizex - iwidth) / 2
+ if iwidth > self.image_sizex - 10:
+ diffx = 5
+ iwidth = self.image_sizex - 10
+
+ elif fit == 'both':
+ diffx = (self.image_sizex - iwidth)/2 # center calc
+ if iwidth >= self.image_sizex -10: # if image width fits in
+ # window adjust
+ diffx = 5
+ iwidth = self.image_sizex - 10
+
+ diffy = (self.image_sizey - iheight)/2 # center calc
+ if iheight >= self.image_sizey - 10: # if image height fits in
+ # window adjust
+ diffy = 5
+ iheight = self.image_sizey - 10
+
+ image.Rescale(iwidth, iheight) # rescale to fit the window
+ bmp = image.ConvertToBitmap()
+ dc.DrawBitmap(bmp, diffx, diffy) # draw the image to window
+
+
+#
============================================================================= #
Wrap an UI layer around a wx image
+# =============================================================================
+
class UIImage (_base.UIHelper):
"""
Creates a single instance of an image.
@@ -65,22 +195,12 @@
parent = event.container
self.image_size = self.get_default_size()
- self.widget = wx.ScrolledWindow(parent, -1, size=self.image_size)
- sw_sizer = wx.BoxSizer(wx.VERTICAL)
- self.widget.SetSizer(sw_sizer)
+ self.widget = ImageViewer(parent, self.image_size, self._gfObject.fit)
- if self.managed:
- bmp = wx.StaticBitmap(self.widget, -1, wx.NullBitmap,
- size=self.image_size)
- else:
- bmp = wx.StaticBitmap(self.widget, -1, wx.NullBitmap)
-
- sw_sizer.Add(bmp, 1, wx.EXPAND)
-
self.getParent().add_widgets(self, spacer)
- return bmp
+ return self.widget
# -------------------------------------------------------------------------
@@ -120,47 +240,12 @@
"""
if PILImage is None:
- return
+ return
- widget = self.widgets [index]
- scrx, scry = self.image_size
- imgx, imgy = value.size
+ widget = self.widgets[index]
+ widget.SetValue(value)
- scalex = scaley = 1
- fit = self._gfObject.fit
-
- if fit == "auto":
- if float (scrx) / imgx < float (scry) / imgy:
- fit = "width"
- else:
- fit = "height"
-
- if fit == "width":
- scalex = scaley = float (scrx) / imgx
-
- elif fit == "height":
- scalex = scaley = float (scry) / imgy
-
- elif fit == "both":
- scalex = float (scrx) / imgx
- scaley = float (scry) / imgy
- else:
- self.widget.SetScrollRate (10, 10)
-
- if scalex != 1 or scaley != 1:
- value = value.resize ((abs (int (imgx * scalex)),
- abs (int (imgy * scaley))), PILImage.BICUBIC)
-
- # Convert the PIL Image to a wxBitmap
- wxImg = wx.EmptyImage(value.size[0], value.size[1])
- wxImg.SetData(value.convert("RGB").tostring())
- image = wxImg.ConvertToBitmap()
-
- widget.SetBitmap(image)
- widget.Refresh()
-
-
# =============================================================================
# Configuration data
# =============================================================================
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r9504 - in trunk/gnue-forms/src: GFObjects input/displayHandlers uidrivers/wx26 uidrivers/wx26/widgets,
johannes <=