Filipe Saraiva's blog

Tecnologia, sociedade e política.

Python backend for Cantor – Syntax Highlighting, Tab Complete, and Interactive Mode

with 11 comments

My GSoC’2013 project for development a python backend for Cantor reach some objectives in before weeks.

Firstly I developed preliminary versions of syntax highlighting and tab complete features. This version use XML file processing to provide a basic set of keywords and built-in functions to these features. To activate tab complete, press Tab button after some letter.  You can see some screenshots of these features below (click mouse right-button and enlarge it):


A simple syntax highlighting


More syntax highlighting and tab complete

Next, the preliminary version  of the backend developed during LaKademy was build to support python script mode. But it would be more interesting to support python interactive mode in Cantor console. So, to do it, I implemented preprocessing in python command before send it to python interpreter, adding some commands to simulate python interactive mode.

This solution use PyRun_SimpleString from python/C API to process python commands in python script mode. There is other functions from python/C API to process python commands in interactive mode, for example, PyRun_InteractiveOne, but this function requires the python commands in a file to process and the output of commands is a bit of hard to get. So, for now, PyRun_SimpleString + preprocessing commands is working very well.

You can see in screenshots below and above that variable values and operation values are show in Cantor console without use of print command. It is a one of characteristic of python interactive mode:

python_backend_aninhado1More examples of syntax highlighting and python interactive mode


More examples of syntax highlighting and python interactive mode

Now I am developing a feature to list all functions and keywords from a specific python module imported during the program execution. I am using dir command to do it. This feature will provide these keywords to use in syntax highlighting and tab complete in a dynamic way. Then, python backend will support any python module, and not scipy, numpy, and matplotlib only.

Python backend is available in python-backend branch in Cantor repository. You can test it, but remember this code is not stable and finalized for now.

11 Responses to “Python backend for Cantor – Syntax Highlighting, Tab Complete, and Interactive Mode”

  1. ZeD disse:

    I think there are problems with the images

    • Filipe Saraiva disse:

      Thanks ZeD. The plugin to copy images from URL to my server don’t worked this time, but I updated the post to fix it. =)

  2. ZeD disse:

    Cool 🙂

    I know it’s a totally different stack of technologies, and it’s like a orange-to-apple comparison, but it reminds me of
    Do you plan something like that? Or maybe some integration?

    • TheBlackCat disse:

      Yes, I mentioned that in his previous blog post on this topic. iPython already has a Qt backend, support for HTML notebooks, multiple simultaneous notebooks, built-in pretty-printing and syntax highlighting, and what looks to be a pretty large API.

    • Filipe Saraiva disse:

      Hi Zed and TheBlackCat. TheBlackCat mentioned about iPython in previous blogpost. I read about iPython, it is wonderful project, but it delivery some additional and interesting features. However, my project aims develop a “more pure python” backend.

      I think will be more interesting develop a specific iPython backend to use these additional features.

      Well, I will think about create a iPython backend after this GSoC. =)

  3. […] Python backend for Cantor – Syntax Highlighting, Tab Complete, and Interactive Mode […]

  4. The User disse:

    Will these features also be available in the Sage backend?

    • Filipe Saraiva disse:

      I can not test sage backend now, but these features are available in currently version of sage backend (in fact, these features are available since sage backend release).

  5. The User disse:

    Couldn’t the Sage and the Python backend share the same code for completion etc.?

    • Filipe Saraiva disse:

      Yes, parts of code in Sage and Python backends are similar. Maybe, dynamic keywords developed to Python backend can be used in Sage backend too.

  6. […] previous post, I mentioned about dynamic keywords in python backend. The idea is, after import a python module in […]

Leave a Reply