commit-gnue
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnue] r6945 - trunk/gnue-forms/src/uidrivers/win32/widgets


From: btami
Subject: [gnue] r6945 - trunk/gnue-forms/src/uidrivers/win32/widgets
Date: Thu, 3 Feb 2005 04:17:44 -0600 (CST)

Author: btami
Date: 2005-02-03 04:17:43 -0600 (Thu, 03 Feb 2005)
New Revision: 6945

Modified:
   trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py
Log:
added 'fit' attrib support to image widgets in win32 uidriver

Modified: trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py       2005-02-03 
10:16:46 UTC (rev 6944)
+++ trunk/gnue-forms/src/uidrivers/win32/widgets/_base.py       2005-02-03 
10:17:43 UTC (rev 6945)
@@ -35,7 +35,8 @@
 from gnue.forms.uidrivers._base.widgets._base import *
 from gnue.forms.uidrivers.win32.common import *
 
-try:
+try:
+  import Image
   import ImageWin
 except:
   pass
@@ -224,7 +225,7 @@
       gfObject = self._uiDriver._IdToGFObj[self._id]
       if gfObject._type == 'GFImage':
         win32gui.CallWindowProc(self._oldWndProc, hwnd, msg, wParam, lParam)
-        hdc = win32gui.GetDC(self._hwnd)
+        hdc = win32gui.GetDC(self._hwnd)
         self.dib.expose(hdc)
         win32gui.ReleaseDC(self._hwnd,hdc)
       else:
@@ -448,14 +449,46 @@
 
 class Win32Image(Win32Base):
     
-  def SetValue(self, value):
-    width, height = value.size
-    win32gui.SetWindowPos(self._hwnd, 0, 0, 0, 0, 0, win32con.SWP_NOMOVE | 
win32con.SWP_NOZORDER)
-    if width>1:
-      win32gui.SetWindowPos(self._hwnd, 0, 0, 0, width, height, 
win32con.SWP_NOMOVE | win32con.SWP_NOZORDER)
-      self.dib = ImageWin.Dib(value)
+  def SetValue(self, value):
+    l,t,r,b = win32gui.GetWindowRect(self._hwnd)
+    scrx,scry = (r-l, b-t)
+    imgx, imgy = value.size
+    
+    gfObject = self._uiDriver._IdToGFObj[self._id]
+
+    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
+
+    if scalex != 1 or scaley != 1:
+      value = value.resize((abs(int(imgx * (scalex))), abs(int(imgy * 
(scaley)))), Image.BICUBIC)
+
+    # clear the previous image
+    win32gui.SetWindowPos(self._hwnd, 0, 0, 0, 0, 0, win32con.SWP_NOMOVE | 
win32con.SWP_NOZORDER)
+    
+    # resize the bitmap holder to match the image size again
+    win32gui.SetWindowPos(self._hwnd, 0, 0, 0, scrx, scry, win32con.SWP_NOMOVE 
| win32con.SWP_NOZORDER)
+    
+    # convert a PIL image to Dib
+    self.dib = ImageWin.Dib(value)
+    
+    # paint it
+    win32gui.SendMessage(self._hwnd, win32con.WM_PAINT, 0, 0)
+
+
 #
 # UIHelper
 #





reply via email to

[Prev in Thread] Current Thread [Next in Thread]