[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnue] r8782 - trunk/gnue-forms/src/uidrivers/qt3/widgets
From: |
johannes |
Subject: |
[gnue] r8782 - trunk/gnue-forms/src/uidrivers/qt3/widgets |
Date: |
Fri, 13 Oct 2006 05:29:47 -0500 (CDT) |
Author: johannes
Date: 2006-10-13 05:29:45 -0500 (Fri, 13 Oct 2006)
New Revision: 8782
Added:
trunk/gnue-forms/src/uidrivers/qt3/widgets/image.py
Log:
added image widget
Added: trunk/gnue-forms/src/uidrivers/qt3/widgets/image.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/qt3/widgets/image.py 2006-10-13 09:41:42 UTC
(rev 8781)
+++ trunk/gnue-forms/src/uidrivers/qt3/widgets/image.py 2006-10-13 10:29:45 UTC
(rev 8782)
@@ -0,0 +1,154 @@
+# GNU Enterprise Forms - QT3 UI driver - Image widget
+#
+# Copyright 2001-2006 Free Software Foundation
+#
+# This file is part of GNU Enterprise
+#
+# GNU Enterprise is free software; you can redistribute it
+# and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation; either
+# version 2, or (at your option) any later version.
+#
+# GNU Enterprise is distributed in the hope that it will be
+# useful, but WITHOUT ANY WARRANTY; without even the implied
+# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+# PURPOSE. See the GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public
+# License along with program; see the file COPYING. If not,
+# write to the Free Software Foundation, Inc., 59 Temple Place
+# - Suite 330, Boston, MA 02111-1307, USA.
+#
+# $Id$
+
+import qt
+import cStringIO
+
+try:
+ from PIL import Image as PILImage
+
+except:
+ PILImage = None
+
+from gnue.common.definitions import GParser
+from gnue.forms.uidrivers.qt3.widgets import _base
+
+# =============================================================================
+# Exceptions
+# =============================================================================
+
+class MissingSizeError(GParser.MarkupError):
+ """ Image has no size given """
+ def __init__(self, image):
+ msg = u_("Image '%(name)s' is missing one of Sizer:width or "
+ "Sizer:height") % {'name': image.name}
+ GParser.MarkupError.__init__(self, msg, image._url, image._lineNumber)
+
+
+# =============================================================================
+# Wrap an UI layer around a wx image
+# =============================================================================
+
+class UIImage (_base.UIHelper):
+ """
+ Creates a single instance of an image.
+ """
+
+ # ------------------------------------------------------------------------
+ # Create an image widget
+ # ------------------------------------------------------------------------
+
+ def _create_widget_ (self, event, spacer):
+ """
+ Creates a new StaticBitmap widget.
+ """
+
+ parent = event.container
+
+ (min_w, min_h) = self.get_default_size()
+ self.widget = qt.QLabel(parent)
+ self.widget.setMinimumSize(min_w, min_h)
+
+ self.getParent().add_widgets(self, spacer)
+
+ return self.widget
+
+
+ # -------------------------------------------------------------------------
+ # Get the default size for the image
+ # -------------------------------------------------------------------------
+
+ def get_default_size(self):
+
+ if self.managed:
+ width = int(getattr(self._gfObject, 'Sizer__width', -1))
+ height = int(getattr(self._gfObject, 'Sizer__height', -1))
+ if width == -1 or height == -1:
+ raise MissingSizeError(self._gfObject)
+ else:
+ width = self._uiDriver.cell_width * self.chr_w
+ height = self._uiDriver.cell_height * self.chr_h
+
+ return (width, height)
+
+
+ # ------------------------------------------------------------------------
+ # Set the widget's PIL
+ # ------------------------------------------------------------------------
+
+ def _ui_set_value_(self, index, value):
+ """
+ Loads an image.
+ """
+
+ if PILImage is None:
+ return
+
+ widget = self.widgets [index]
+ scrx, scry = self.get_default_size()
+ imgx, imgy = value.size
+
+ 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:
+ # TODO: is there something like a ScrollWindow ?
+ pass
+
+ 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 QPixmap
+ # TODO: find a better way than using StringIO
+ f = cStringIO.StringIO()
+ value.save(f, 'PNG')
+ pxm = qt.QPixmap()
+ pxm.loadFromData(f.getvalue())
+ widget.setPixmap(pxm)
+
+# =============================================================================
+# Configuration data
+# =============================================================================
+
+configuration = {
+ 'baseClass': UIImage,
+ 'provides' : 'GFImage',
+ 'container': 0,
+}
Property changes on: trunk/gnue-forms/src/uidrivers/qt3/widgets/image.py
___________________________________________________________________
Name: svn:keywords
+ Id
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnue] r8782 - trunk/gnue-forms/src/uidrivers/qt3/widgets,
johannes <=