How wxDefaultSize expand

I write following wxpython code, button,listbox widget can expand.
but self.image_view = ImagePanel( panel ) cann't expand. why? how to
expand image_view panel.
my wxDefaultSize always 20.
I need a imagepanel, hope the imagepanel can clear, change image.

-- Rill

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import wx
import os

class ImageView(wx.Window):
    def __init__(self, parent, id=-1, pos=wx.DefaultPosition,
size=wx.DefaultSize,
                 style=wx.BORDER_SUNKEN
                 ):
        wx.Window.__init__(self, parent, id, pos, size, style=style)

        self.image = None

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

    def SetValue(self, filename): # display the selected file in
the panel
        self.image = wx.Image(filename, wx.BITMAP_TYPE_ANY)
        self.Refresh()

    def OnPaint(self, event):
        dc = wx.PaintDC(self)
        self.DrawImage(dc)

    def DrawImage(self, dc):
        wwidth,wheight = self.GetSize()
        image = self.image
        bmp = None

        dc.DrawBitmap(bmp, 0, 0, useMask=True) # draw the image
to window

class ImagePanel(wx.Panel):
    def __init__(self, parent, id=-1, pos=wx.DefaultPosition,
size=wx.DefaultSize, style=wx.NO_BORDER ):
        wx.Panel.__init__(self, parent, id, pos, size, style=style)
        self.view = ImageView(self)

    def SetValue(self, filename): # display the selected file in
the panel
        self.view.SetValue(filename)

class Frame(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "Image Show", size=(800,
600))
        panel = wx.Panel(self)

        self.filename = None

        self.listbox = wx.ListBox(panel, -1, (20, 20), (150, 150),
["listbox1"], wx.LB_EXTENDED)
        self.listbox2 = wx.ListBox(panel, -1, (20, 20), (150, 150),
["listbox2"], wx.LB_EXTENDED)

        button_open_dir = wx.Button(panel, label="button", size=(30,
-1))

        vbox_top = wx.GridSizer(cols=2, hgap=5, vgap=5)

        self.image_view = ImagePanel( panel )
        vbox_top.Add(button_open_dir, 0, flag=wx.EXPAND)
        vbox_top.Add(self.listbox, 0, wx.EXPAND)
        vbox_top.Add(self.image_view, 1, wx.GROW|wx.ALL, 0)
        vbox_top.Add(self.listbox2, 0, wx.EXPAND)

        panel.SetSizer(vbox_top)
        vbox_top.Fit(self)

class App(wx.App):
    def OnInit(self):
        self.frame = Frame()
        self.frame.Show()
        self.SetTopWindow(self.frame)
        return True

def main():
    app = App()
    app.MainLoop()

if __name__ == '__main__':
    main()

Hi,

I write following wxpython code, button,listbox widget can expand.
but self.image_view = ImagePanel( panel ) cann't expand. why? how to
expand image_view panel.
my wxDefaultSize always 20.
I need a imagepanel, hope the imagepanel can clear, change image.

You are missing a sizer, see attached.

BTW, it is better to attach then to put code in line as that messes indentation etc up.

I also had an error (on wxPy 2.9.3 the way you used initialized the bmp = None and to figure your actual problem out I added the WIT to your code, run it and press ctrl-alt-i, it showed me pretty quickly that ImagePanel had no sizer to control its child.

Werner

sizingissue.py (2.56 KB)

···

On 26/04/2012 09:37, luckrill wrote:

It's ok now. thank you very very much.
imagepanel need size.
ctrl-alt-i very good

···

On 4月26日, 下午11时20分, Werner <werner.bru...@sfr.fr> wrote:

Hi,

On 26/04/2012 09:37, luckrill wrote:> I write following wxpython code, button,listbox widget can expand.
> but self.image_view = ImagePanel( panel ) cann't expand. why? how to
> expand image_view panel.
> my wxDefaultSize always 20.
> I need a imagepanel, hope the imagepanel can clear, change image.

You are missing a sizer, see attached.

BTW, it is better to attach then to put code in line as that messes
indentation etc up.

I also had an error (on wxPy 2.9.3 the way you used initialized the bmp
= None and to figure your actual problem out I added the WIT to your
code, run it and press ctrl-alt-i, it showed me pretty quickly that
ImagePanel had no sizer to control its child.

Werner

sizingissue.py

start app as max window is OS problem.
void Maximize(Bool maximize)
Maximizes the frame if maximize is TRUE, otherwise restores it (MS
Windows only).

with MS Windows: display as max window and self.GetSize() return value
is max window size.
with linux/GTK: display as max window but self.GetSize() return value
is (400, 250)

Don't know how to avoid this OS problem.

···

--
jiang zhixiang