Archive for the ‘planet-mageia-english’ tag
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!
Back to 2011 I was a GSoC student at Scilab community. My project was to create a backend for Scilab in Cantor, the KDE mathematical software. My project ended very well and the objectives were accomplished. You can see several features of this project in reports from my blog.
The backend would be working with Scilab 5.4 because I implemented the standard streams support in Scilab. The backend was available in KDE 4.8, released in January 2012, but Scilab 5.4 was released in October 2012. Unfortunately, when this version of Scilab was released, the standard streams support were not working.
Since this date I tried some times fix it but I did not obtained success.
Therefore, Scilab release a 5.5-beta1 version in begin of this October and I did a test with Cantor and… voilá! The standard streams is working now and the Cantor backend is working too!
Now it is time to Scilab backend for Cantor revive! I am doing “nightly-builds” of Scilab to verify if the standard streams are working and I developed new features to the backend. Let me show them:
Predefined functions and variables
In the past Scilab backend had a giant-size XML file listing all predefined functions and variables. Now the backend run getscilabkeywords command to get this information, used in tab-complete and syntax highlighting.
Tab-Complete and Syntax Highlighting
These features were available in previous version of the backend to predefined functions and variables. Now user variables are too used in these features.
Tab-complete for predefined functions
Variable Management Panel
Scilab backend now have a preliminary variable management panel. All variable defined by user are showed in this panel.
With this feature the user can save and load variables, and clean the variable environment.
But it is a preliminary version based in Octave variable management: the user must define the variable presenting it (you can not use “;”). So the label and value will be send to panel.
Scilab backend reviving in KDE 4.12
I am working for this new version of Scilab backend in KDE 4.12.
But you can test it now: the code is hosted in scilab-backend branch from Cantor repository.
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.
In previous post, I mentioned about dynamic keywords in python backend. The idea is, after import a python module in Cantor workspace, functions, keywords, variables, and more from this module are load by Cantor and available to syntax highlighting and tab complete.
This feature is implemented for now. You can test it compiling Cantor from python-backend branch.
But, let me show more information about this feature.
There are several ways to import a python module in python console. You have “import modulename”, “import modulename as modulevariable”, “from modulename import *”, “from modulename import function_1, function_2, …”, and more. Each import way causes different consequences to user experience.
The four import ways mentioned in previous paragraph are supported by python backend. I will show these different import ways and how python backend behave for each one.
The more basic import way. After this command, a variable named “modulename” is defined and the functions and more keywords of this module are available to access using “modulename.keyword”.
import modulename as modulevariable
This way the user define a name “modulevariable” to reference “modulename”, and “modulename” is not defined. So, you can access the functions and more from “modulename” using “modulevariable.keyword”.
from modulename import *
This way the user import all functions and keywords from “modulename” but anything variable is defined to access “modulename”. The functions of the module are accessed directly.
from modulename import function_1, function_2, …
The user import only specific functions from a “modulename”, no all functions.
I developed a Cantor plugin to import modules. This plugin open a dialog to user enter a modulename and, after press Ok, Cantor run “import modulename” and keywords are available. The diaglog is accessible by “Packaging” menu, in toolbar.
The backend can identify several errors during import.
Well, the feature is working and it is mature for use, however it don’t support all import ways in python. But, I think these five ways cover the most commons import ways used by most python scientific users.
The important thing is, this feature enable python backend to support the several python modules, and no only scipy, numpy, and matplotlib, as I proposed in begin of this project.
Let me know how you import a module in python. I will develop support to more import ways in future versions of the backend.
For now, wait for more news of this project soon!