Dynamic Resizing and Centering Image.

mkey wrote:

Only subclass of Window can be add to any sizers.
( this is not my misunderstandings, isnt it? )

So, do you know how we can add Image or Bitmap object to sizers?
Could you please tell me?
  
self.bitmap=wxStaticBitmap(self, ID_NULL, jpg, wxPoint(0, 0),
wxSize(jpg.GetWidth(), jpg.GetHeight()))
sizer_image_buttons.Add(self.bitmap, 1, wxEXPAND)

... is a very simple example to add an image to a sizer.

Hello Niels,

I wrote some code that I use StaticBitmap and BoxSizer.
But if I try to make frame bigger, StaticBitmap object never move and resize.
The below sample is something wrong?

Kindly Regards
mk

class SampleClass(wx.Frame):

    def __init__(self, parent):
        
        # init operations
        wx.Frame.__init__(self, parent, -1, size=(550, 550))
        self.Show()
        self.panel = wx.Panel(self, -1, size=(500,500), style= wx.DOUBLE_BORDER)
        self.panel.SetBackgroundColour(wx.Color(255,255,255))

        self.bmp = wx.Image( 'PATH_TO_IMAGE' ).Scale(450,450).ConvertToBitmap()
        self.stBmp = wx.StaticBitmap(self.panel, -1, self.bmp, (0,0))
        
        sizer = wx.BoxSizer()
        sizer.Add(self.panel, 1, wx.EXPAND | wx.ALIGN_CENTER, wx.ALL)
        self.SetSizer(sizer)
        
        sizer2 = wx.BoxSizer( )
        sizer2.Add(self.stBmp, 1, wx.EXPAND | wx.ALIGN_CENTER, wx.ALL)
        self.panel.SetSizer(sizer2)
        
        self.SetSize((self.GetSize()[0]-10,self.GetSize()[1]-10) )

···

----- Original Message -----
From: Niels Huylebroeck <niels@bubbles-it.be>
To: wxPython-users@lists.wxwidgets.org
Sent: Tue, 15 Jan 2008 17:02:19 +0100
Subject: Re: [wxPython-users] Dynamic Resizing and Centering Image.

mkey wrote:

Only subclass of Window can be add to any sizers.
( this is not my misunderstandings, isnt it? )

So, do you know how we can add Image or Bitmap object to sizers?
Could you please tell me?
  
self.bitmap=wxStaticBitmap(self, ID_NULL, jpg, wxPoint(0, 0),
wxSize(jpg.GetWidth(), jpg.GetHeight()))
sizer_image_buttons.Add(self.bitmap, 1, wxEXPAND)

... is a very simple example to add an image to a sizer.

You need to tell wxPython that it's been resized by binding a handler to
an EVT_SIZE event. Then in the handler you would need to re-scale the
photo and then do a Refresh().

I did some Googling and I think you may be able to modify the code in this
thread to get you started:

http://lists.wxwidgets.org/archive/wxPython-users/msg07634.html

I messed around a bit before I found that and discovered that EVT_SIZE
tends to fire multiple times. The code in that link seems to alleviate the
issue. Since I don't know much about picture resizing, you'll have to wait
for one of those gurus.

Mike

···

-----Original Message-----
From: mkey [mailto:mkey@inter7.jp]
Sent: Tuesday, January 15, 2008 10:46 AM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Dynamic Resizing and Centering Image.

Hello Niels,

I wrote some code that I use StaticBitmap and BoxSizer.
But if I try to make frame bigger, StaticBitmap object never
move and resize.
The below sample is something wrong?

Kindly Regards
mk

class SampleClass(wx.Frame):

    def __init__(self, parent):
        
        # init operations
        wx.Frame.__init__(self, parent, -1, size=(550, 550))
        self.Show()
        self.panel = wx.Panel(self, -1, size=(500,500),
style= wx.DOUBLE_BORDER)
        self.panel.SetBackgroundColour(wx.Color(255,255,255))

        self.bmp = wx.Image( 'PATH_TO_IMAGE'
).Scale(450,450).ConvertToBitmap()
        self.stBmp = wx.StaticBitmap(self.panel, -1, self.bmp, (0,0))
        
        sizer = wx.BoxSizer()
        sizer.Add(self.panel, 1, wx.EXPAND | wx.ALIGN_CENTER, wx.ALL)
        self.SetSizer(sizer)
        
        sizer2 = wx.BoxSizer( )
        sizer2.Add(self.stBmp, 1, wx.EXPAND | wx.ALIGN_CENTER, wx.ALL)
        self.panel.SetSizer(sizer2)
        
        self.SetSize((self.GetSize()[0]-10,self.GetSize()[1]-10) )

maybe this will help.

-Chris

StaticBitmap.py (2.59 KB)

···

--
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