[IPython-dev] Ipython plugin for Editra

Laurent Dufréchou laurent.dufrechou at gmail.com
Sun Mar 1 07:35:44 EST 2009


Hey quite interesting !

I’ve seen you get directly access to ipython directly inside the plugin, quite good!

 

To execute lines of code, it is currently done like this in ipython_view.py:

 

User push enter ->

#------------------------ Key Handler ------------------------------------

    def keyPress(self, event):

if event.KeyCode == wx.WXK_RETURN:

            if self.cur_state == 'IDLE':

                #we change the state ot the state machine

                self.setCurrentState('DO_EXECUTE_LINE')

                self.stateDoExecuteLine()

                return

 

def stateDoExecuteLine(self):

        lines=self.text_ctrl.getCurrentLine()

        self.text_ctrl.write('\n')

        lines_to_execute = lines.replace('\t',' '*4)

        lines_to_execute = lines_to_execute.replace('\r','')

        self.IP.doExecute(lines_to_execute.encode(ENCODING))

        self.updateHistoryTracker(lines)

        self.setCurrentState('WAIT_END_OF_EXECUTION')

 

So the hackish way to do you what you’re trying to do is: (self was self._ipanel for your plugin)

Set self._ipanel.setCurrentState('DO_EXECUTE_LINE'), this is necessary because there is s state machine, and depending what the gui is doing key event and behavior change.

This is usefull when displaying help for example where display and keys are handled differently.

 

       Then do:

        nb = self._mw.GetNotebook()

        current = nb.GetCurrentCtrl()

 

        Lines_to_execute = current.GetSelectedText()

        lines_to_execute = lines.replace('\t',' '*4)

        lines_to_execute = lines_to_execute.replace('\r','')

        self._ipanel.IP.doExecute(lines_to_execute.encode(ENCODING))

        self._ipanel.updateHistoryTracker(lines)

        self._ipanel.setCurrentState('WAIT_END_OF_EXECUTION')

 

the best way should be to have a method to allow execution of an external string buffer.

If the method that I tell you works, I will change the method  to something like def stateDoExecuteLine(self, string).

 

Will resintall my plugin dev env of editra. Hope I can have some time today, but not sure… I forgot I got something urgent to do before … J

 

Laurent

 

De : Ronen Abravanel [mailto:ronena at gmail.com] 
Envoyé : dimanche 1 mars 2009 11:11
À : Laurent Dufréchou
Cc : ipython-dev at scipy.org
Objet : Re: [IPython-dev] Ipython plugin for Editra

 

Hi Laurent,

My hack attached.
It is mostly defined at "ShellIntegrator" class at the end of the file.

The work flow I want to achieve is as  following:
* in Ipython - "%edit myfile.py" or "edit 1:5" etc. Open editing buffer within the current windows, and returns without running the file.
* Selectin "Run" from the tool menu in Editra run the buffer, as it was sopused to run after closing the editor.

By the way, the plugin have some series stabilty issues. 
calling '%run filename.py' for none trevial python file is cusing editra crash with:
python2.5: ../../src/xcb_lock.c:77: _XGetXCBBuffer: Assertion `((int) ((xcb_req) - (dpy->request)) >= 0)' failed.
Aborted


Thanks, 
Ronen

On Sun, Mar 1, 2009 at 3:33 AM, Laurent Dufréchou <laurent.dufrechou at gmail.com> wrote:

Hi Ronen,

 

Happy to see you’ve tried to hack the editra plugin ;)

 

IPyShell/__init__.py contains only the interface with editra. 

I do not cleanly understand the step your are trying to do. You’ve used ” %ed” than it launched editra new source panel? And closing it executed your code, but stdin/out goes outside ipython shell?

Is that what you tried?

 

About the files to modify. __init__.py in editra plugn is the definition of the plugin interface and how you interact with editra.

Ipython dir is a pure copy that I was used to upload from time to time. I have to take a look at some updates that cody did. (some compatibility issue with python 2.6 and ipython tree)

The fact is that the update you’re currently trying to di will surely need some update into /gui/wx I think L. But well we’ll see.

Depending on what you’ll want to do we will perhaps expose some methods so plugin will be able to configure the things you need. (ex being able to define an editor)

(I think we can use ipython config file but I’ve never used them since then so…)

 

I will try to upload updated sources for python tree tomorrow, so you’ll have a bleeding edge wx integration. I’ve corrected some bugs since then.

Sure we will find a way to workaround the stdin/out issue you saw.

 

Send me your current hack, I’ll take a look at your issue.

 

Cheers,

Laurent

 

De : ipython-dev-bounces at scipy.org [mailto:ipython-dev-bounces at scipy.org] De la part de Ronen Abravanel
Envoyé : samedi 28 février 2009 22:53
À : ipython-dev at scipy.org
Objet : [IPython-dev] Ipython plugin for Editra

 

Editra, an extensible programmer's editor written in wxPython, contain a cool IPython plugin. This mail is a follow up for a discussion with Laurent , The author of the plugin, in his blog, continue here according to his request. The Orginal discassion can be found in http://ipython0.wordpress.com/2008/04/25/editra-ipython-plugin-under-work/ or at the end of this mail.


Using papi to set\redefine IPython's magic word partly do the job, The other part is to execute some arbitrary python code inside The ipython shell. Invoking papis "ex" method (Using papi from ipython_panel.IP._IP.getapi() ) let the Code run in IPython's context, but the output is printed to Editra's stdout (The console in wich I invoked editra's from) and not in the IPython in the shelf.  My attempts to set sys.stdout to an handler from, let say, _term.cout or others, cused IPython to stack. futher more, the Exeption throws while I call ip.ex, is cought within Editra and withn IPython.

Further more - I wish to change, If I can, Only IPyShell/__init__.py and not the stuff in "IPython" dir, as it seems as a "pure" copy of IPython's orginal source (is it?)


Thanks,
Ronen.


--------------------------------------
The orginal discassion:

1.	Ronen Says: 
February 21, 2009 at 8:18 pm <http://ipython0.wordpress.com/2008/04/25/editra-ipython-plugin-under-work/#comment-25>  

That’s a one cool Plugin.

What will make it ideal, is better integration with Editra’s Editor:
Make ipython’s %edit Open the edit-buffer in Editra’s current Windows, and Enable poeple to run The code they edit in Editra inside the open IPython windows…
Any hint where should I try to hack in order to achieve those? 

Thanks,
Ronen.

2.	Erreur ! Nom du fichier non spécifié.Laurent Says: 
February 22, 2009 at 10:45 am <http://ipython0.wordpress.com/2008/04/25/editra-ipython-plugin-under-work/#comment-26>  

Hello,
You can have access to the plugin repos:

# Non-members may check out a read-only working copy anonymously over HTTP.
svn checkout http://editra-plugins.googlecode.com/svn/trunk/ editra-plugins-read-only 

The plugin name is ipyshell, in it’s directory you’ve got the whole ipython source + the plugin source.

It need a little refresh for sure Erreur ! Nom du fichier non spécifié..

If you want to try to hack it take a look @Ipython/gui/wx the whole code is in ipython_view and ipshellnonblocking.

ipython_view -> gui interface
ipshellnonblocking -> the interface with ipython

You can add:
ip = IPython.ipapi.get()
def myEdit(self, arg):
print ‘do what you want’
ip.expose_magic(’edit’, myEdit)

to WxNonBlockingIPShell inside ipython_view.py

Please note that if ipython is ever installed on your system you’ll have to make a eggsetup.py develop to make sure to use your new local copy.

We can discuss about all of this in ipython-dev mailing list Erreur ! Nom du fichier non spécifié.

Cheers,
Laurent

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ipython-dev/attachments/20090301/0ad500f3/attachment.html>


More information about the IPython-dev mailing list