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