[wxPython-users] Calling parent functions from an embedded pyShell??

Patrick Van Pelt patrick at laika.com
Wed Nov 14 11:16:29 PST 2007


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)

Thanks again for the response!

----- Original Message -----
From: "Patrick K. O'Brien" <pobrien at orbtech.com>
To: wxPython-users at lists.wxwidgets.org
Sent: Wednesday, November 14, 2007 8:14:51 AM (GMT-0800) America/Tijuana
Subject: Re: [wxPython-users] Calling parent functions from an embedded pyShell??

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.  :-P
>
> 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).

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

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



---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe at lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help at lists.wxwidgets.org



_____________________________________________________________________
The information contained in this message and its attachments is
confidential and proprietary to LAIKA, Inc.  By opening this email
or any of its attachments, you agree to keep all such information
confidential and not to use, distribute, disclose or copy any part
of such information without the prior written consent of LAIKA,
Inc.  If you are not the intended recipient of this message, any use,
distribution, disclosure or copying of such information is prohibited.
If received in error, please contact the sender. 





More information about the wxpython-users mailing list