[wxPython] Overriding OnSize

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Overriding OnSize

Robertson Duane SSgt 82TRSS/TTCI

Seeing as I'm new to wxPython (and Python), could someone tell me why this
override doesn't work?

---------------------------

from wxPython.wx import *

class AdlApp(wxApp):
  def OnInit(self):
    frame = AdlFrame(NULL, -1, "Simplified")
    frame.Show(true)
    self.SetTopWindow(frame)
    return true

class AdlFrame(wxFrame):
  def __init__(self, parent, ID, title):
    wxFrame.__init__(self, parent, ID, title,
             wxDefaultPosition, wxSize(500, 300), wxTAB_TRAVERSAL |
wxDEFAULT_FRAME_STYLE )

    self.sizer = wxBoxSizer(wxHORIZONTAL)
    self.sizer.Add(ShowIt(self, 10, wxSize(500, 300)), 1, wxEXPAND)
   
    self.sizer.Fit(self)
   
    self.SetAutoLayout(true)
    self.SetSizer(self.sizer)

class ShowIt(wxScrolledWindow):
  def __init__(self, parent, id = -1, size = wxDefaultSize, virtualSize =
wxDefaultSize):
    wxScrolledWindow.__init__(self, parent, id, wxPoint(0, 0), size,
wxSUNKEN_BORDER)

    self.SetScrollbars(20, 20, 450, 250)

  def OnSize(self, event):
    wxScrolledWindow.OnSize(self, event)    #  <------------
   
def main():
  app = AdlApp(0)
  app.MainLoop()

main()

---------------------------

I get an attribute error in the call to "wxScrolledWindow.OnSize(self,
event)".  I suspect I'm missing something simple.


Duane Robertson


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Overriding OnSize

Robin Dunn

>
> Seeing as I'm new to wxPython (and Python), could someone tell me why this
> override doesn't work?
>
> def OnSize(self, event):
>     wxScrolledWindow.OnSize(self, event)    #  <------------
>


The correct way to pass an event up the heirarchy is to call event.Skip().
The fact that wxWindow::OnSize is documented at all is a holdover from
wxWindows 1.x when virtual functions were used instead of events.  The fact
that it exists by that name in the C++ version of the class is just
tradition.  The reality is that any method could be used to catch the size
event and so the only way to be sure that you are giving it to the right one
is to let the event system do it for you, hence the event.Skip().

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!







_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users