PyShell interactive experimentation

Hi,

This is probably already well-known: If you use PyShell (aka "The Flakiest Python Shell") that ships with the wxPython sample distribution, you can create widgets dynamically without having to create a wx.App-derived class instance first, e.g.:

import wx
frame = wx.Frame(None)
frame.Show()

True

... creates and displays a frame. I find this really handy since it allows you to create hierarchies step by step and see the changes visually (compared to one giant constructor in a wx.App derived class).

Happy wxPython'ing,

-Andreas

Andreas Schmid wrote:

Hi,

This is probably already well-known: If you use PyShell (aka "The Flakiest Python Shell") that ships with the wxPython sample distribution, you can create widgets dynamically without having to create a wx.App-derived class instance first, e.g.:

import wx
frame = wx.Frame(None)
frame.Show()

Yep, I do that nearly every day when testing things and etc. Very handy.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Any more examples of what can be done with PyShell? For example, adding a menu, at textEdit control, etc.? I tried the following but got errors:

   import wx
   f = wx.Frame(None)
   f.Show()
   f.SetTitle("Example")

That worked fine. But then I tried:

   m1 = wx.Menu()
   m1.Append(101, "Quit", "Quit the application")
   *** error ***

I reviewed other sources and the calltips in PyAlaMode, but I don't see what I'm doing wrong.

-- Clint

Robin Dunn wrote:

···

Andreas Schmid wrote:

Hi,

This is probably already well-known: If you use PyShell (aka "The Flakiest Python Shell") that ships with the wxPython sample distribution, you can create widgets dynamically without having to create a wx.App-derived class instance first, e.g.:

import wx
frame = wx.Frame(None)
frame.Show()

Yep, I do that nearly every day when testing things and etc. Very handy.

Clint Laskowski wrote:

Any more examples of what can be done with PyShell? For example, adding a menu, at textEdit control, etc.? I tried the following but got errors:

  import wx
  f = wx.Frame(None)
  f.Show()
  f.SetTitle("Example")

That worked fine. But then I tried:

  m1 = wx.Menu()
  m1.Append(101, "Quit", "Quit the application")
  *** error ***

I reviewed other sources and the calltips in PyAlaMode, but I don't see what I'm doing wrong.

What was the error?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn asked what the error was. Here is the full session (note that after 'f.Show()' the window was drawn correctly, and after 'f.SetTitle("Example")' the window title was drawn correctly. Obviously, my mistake has something to do with the way I'm trying to create the menu.

-- Clint

PyShell 0.9.4 - The Flakiest Python Shell
Sponsored by Orbtech - Your source for Python programming expertise.
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> f = wx.Frame(None)
>>> f.Show()
True
>>> f.SetTitle("Example")
>>> m1 = wx.Menu()
>>> m1.Append(101, "Quit", "Quit the Application")
<wx._core.MenuItem; proxy of C++ wxMenuItem instance at _984f7601_p_wxMenuItem>
>>>

Robin Dunn wrote:

···

Clint Laskowski wrote:

Any more examples of what can be done with PyShell? For example, adding a menu, at textEdit control, etc.? I tried the following but got errors:

  import wx
  f = wx.Frame(None)
  f.Show()
  f.SetTitle("Example")

That worked fine. But then I tried:

  m1 = wx.Menu()
  m1.Append(101, "Quit", "Quit the application")
  *** error ***

I reviewed other sources and the calltips in PyAlaMode, but I don't see what I'm doing wrong.

What was the error?

Clint Laskowski wrote:

Robin Dunn asked what the error was. Here is the full session (note that after 'f.Show()' the window was drawn correctly, and after 'f.SetTitle("Example")' the window title was drawn correctly. Obviously, my mistake has something to do with the way I'm trying to create the menu.

-- Clint

PyShell 0.9.4 - The Flakiest Python Shell
Sponsored by Orbtech - Your source for Python programming expertise.
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> f = wx.Frame(None)
>>> f.Show()
True
>>> f.SetTitle("Example")
>>> m1 = wx.Menu()
>>> m1.Append(101, "Quit", "Quit the Application")
<wx._core.MenuItem; proxy of C++ wxMenuItem instance at _984f7601_p_wxMenuItem>
>>>

That's not an error. It's the string representation of the return value of the Append method. Just like the f.Show returned True and it was printed, the Append returned a wx.MenuItem instance and it was printed.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Wow, do I feel stupid! Okay, thanks, that worked ... I just continued on building the menu and when I did the .SetMenuBar, it showed up and worked :-). Here's my entries into PyShell (with the PyShell responses):

import wx
f = wx.Frame(None)
f.Show()
f.SetTitle("Example")
f.CreateStatusBar()
f.SetStatusText("Greetings, Earthlings!")
mb = wx.MenuBar()
m = wx.Menu()
m.Append(100, "About", "About this Application", wx.ITEM_NORMAL)
m.AppendSeparator()
m.Append(101, "&Quit", "Quit the Application", wx.ITEM_NORMAL)
mb.Append(m, "&File")
f.SetMenuBar(mb)

Now, to make the "app" respond to menu events ...

-- Clint

Robin Dunn wrote:

···

Clint Laskowski wrote:

Robin Dunn asked what the error was. Here is the full session (note that after 'f.Show()' the window was drawn correctly, and after 'f.SetTitle("Example")' the window title was drawn correctly. Obviously, my mistake has something to do with the way I'm trying to create the menu.

-- Clint

PyShell 0.9.4 - The Flakiest Python Shell
Sponsored by Orbtech - Your source for Python programming expertise.
Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import wx
>>> f = wx.Frame(None)
>>> f.Show()
True
>>> f.SetTitle("Example")
>>> m1 = wx.Menu()
>>> m1.Append(101, "Quit", "Quit the Application")
<wx._core.MenuItem; proxy of C++ wxMenuItem instance at _984f7601_p_wxMenuItem>
>>>

That's not an error. It's the string representation of the return value of the Append method. Just like the f.Show returned True and it was printed, the Append returned a wx.MenuItem instance and it was printed.

Oops, that was suppose to say, "withOUT the PyShell responses".

I wrote:

···

Here's my entries into PyShell (with the PyShell responses):

Try it in this order (see the effects of each step):

     import wx
     f = wx.Frame(None)
     f.Show()
     mb = wx.MenuBar()
     f.SetMenuBar(mb)
     m = wx.Menu()
     mb.Append(m, '&Menu')

--Scott David Daniels
Scott.Daniels@Acm.Org