wxStaticBitmap as Delphi TImage?

durumdara@gmail.com wrote:

Your code is very interesting, but not working good in my machine. Possible it is windows s*ing :-(....

Well, I only tested in OS-X, there are subtle differences.

I installed the new version of the wxPython 2.4 unicode today, but the problem remaining.

I hope you mean wxPython2.8 -- 2.4 is very old.

Are you see that the growing is not working good?

strange -- that must be the system setting a clipping region so that only the expanded part of the Window is re-drawn

And this?

Similar issue, I think.

In Delphi I can solve these problems with a Timer that fired 10 (20, 100, 250) ms after the resize and destroys prev. Timer class.

You can do the same thing in wxPython, with a wx.Timer. I've done that for things that take a while to re-draw. However, I suspect this is fast enough that it should be able to keep up with the Window re-size.

Or if not then how I force the full repaint in your code?

I've just tested on Windows, and I get the same result. Adding a self.Refresh() call at the end of the OnSize() method works, but results in some flashing. I think it's clearing the Window before re-painting it.

Then I tried a dc.DestroyClippingRegion() call in the OnPaint, but that did nothing -- apparently, the clipping is happening somewhere down in the system, not at the DC level. Indeed, a call to dc.Clear() didn't work either.

So: how do I get it to repaint the whole window, but without clearing it first?

I think this may have been covered in a recent thread on this list -- something about a gradient background -- take a look at the last week or so's posts.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Hi!

Christopher Barker írta:

wrote:
I hope you mean wxPython2.8 – 2.4 is very old.

Sorry, 2.8, but py 2.4… :frowning:

I think this may have been covered in a recent thread on this list –
something about a gradient background – take a look at the last week
or so’s posts.

-Chris

Thanks for your help. With this extension it is working good:

#!/usr/bin/env python

“”"

ImageWindow.py

A wx component for a resazable window that holds an image

“”"

import wx

class ImageWindow(wx.Window):

"""

ImageWindow(Image, *args, **kwargs)



Image: A wx.Image

*args and **kwargs are passed in to wx.Window

"""



def __init__(self, Image, *args, **kwargs):

    wx.Window.__init__(self, *args, **kwargs)



    self.Image = Image

    self._buffer = None

    self.KeepAspect = True



    self.Bind(wx.EVT_PAINT, self.OnPaint)

    self.Bind(wx.EVT_SIZE, self.OnSize)

    self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)  

################## THIS

def OnEraseBackground(self, event):

    pass    ######################### AND THIS





def OnPaint(self, event):

    print "in OnPaint"

    dc = wx.BufferedPaintDC(self)

    #wx.PaintDC(self)

    w, h = self.GetSize()

    dc.DrawRectangle(0, 0, w, h)

    dc.DrawBitmap(self._buffer, 0, 0)

    #dc.FullRepaint()



def OnSize(self, event):

    print "in OnSize"

    w, h = self.GetSize()

    if not self.KeepAspect:

        # scale the image to the new window size

        Img = self.Image.Scale(w, h)

    else:

        # scale the image, preserving the aspect ratio

        iw = self.Image.GetWidth()

        ih = self.Image.GetHeight()

        if float(iw) / ih > float(w) / h:

            NewW = w

            NewH = w * ih / iw

        else:

            NewH = h

            NewW = h * iw / ih

        Img = self.Image.Scale(NewW,NewH)

    self._buffer = wx.BitmapFromImage(Img)

    #self.Refresh()

if name == “main”:

import TestImage

class TestFrame(wx.Frame):

    def __init__(self, *args, **kwargs):

        wx.Frame.__init__(self, *args, **kwargs)



        # there needs to be an image here:

        Image = TestImage.getImage()



        # create the ImageWindow

        IW = ImageWindow(Image, self,

style=wx.FULL_REPAINT_ON_RESIZE)

        # Using a Sizer to handle the layout: I never like to use

absolute postioning

        box = wx.BoxSizer(wx.VERTICAL)

        box.Add(IW, 1, wx.ALL | wx.EXPAND, 10)



        self.SetSizer(box)

       

class App(wx.App):

    def OnInit(self):

        frame = TestFrame(None, title="ImageWindow Test",

size=(300, 300))

        self.SetTopWindow(frame)

        frame.Show(True)

        return True



app = App(False)

app.MainLoop()    

KoR:

            dd
···

durumdara@gmail.com

Christopher Barker wrote:

I've just tested on Windows, and I get the same result. Adding a self.Refresh() call at the end of the OnSize() method works, but results in some flashing. I think it's clearing the Window before re-painting it.

Then I tried a dc.DestroyClippingRegion() call in the OnPaint, but that did nothing -- apparently, the clipping is happening somewhere down in the system, not at the DC level.

Correct.

Indeed, a call to dc.Clear() didn't work either.

So: how do I get it to repaint the whole window, but without clearing it first?

Pass False to Refresh.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!