how do I start PyCrust?
7stud
bbxx789_05ss at yahoo.com
Fri Jun 8 01:29:07 PDT 2007
Robin Dunn <robin <at> alldunn.com> writes:
> > 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.
I think I confused you. In my original post--where my code didn't have the
"if __name__ " guard--the first thing that was displayed was the program
window. I stated that I had to close the program window before the pycrust
window would display. I also said that I found another program window behind
the pycrust window. Once I included the "if __name__" guard, it caused the
pycrust window to display first thing, and the program window was behind the
pycrust window as before.
The problem I am now having is that I can't get the example on p.100-103 of
"wxPython in Action" to work: nothing in the program window changes color when
I enter the commands in pycrust. This is the code I am using:
wxPython1.py:
------
import wx
class MyFrame(wx.Frame):
pass
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame(parent=None, id=-1, title="Test")
self.frame.Show()
self.SetTopWindow(self.frame)
return True
if __name__ == "__main__":
app = MyApp()
app.MainLoop()
-----------------------
Then I did a pywrap:
$ /usr/local/bin/pywrap wxPython1.py
and I typed the following into the pycrust window:
------
>>> import wx
>>> app.frame.panel = wx.Panel(parent=app.frame)
>>> app.frame.panel.SetBackgroundColour("blue")
True
----------
The book says:
-----
However, setting the panel background color doesn't immediately change its
appearance. Instead, something needs to trigger an event that causes the
panel to repaint itself, using its new background color property. One way to
trigger such an event is to ask the panel to refresh itself:
>>>app.frame.panel.Refresh()
---------------
So I typed in:
---
>>> app.frame.panel.Refresh()
>>>
--------------
And nothing in the window turned blue.
> Try calling app.frame.SendSizeEvent().
Ok. I closed out the pycrust and program windows, and I did another pywrap,
and this time instead of typing:
>>>app.frame.panel.Refresh()
I typed in:
>>>app.frame.SendSizeEvent()
and that caused the whole window to turn blue. Now my question is this: why
does "wxPython in Action" say to do a Refresh() instead of a SendSizeEvent()?
> 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.
I don't know what that means or what "auto size magic" is. I did try using
SetMinSize() on the panel before making by original post because in my limited
experience when nothing is in a panel, it shrinks to 0.
> But since the frame is
> already shown it doesn't get a size event at this point in time.
Right. So are you saying the only way to make a window redraw itself once
it's displayed is with a size event(assuming it doesn't get covered and
uncovered by another window)? In other words, Refresh() doesn't and shouldn't
work? Also, why is it that after the panel is repainted blue, I am able to
use SetBackgroundColour() to change the panel to the color red without having
to do a SendSizeEvent()?
More information about the wxpython-users
mailing list