[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
r5857 - in trunk/gnue-forms/src: . uidrivers/wx/widgets
From: |
jcater |
Subject: |
r5857 - in trunk/gnue-forms/src: . uidrivers/wx/widgets |
Date: |
Wed, 2 Jun 2004 11:22:51 -0500 (CDT) |
Author: jcater
Date: 2004-06-02 11:22:50 -0500 (Wed, 02 Jun 2004)
New Revision: 5857
Modified:
trunk/gnue-forms/src/GFParser.py
trunk/gnue-forms/src/uidrivers/wx/widgets/image.py
Log:
Added support for auto-fitting images in the <image> tag.
Modified: trunk/gnue-forms/src/GFParser.py
===================================================================
--- trunk/gnue-forms/src/GFParser.py 2004-06-02 14:26:57 UTC (rev 5856)
+++ trunk/gnue-forms/src/GFParser.py 2004-06-02 16:22:50 UTC (rev 5857)
@@ -683,6 +683,16 @@
'URL': {'Label': _('Field contains the URL of the image')},
'PIL': {'Label': _('Field contains a PIL encoding of the
image')} },
'Default': "URL",
+ 'Description': 'The type of image reference. Can be {URL} for a
url reference, or {PIL} for an embedded image.' },
+ 'fit': {
+ 'Typecast': GTypecast.name,
+ 'ValueSet': {
+ 'none': {'Label': _('Full-size image (no scaling)')},
+ 'width': {'Label': _('Scale to width')},
+ 'height': {'Label': _('Scale to height')},
+ 'both': {'Label': _('Scale width and height (may distort
image)')},
+ 'auto': {'Label': _('Use a best-fit algorithm')} },
+ 'Default': "none",
'Description': 'TODO' },
'editable': {
'Description': 'Only allow this object to be edited if it '
Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/image.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/image.py 2004-06-02 14:26:57 UTC
(rev 5856)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/image.py 2004-06-02 16:22:50 UTC
(rev 5857)
@@ -40,13 +40,9 @@
def _createWidget(self, event, spacer):
object = event.object
- #im = Image.open("/home/jamest/cvs/ajrs/imaging/src/testfoo.png")
- #wxImg = wxEmptyImage(im.size[0],im.size[1])
- #wxImg.SetData(im.tostring())
- #png = wxImg.ConvertToBitmap()
-
+
png=wxEmptyBitmap(1,1)
-
+
self.pane = wxScrolledWindow(event.container, -1,
wxPoint(object.Char__x*event.widgetWidth,
(object.Char__y+spacer+(spacer*object._gap))*event.widgetHeight),
@@ -57,17 +53,12 @@
imageWidth = png.GetWidth()
imageHeight = png.GetHeight()
self.imageWindow = wxStaticBitmap(self.pane, -1, png,
- wxPoint(0,0), #object.Char__x*event.widgetWidth,
-
#(object.Char__y+spacer+(spacer*object._gap))*event.widgetHeight),
+ wxPoint(0,0),
wxSize(imageWidth,imageHeight))
- #self.imageWindow = wxStaticBitmap(self.pane, -1, png,
- # wxPoint(object.Char__x*event.widgetWidth,
- #
(object.Char__y+spacer+(spacer*object._gap))*event.widgetHeight),
- # wxSize(self.itemWidth,self.itemHeight))
self.fixScrollbars()
-
+
return self.imageWindow
-
+
def OnFrameSize(self, event):
pass
#self.pane.SetSize(self.pane.GetClientSize())
@@ -88,13 +79,44 @@
widget = self.widgets[index]
widget.SetEvtHandlerEnabled(FALSE)
+ scrx, scry = self.pane.GetClientSizeTuple()
+ imgx, imgy = value.size
+ gfObject = self._uiDriver._IdToGFObj[widget.GetId()]
+
+
+ scalex = scaley = 1
+
+ fit = 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
+
+## print "(%s, %s) (%s, %s)" % (scrx, scry, imgx, imgy)
+## print "(%s, %s)" % (abs(int(imgx*scalex)), abs(int(imgy*scaley)))
+## print "%s%% %s%%" % (scalex, scaley)
+
+ if scalex != 1 or scaley != 1:
+ value = value.resize((abs(int(imgx*(scalex))), abs(int(imgy*(scaley)))),
Image.BICUBIC)
+
+
# Convert the PIL Image to a wxBitmap
wxImg = wxEmptyImage(value.size[0],value.size[1])
wxImg.SetData(value.convert("RGB").tostring())
image = wxImg.ConvertToBitmap()
# Resize the bitmap holder to match the image size
- # and fix the scrollbars
+ # and fix the scrollbars
imageWidth = image.GetWidth()
imageHeight = image.GetHeight()
widget.SetSize(wxSize(imageWidth,imageHeight))
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- r5857 - in trunk/gnue-forms/src: . uidrivers/wx/widgets,
jcater <=