Author: reinhard
Date: 2010-10-20 09:20:26 -0500 (Wed, 20 Oct 2010)
New Revision: 10206

Modified:
   trunk/gnue-forms/
   trunk/gnue-forms/src/uidrivers/wx/widgets/image.py
Log:
Replaced black border around images with a standard sunken border, and made
images resizable.



Property changes on: trunk/gnue-forms
___________________________________________________________________
Name: bzr:revision-info
   - timestamp: 2010-10-20 14:45:41.104000092 +0200
committer: Reinhard Müller <reinhard.muel...@bytewise.at>
properties: 
        branch-nick: forms

   + timestamp: 2010-10-20 16:19:05.575999975 +0200
committer: Reinhard Müller <reinhard.muel...@bytewise.at>
properties: 
        branch-nick: forms

Name: bzr:file-ids
   - src/GFObjects/GFImage.py   
3...@3a364389-8fce-0310-8f11-cc363fde16c7:trunk%2Fgnue-forms:src%2FGFObjects%2FGFImage.py
src/uidrivers/wx/widgets/image.py       
10...@3a364389-8fce-0310-8f11-cc363fde16c7:trunk%2Fgnue-forms:src%2Fuidrivers%2Fwx%2Fwidgets%2Fimage.py

   + src/uidrivers/wx/widgets/image.py  
10...@3a364389-8fce-0310-8f11-cc363fde16c7:trunk%2Fgnue-forms:src%2Fuidrivers%2Fwx%2Fwidgets%2Fimage.py

Name: bzr:revision-id:v4
   - 3116 reinhard.muel...@bytewise.at-20100426083500-vtmq0qvd7htz02zx
3117 reinhard.muel...@bytewise.at-20100512151744-2jx8tmtop30kl5n0
3118 reinhard.muel...@bytewise.at-20100705094014-ks9yv7b8gs6ychrb
3119 reinhard.muel...@bytewise.at-20100706085143-hyxadj30ayg28jpx
3120 reinhard.muel...@bytewise.at-20100706140804-sn3npws1ykm81ubx
3121 reinhard.muel...@bytewise.at-20100909134008-5p7jq048nkutldse
3122 reinhard.muel...@bytewise.at-20100923144753-e8hthxho7n5mwg9z
3123 reinhard.muel...@bytewise.at-20100929193018-7r3injoy8g28fwm6
3124 reinhard.muel...@bytewise.at-20100930073631-ilf6smgjt6mfvkpz
3125 reinhard.muel...@bytewise.at-20101011191957-yaj9rkqbervc91ac
3126 reinhard.muel...@bytewise.at-20101020084039-jmfxjbctt6vc2usd
3127 reinhard.muel...@bytewise.at-20101020124425-0dpprxsmanmaenty
3128 reinhard.muel...@bytewise.at-20101020124541-zppkmzww1lnsk8x4

   + 3116 reinhard.muel...@bytewise.at-20100426083500-vtmq0qvd7htz02zx
3117 reinhard.muel...@bytewise.at-20100512151744-2jx8tmtop30kl5n0
3118 reinhard.muel...@bytewise.at-20100705094014-ks9yv7b8gs6ychrb
3119 reinhard.muel...@bytewise.at-20100706085143-hyxadj30ayg28jpx
3120 reinhard.muel...@bytewise.at-20100706140804-sn3npws1ykm81ubx
3121 reinhard.muel...@bytewise.at-20100909134008-5p7jq048nkutldse
3122 reinhard.muel...@bytewise.at-20100923144753-e8hthxho7n5mwg9z
3123 reinhard.muel...@bytewise.at-20100929193018-7r3injoy8g28fwm6
3124 reinhard.muel...@bytewise.at-20100930073631-ilf6smgjt6mfvkpz
3125 reinhard.muel...@bytewise.at-20101011191957-yaj9rkqbervc91ac
3126 reinhard.muel...@bytewise.at-20101020084039-jmfxjbctt6vc2usd
3127 reinhard.muel...@bytewise.at-20101020124425-0dpprxsmanmaenty
3128 reinhard.muel...@bytewise.at-20101020124541-zppkmzww1lnsk8x4
3129 reinhard.muel...@bytewise.at-20101020141905-vjg7r3wihnm7mxam

Name: bzr:text-parents
   - src/GFObjects/GFImage.py   
svn-v3-single1-dHJ1bmsvZ251ZS1mb3Jtcw..:3a364389-8fce-0310-8f11-cc363fde16c7:trunk%2Fgnue-forms:10015
src/uidrivers/wx/widgets/image.py       
svn-v3-single1-dHJ1bmsvZ251ZS1mb3Jtcw..:3a364389-8fce-0310-8f11-cc363fde16c7:trunk%2Fgnue-forms:10117

   + 

Modified: trunk/gnue-forms/src/uidrivers/wx/widgets/image.py
===================================================================
--- trunk/gnue-forms/src/uidrivers/wx/widgets/image.py  2010-10-20 12:46:14 UTC 
(rev 10205)
+++ trunk/gnue-forms/src/uidrivers/wx/widgets/image.py  2010-10-20 14:20:26 UTC 
(rev 10206)
@@ -59,16 +59,12 @@
 
     def __init__(self, parent, size=wx.DefaultSize, fit='auto'):
 
-        wx.Window.__init__(self, parent, -1, wx.DefaultPosition, size)
+        wx.Window.__init__(self, parent, -1, wx.DefaultPosition, size,
+                style=wx.BORDER_SUNKEN | wx.FULL_REPAINT_ON_RESIZE)
         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)
 
 
@@ -94,85 +90,46 @@
 
 
     # -------------------------------------------------------------------------
-    # 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:
+        if self.image is None:
             return
 
-        bmp = image.ConvertToBitmap()
+        bmp = self.image.ConvertToBitmap()
+        image_w = bmp.GetWidth()
+        image_h = bmp.GetHeight()
 
-        # Dimensions of the image file
-        iwidth = bmp.GetWidth()
-        iheight = bmp.GetHeight()
-        scrx = self.image_sizex
-        scry = self.image_sizey
+        win_w, win_h = self.GetClientSize()
 
         fit = self.fit
         if fit == "auto":
-            if float(scrx) / iwidth < float(scry) / iwidth:
+            if float(win_w) / image_w < float(win_h) / image_h:
                 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 fit == 'height':
+            image_w = int(image_w * float(win_h) / image_h)
+            image_h = win_h
 
-            if iheight >= self.image_sizey - 10:
-                diffy = 5
-                iheight = self.image_sizey - 10
+        elif fit == 'width':
+            image_h = int(image_h * float(win_w) / image_w)
+            image_w = win_w
 
-        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
+            image_w = win_w
+            image_h = win_h
 
-            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
+        x = max((win_w - image_w) / 2, 0)
+        y = max((win_h - image_h) / 2, 0)
 
-        image.Rescale(iwidth, iheight)      # rescale to fit the window
-        bmp = image.ConvertToBitmap()
-        dc.DrawBitmap(bmp, diffx, diffy)        # draw the image to window
+        img = self.image.Copy()
+        img.Rescale(image_w, image_h)
+        bmp = img.ConvertToBitmap()
+        dc.DrawBitmap(bmp, x, y)
 
 
 # =============================================================================


_______________________________________________
commit-gnue mailing list
commit-gnue@gnu.org
http://lists.gnu.org/mailman/listinfo/commit-gnue

Reply via email to