[IPython-dev] pyreadline (Hey cocoa/QT/wx ipython GUI what do you think about this?)

Laurent Dufréchou laurent.dufrechou at gmail.com
Wed Mar 26 20:34:39 EDT 2008


Hi gaël,

>OK, but how to you choose how a key must behave? You need one single
>object that knows the configuration of keys (is pageup history, or
>nothing?), and what if I want to switch to VI mode, you don't want to
>implement this in all the frontends.

When you use a widget, like scintilla one that I used, all the classical key
where already handled by the text widget itself. I add to overload some to
better match ipython shell behavior. Like pushing 'up', does not go up but
call history back.
So if you want VI mode , just design your ipython widget around a VI aware
text widget, that's all... 

>Sending a string defeats the goal of readline: readline is what
>translates keystrokes to a command string. Readline knows that if I use
>"ctr-left", it should jump the cursor one word to the left. Yes, it is
>not easy, but that's what readline is about, IMHO.

Ok I've deleted the beginning of my email:
In fact the problem can be solved 'easily'.
For WX the widget developer will ahev something like this:

Class MyTextAreaWidget(object):

    def __init__(self):
	  ...
        Self.readline = Readline(ipython_instance)
        ...
	  self.readline.MoveCursorLeft = self.MoveCursorLeft
        self.readline.GotoStartOfLine = self.MoveToPrompt
#------------------------ Key Handler ------------------------------------
    def keyPress(self, event):
        '''
        Key press callback with plenty of shell goodness, like history,
        autocompletions, etc.
        '''
        
	  #readline shortcircuit
        if event.GetKeyCode() == ord('C'):
     		if event.Modifiers == wx.MOD_CONTROL:
                #we raise an exception inside the IPython thread container
                self.IP.ce.raise_exc(KeyboardInterrupt)
                return
	  #readline key handling
	  self.readline.ProcessKey(event.GetKeycode())
	  
        #post key processing
	  if (self.readline.has_processed_key == False):
		 self.postProcessKey()

Developer must have the possibility to let or not readline to handle the
keys.
If he don't want to use readline key handling, he must have access to
function that can make ipython execute a string, and that should be ok.

Am I clear in my explanation? Readline only process key but does not manage
widget directly. User will to hook it's widget function to readline one.
With this approach I'm OK. So we will be able to use a text area renderer, a
scintilla renderer or even an html renderer...
This will not be a problem for readline, has it will only redirect key event
to good widget functions via a unified interface.

Laurent




More information about the IPython-dev mailing list