Hello,
I would like some advise on how to implement scrolling support for a panel that is resized dynamically. The current implementation (attached) is not working. The sample creates the following UI
Frame with vertical box sizer
>
+---Editor(ScrolledPanel) with vertical box sizer (as reqd by ScrolledPanel?)
>
+---EditorPane(Panel) (resized to (vw, 3*vw) each time the ScrolledPanel view size changes. vw is the the view width size in pixels)
The issues
1) The EditorPane height does not change to 3*vw. Seems to be overwritten by another call
2) The EditorPane width does not change when the frame is enlarged horizontally (white region appears to the right)
3) Vertical scrollbar does not refresh as per the new EditorPane size probably because the Editor is not resizing correctly.
What would be the preferred approach to implementing this?
I am using wxPython 2.8 and Python 2.4 on WindowXP
Thanks
Kurien
import wx
import wx.lib.scrolledpanel as sp
import threading
import traceback
class EditorPane(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.SetBackgroundColour(wx.Colour(224, 224, 224))
self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self, event):
print 'editorpane:', event.GetSize()
class Editor(sp.ScrolledPanel):
def __init__(self, parent):
sp.ScrolledPanel.__init__(self, parent)
self.SetupScrolling()
# editor pane (Panel) in vertical box sizer
self.pane = EditorPane(self)
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(self.sizer)
self.sizer.Add(self.pane)
self.Bind(wx.EVT_SIZE, self.OnSize)
def OnSize(self, event):
viewSize = event.GetSize()
scale = wx.Size(1, 3)
size =wx.Size(viewSize.x*scale.x, viewSize.x*scale.y)
print viewSize, scale, size
self.pane.SetSize(size)
class AppFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "tsan")
self.SetBackgroundColour(wx.Colour(180, 180, 180))
# editor(ScrolledPanel) in vertical box sizer
vsizer = wx.BoxSizer(wx.VERTICAL)
self.SetSizer(vsizer)
hexEditor = Editor(self)
hexEditor.SetBackgroundColour(wx.Colour(255, 255, 255))
vsizer.Add(hexEditor, 1, wx.EXPAND)
app = wx.PySimpleApp()
frame = AppFrame()
frame.Show()
app.MainLoop()
test.py (1.48 KB)