[wxPython] Scrollable panel

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

[wxPython] Scrollable panel

Niki Spahiev-3
This is example of wxFrame holding possibly bigger wxPanel.
panel.min_size is tuple of minimal dimensions of panel,
This is part of bigger code so might be not complete.

class UserFrame(wxFrame):
    def __init__(self, parent, id, title):
        wxFrame.__init__(self, parent, id, title, style =
                wxDEFAULT_FRAME_STYLE | wxHSCROLL | wxVSCROLL )
        self.panel = wxPanel( self, parent )
        EVT_SCROLLWIN( self, self.OnScroll)

    def OnScroll( self, event ):
        p = event.GetPosition()
        d = event.GetOrientation()
        if event.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK:
            self.SetScrollPos( d,p )
        px = self.GetScrollPos( wxHORIZONTAL )
        py = self.GetScrollPos( wxVERTICAL )
        self.panel.Move( wxPoint(-px, -py) )

    def OnSize( self, event ):
        cs = self.GetClientSize()
        px = self.GetScrollPos( wxHORIZONTAL )
        py = self.GetScrollPos( wxVERTICAL )
        self.SetScrollbar( wxHORIZONTAL, px, cs.x, self.panel.min_size[0] )
        self.SetScrollbar( wxVERTICAL  , py, cs.y, self.panel.min_size[1] )

Niki Spahiev
e-mail: [hidden email]

Get free email and a permanent address at http://www.netaddress.com/?N=1

wxPython-users maillist  -  [hidden email]