Pular para o conteúdo

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

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 comentários em “Python backend for Cantor – Syntax Highlighting, Tab Complete, and Interactive Mode”

    1. 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.

    2. 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. =)

  1. Pingback: Links 27/7/2013: More Android/Linux, Also Coming to TVs Now | Techrights

    1. 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).

    1. 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.

  2. Pingback: Cantor – dynamic keywords in python backend at Filipe Saraiva's blog

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *