Archive for the ‘planet-python’ tag
I have some posts to write about Cantor but first I would like to request a help to KDE packagers of several Linux distros around the world.
I received some mails from users asking “how can I use python in Cantor?” or “where is python support in Cantor?”. Well, python2-backend is available in Cantor since KDE 4.12 release. If you is using KDE >= 4.12 but you can not to use python in Cantor, maybe the package was not build correctly.
python 2 development library (commonly packed as python-devel in some Linux distros) is required to build python2-backend. python 2 is required to use Cantor with python 2.
Then if you are a Cantor user and can not to use Cantor with python, please write a bug report in the bug management system of your distro. You can to put a link in the bug report to this post too.
Anyway, if your distro bring or not bring python2-backend, write a comment below and I will make a table with this information.
A small blogpost about Cantor before Brazilian Carnival parties.
KDE 4.13 is feature freeze now and I developed some improvements in Cantor’s script editor. It will be available in next KDE stable release around April 16.
Now Python 2 and Scilab backends have support to script editor! See some pictures:
You can access script editor in menu bar View -> Show Script Editor. The script editor is based in kate-part, so you have syntax highlighting, line numbering, mini-map, and all cool stuffs from Kate. You have a Run Script button too, so you can just push this button and the script will be load in Cantor worksheet, as you can see in examples.
There is news for others Cantor backends too. Now script editor load default syntax highlighting for each backend – in old versions it did not happen. And, if you push New button, the new script editor will have the default syntax highlighting working too.
It is the news about my work in Cantor for KDE 4.13. I intent improve Python 2 backend and script editor for future releases.
But now it is time to go to Brazilian street parties! Happy Carnival! ;)
Cantor is a mathematical/scientific programming software, a frontend providing IDE features (syntax highlighting, tab-complete, variables management, and more) and a advanced terminal. Cantor support a lot of mathematical engines like Octave, Sage, Maxima, Kalgebra, Qualculate, R, Scilab (developed by me too), and now, Python 2. You can see Cantor as a Matlab-like software, but it uses other mathematical environment/software as programming language.
This post I will do a “feature tour” in Python 2 backend to show Cantor software for scientific python developers community.
Initial Screen – Syntax Highlighting and Tab Complete
After select the Python 2 backend, Cantor will show the initial screen. This window have a big widget for the Python 2 terminal, and two side panels – one to show the Python 2 help and the other to variables management.
Let’s see some commands inputs in the terminal:
Cantor is highlighting the Python 2 syntax and, in side panel, you can see the variables created.
Now, let’s create new variables with similar names to test the tab complete. See the picture below:
After create variables variable_x, variable_y e variable_var, we can write in terminal var and type tab key twice – Cantor will show the variables and functions with the same piece of word. Tab complete is available for module functions too.
Cantor show error messages in terminal too. Next figure show a import error:
You can save the terminal state or just the input commands and their outputs in a file. Cantor allows upload/download a terminal example for a remote server. You can explore this features in “File” menu.
Cantor shows Python help from help command in a side panel. The picture below shows the help for complex class:
Cantor uses Qt/KDE technologies, so you can change the window format moving the side panels. Next picture show the window with the variables management in the left side and the help panel in the right side.
Variables management panel shows the variables created in Cantor session, showing their labels and values. The panel have some additional functions too, in buttons bottom the widget. These functions are, from left to right, Add variable, Load variables, Save variables, and Clear all variables.
Add variable just open a pop-up window to input a label and a value to a variable.
Load variables and Save variables uses shelve module to data persistence. When the buttons are clicked, Cantor loads scripts to, in first case, read and load variables to the session, and, in second case, save the python dictionary in a file. The figures below show this operations:
The function Clear all variables delete each variable from Python dictionary. The code is below:
The figures below show the graphic loaded in Cantor worksheet. When a session is exported, the graphic will be exported too. This feature can be configured to create the graphics in a new window – this is the default option.
Conclusion and Future
This is the first stable version of Python 2 support in Cantor. It is working good, but you can see the bug presence in some parts of software.
I would like to see some feedbacks from mathematical/scientific programming python community. I am not a “pythonist”, so the python community can find bugs and strange behaviours in the software better than me. I would like to see some feature suggestions too.
For the next version, Python 2 backend will have support to script editor – unfortunately, I can not develop it for this release.
If you are interested in the backend development, my blog have a set of posts (in Portuguese and English) about it. You can download the source code in Cantor repository – the license is GPLv2. And you can submit a bug report in KDE bugzilla.
And you can contact me in comments area below or in my mail address filipe at kde.org.
Hello Python community,
My name is Filipe Saraiva, I am not a python developer (I am a novice in python), but I am a C++ and KDE developer.
I would like to see some feedbacks from scientific python community about improves in this backend. I intent to develop a Python 3 and a iPython backend too in the future.
I will write a “tour post” about the Python 2 backend features soon, but you can see posts about the backend development in the tag python-backend (posts in English and Brazilian Portuguese).
A fast update: now Cantor backends for Python2 and Scilab were merged in master branch. I will do more polishing until the stable release in KDE 4.12. You can follow the new status of development compiling and testing Cantor from master branch.
In a related topic, KDE Edu sprint in A Coruña, Spain, began and runs through the October 30th. Unfortunately I can not participate this time but I expect go to the next meeting (maybe, in Akademy 2014). =)
Have a good work, edu-gearheads!
Other feature implemented in python backend for Cantor in last weeks was “append plot image to Cantor Workspace”.
In other backends you can, optionally, generate a plot image and this image will be append in Cantor workspace, not generating a separated window to the picture.
Below we have a command to generate a plot image in python using matplotlib and pyplot:
Now we have the result appended in Cantor workspace:
In python, to save a picture using pyplot, we type the command pyplot.savefig(). But, if a picture was saved, it can not be shown in separated window. Otherwise, if a picture is shown in a separated window, it can not be saved to a file.
To solve this problem, the python backend change the show() command to savefig(), with a random name to the picture. The image is saved in a temporary file and loaded in Cantor workspace.
The option to load figure in Cantor workspace or to use a separated window is configured in python backend configuration screen. The default is to use separated window because matplotlib/pyplot have several additional features in image screen.
I would like to see some feedback from you, in special if you are a python developer. The code is hosted in python-backend branch from Cantor repository.
In last weeks I developed some new features to python backend for Cantor. In this post I will write about two of their: the help and the variable management, implemented as panels.
Help Panel on left; Variable Management Panel on right
Help panel shows the help output in a separated panel, facilitating the consult of this information. To use it, simply use help command as in python interactive mode, as in example below:
Below a bigger help output, from a python module:
In previous picture, did you see some change in variable management panel?
Variable Management panel
Variable management panel is a great feature provide by Cantor, but until now just Octave backend had it. This feature show the variables defined in the session, their values, and allow some interesting functions to manipulate these variables.
You can define a lot of variables in python session and these variables will be shown in the panel. See:
In previous picture, I defined a integer variables x and y, a string a, and two modules: numpy and scipy, this last as sc. All this values are shown in panel.
Now I will change some values defined previously and will add some others:
See, now I defined a variable aa by the concatenation of two a‘s; the value of a is now aa; div is the division of y by x. I have a 2-dimensional matrix mtr defined by matrix function from numpy module; a python class HelloWorldClass and a object hello.
I can change the value of some these variable manipulating their values in the panel. For example, I can rewrite the x variable from 35 to 350, clicking in value column and typing 350.
But the more interesting features are provide by the buttons bellow this panel. These buttons load python scripts to run some feature. There are: add variable, load variables from a file, save variables to a file and clear all variables in the session.
Add variable is quite simple: a dialog is open and you type the variable and their value:
Save/Load use shelve module to save and load the variables of the session. But, it is important to say, this feature don’t save all the variables because shelve module have some limitations. For example, I saved this session to a file named “python_session.txt”. The python code loaded is:
After save, I will clear the session. The python code loaded is:
It is working now but I need some more tests, in special the save/load python objects defined by user and modules.
I would like to see some feedback from you. The code is hosted in python-backend branch from Cantor repository, so you can test it.