Calling parent functions from an embedded pyShell??

You need to expose your commands to the environment/namespace in which the shell is executing. The easiest way to do so is when you create the pyshell object by passing a dictionary as the "locals" argument. Here is how it is done in the wxPython Demo application:

     def on_OpenShellWindow(self, evt):
         if self.shell:
             # if it already exists then just make sure it's visible
             s = self.shell
             if s.IsIconized():
                 s.Iconize(False)
             s.Raise()
         else:
             # Make a PyShell window
             from wx import py
             namespace = { 'wx' : wx,
                           'app' : wx.GetApp(),
                           'frame' : self,
                           }
             self.shell = py.shell.ShellFrame(None, locals=namespace)
             self.shell.SetSize((640,480))
             self.shell.Show()

             # Hook the close event of the main frame window so that we
             # close the shell at the same time if it still exists
             def CloseShell(evt):
                 if self.shell:
                     self.shell.Close()
                 evt.Skip()
             self.Bind(wx.EVT_CLOSE, CloseShell)

Hope that helps,

Pat

···

On Nov 13, 2007, at 6:30 PM, Patrick Van Pelt wrote:

I think this is probably an easy one, but I just can't quite get my head around it right now. :stuck_out_tongue:

I have an Aui app that has a pyShell embedded in one of the dockable subpanels. I'd like to be able to have certain commands and functions (living in a sibling class) be available so that the commands can be eexecuted from the shell. What would be the best way to achieve this? I tried importing the sibling class into the panel that has the shell object, but it couldn't access it that way (couldn't get out of its own shell bubble, I assume). I was able to import the sibling class at runtime through the shell, but it still didn't have any sense of the parent windows (some functions and variables traverse across the panels).

--
Patrick K. O'Brien
Orbtech http://www.orbtech.com
Schevo http://www.schevo.org

Subclass from py.interpreter.Interpreter and override the "push"
method, which is whats used to push text into the actual Python
interpreter. You'll need to handle multi-line input, see the source
for some details.

You can then have your pyshell use your custom subclass by passing it
as the interpClass parameter to py.shell.Shell.

···

On Nov 14, 2007 1:16 PM, Patrick Van Pelt <patrick@laika.com> wrote:

Aha! I new it would be simple! Thank you so much, its working great now!

One more simple question, though. How can I capture the user's ENTER command after he has typed a command in the pyShell? I tried doing the usual bind to the TEXT_ENTER event, but it doesn't seem to capture that. I guess because pyShell is using it internally? It looks like the pyShell object has some of its own event handler functions, but I'm not sure how to use those as they don't seem "bindable." All I want to do is notify the parent window that the user has entered a command (and that it will probably need to update something)