[wxPython-users] Calling parent functions from an embedded
pyShell??
Patrick K. O'Brien
pobrien at orbtech.com
Wed Nov 14 14:31:57 PST 2007
On Nov 14, 2007, at 4:24 PM, Patrick K. O'Brien wrote:
> On Nov 14, 2007, at 1:53 PM, Chris Mellon wrote:
>
>> On Nov 14, 2007 1:16 PM, Patrick Van Pelt <patrick at 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)
>>>
>>
>> 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.
>
> You could also subscribe to interpreter.push events via the
> dispatcher. It should be pretty easy to figure out how by looking
> at the source for the Dispatcher tab in PyCrust.
This is the relevant bit of code that you could add to some class of
yours:
from wx.py import dispatcher
dispatcher.connect(receiver=self.push, signal='Interpreter.push')
def push(self, command, more):
"""Receiver for Interpreter.push signal."""
# Do something with the command string...
Hope that helps,
Pat
--
Patrick K. O'Brien
Orbtech http://www.orbtech.com
Schevo http://www.schevo.org
More information about the wxpython-users
mailing list