[wxPython-users] Re: how do I start PyCrust?
Robin Dunn
robin at alldunn.com
Wed Jun 6 22:23:43 PDT 2007
7stud wrote:
> Robin Dunn <robin <at> alldunn.com> writes:
>> For pywrap to work you need to not automatically create the app and run
>> the MainLoop when the module is imported. Try it like this:
>>
>> import wx
>>
>> class MyFrame(wx.Frame):
>> pass
>>
>> class MyApp(wx.App):
>> def OnInit(self):
>> self.frame = MyFrame(None, -1, "Test")
>> self.frame.Show()
>> self.SetTopWindow(self.frame)
>> return True
>>
>> if __name__ == '__main__':
>> app = MyApp()
>> app.MainLoop()
>>
>> This way pywrap can import the module and then create the instance of
>> the application object itself. It also calls MainLoop.
>>
>
> When I added the "if __name__" guard, the pycrust window was now the
> first window displayed. Then I entered the following into pycrust:
>
They should both be showing up. Pywrap creates the instance of the app,
which creates a frame and shows it, and then it creates and shows the
PyCrust frame, and then it calls MainLoop.
> PyCrust 0.9.5 - The Flakiest Python Shell
> Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
> [GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> import wx
>>>> app.frame.panel = wx.Panel(parent=app.frame)
>>>> app.frame.panel.SetBackgroundColour("blue")
> True
>>>> app.frame.panel.Refresh()
>>>> app.frame.panel.ClearBackground()
>>>>
>
> However, neither Refresh() nor ClearBackground() succeeded in
> repainting the panel blue. I also tried Refresh() on the frame, and that
> didn't work either. So the "if __name__" guard didn't solve the
> painting problem.
It's not a painting problem, it is a sizing problem. You're leaving
panel at the default (very small) size, and the frame's auto size magic
only happens when the frame gets a size event. But since the frame is
already shown it doesn't get a size event at this point in time. Try
calling app.frame.SendSizeEvent().
>
> If I manually resize the window, then it repaints itself in blue.
This is the clue you needed.
--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!
More information about the wxpython-users
mailing list