{"id":779,"date":"2012-05-02T18:46:09","date_gmt":"2012-05-02T18:46:09","guid":{"rendered":"http:\/\/blog.filipesaraiva.info\/?p=779"},"modified":"2012-05-02T18:48:24","modified_gmt":"2012-05-02T18:48:24","slug":"lakademy-results-starting-development-of-python-backend-to-cantor","status":"publish","type":"post","link":"https:\/\/filipe.saraiva.tec.br\/blog\/?p=779","title":{"rendered":"LaKademy results &#8211; starting development of Python backend to Cantor"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2012\/05\/filipesaraiva-20120429T201446-e4aslw9.png\" alt=\"\" width=\"693\" height=\"399\" \/><\/p>\n<p style=\"text-align: justify;\"><em><em><a href=\"http:\/\/blog.filipesaraiva.info\/?p=756\" target=\"_blank\">LaKademy<\/a><\/em> is over and I will report about the event in several themed posts. This is about I developed during the Latin American meeting of KDE developers. More posts in <em><a href=\"http:\/\/blog.filipesaraiva.info\/?tag=lakademy\" target=\"_blank\">LaKademy tag<\/a>.<\/em><br \/>\n<\/em><\/p>\n<p style=\"text-align: justify;\">In this year I submitted a proposal to Google Summer of Code to develop a <a href=\"http:\/\/python.org\/\" target=\"_blank\">Python<\/a> backend for scientific programming in\u00a0<a href=\"http:\/\/edu.kde.org\/cantor\/\" target=\"_blank\">Cantor<\/a>. In the last year, I developed a\u00a0<a href=\"http:\/\/scilab.org\/\" target=\"_blank\">Scilab<\/a> backend. Unfortunately my proposal was not accepted.<\/p>\n<p style=\"text-align: justify;\">But that&#8217;s okay, life goes on. This does not discourage me to begin the project.<\/p>\n<p style=\"text-align: justify;\">During the LaKademy, I put as a goal to make communication between Cantor and Python. My first idea was to make a fork of\u00a0<a href=\"http:\/\/www.sagemath.org\/\" target=\"_blank\">Sage<\/a> backend, which is also a technology based in Python. But in the evaluation phase of proposal for Google Summer of Code, the Cantor main developer, Alex Rieder, suggested to me take a look in <a href=\"http:\/\/docs.python.org\/c-api\/index.html\" target=\"_blank\">Python\/C API<\/a>.<\/p>\n<p style=\"text-align: justify;\">I began studying this API and other resources on the web (like <a href=\"http:\/\/elmer.sourceforge.net\/PyCon04\/elmer_pycon04.html\" target=\"_blank\">this one<\/a>, based on <a href=\"http:\/\/elmer.sourceforge.net\/\" target=\"_blank\">Elmer<\/a>). I realized that send Python commands from C\/C++ code would be easy, however, capture the output of the Python interpreter would be the real challenge. All this communication could be simple if Python would use\u00a0<a href=\"http:\/\/en.wikipedia.org\/wiki\/Standard_streams\" target=\"_blank\">standard streams<\/a> by default, which would allow to use <a href=\"http:\/\/api.kde.org\/4.x-api\/kdelibs-apidocs\/kdecore\/html\/classKProcess.html\" target=\"_blank\">kprocess<\/a>. Scilab didn&#8217;t support, but I implemented this support and it allowed the use of kprocess approach. However, in Python I could not do that &#8211; or would be harder to do it.<\/p>\n<p style=\"text-align: justify;\">After searches in internet and some studies, I implemented a Python class that redirects messages from the Python interpreter, both conventional outputs and error messages, to a variable that can later be retrieved in a string type by Python\/C API. <em>Voil\u00e0<\/em>!<\/p>\n<p style=\"text-align: justify;\">Using this recovered variable, I can say that the core of Python backend for Cantor is working and ready to implement more features. Let see some screenshots:<\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2012\/05\/filipesaraiva-20120429T201506-9ttjgmu1.png\" alt=\"\" width=\"656\" height=\"356\" \/><\/p>\n<p style=\"text-align: center;\"><em>Computation of a simple counter in Python<\/em><\/p>\n<p style=\"text-align: center;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2012\/05\/filipesaraiva-20120501T151658-jqv8wng.png\" alt=\"\" width=\"656\" height=\"356\" \/><\/p>\n<p style=\"text-align: center;\"><em>Cantor + Python + matplotlib in a external plot<br \/>\n<\/em><\/p>\n<p style=\"text-align: center;\"><em><\/em><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2012\/05\/filipesaraiva-20120501T151912-8bxdw4n2.png\" alt=\"\" width=\"656\" height=\"356\" \/><em>Python error message in Cantor<\/em><\/p>\n<p style=\"text-align: justify;\">From this implemented part, the new features that will be added: append plot figure in Cantor workspace, syntax highlighting, auto-complete pre-defined functions, and more. I intend to support in particular for libraries\u00a0<a href=\"http:\/\/numpy.scipy.org\/\" target=\"_blank\">numpy<\/a>, <a href=\"http:\/\/scipy.org\/\" target=\"_blank\">scipy<\/a> and <a href=\"http:\/\/matplotlib.sourceforge.net\/\" target=\"_blank\">matplotlib<\/a>, which when added to Python make it an interesting tool for scientific programming, like others we have in the free world as\u00a0<a href=\"http:\/\/www.gnu.org\/software\/octave\/\" target=\"_blank\">GNU Octave<\/a>, Scilab, <a href=\"http:\/\/maxima.sourceforge.net\/\" target=\"_blank\">Maxima<\/a>, Sage.<\/p>\n<p style=\"text-align: justify;\">The code is avaiable in <a href=\"https:\/\/projects.kde.org\/projects\/kde\/kdeedu\/cantor\/repository\/show?rev=python-backend\" target=\"_blank\">python-backend branch<\/a> of <a href=\"https:\/\/projects.kde.org\/projects\/kde\/kdeedu\/cantor\/repository\/\" target=\"_blank\">Cantor repository<\/a>. But remember: it is a experimental version, and the main fatures will be develop yet. Only communication between C++ &lt;-&gt; Python, the core of application, is working for now.<\/p>\n<p style=\"text-align: justify;\">Watch this blog (or follow <a href=\"http:\/\/blog.filipesaraiva.info\/?tag=python-backend\" target=\"_blank\">python-backend tag<\/a>) for more informations about this project. \ud83d\ude09<\/p>\n<p style=\"text-align: justify;\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter\" src=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2012\/04\/logo-camisa-01_wee.jpg\" alt=\"\" width=\"510\" height=\"360\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>LaKademy is over and I will report about the event in several themed posts. This is about I developed during the Latin American meeting of KDE developers. More posts in LaKademy tag. In this year I submitted a proposal to Google Summer of Code to develop a Python backend for scientific programming in\u00a0Cantor. In the&hellip;&nbsp;<a href=\"https:\/\/filipe.saraiva.tec.br\/blog\/?p=779\" class=\"\" rel=\"bookmark\">Continue a ler &raquo;<span class=\"screen-reader-text\">LaKademy results &#8211; starting development of Python backend to Cantor<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[23,9],"tags":[58,25,48,11,7,26,79,51,41,52,80],"class_list":["post-779","post","type-post","status-publish","format-standard","hentry","category-pessoal","category-software-livre","tag-cantor","tag-ciencia-da-computacao","tag-comunidade","tag-desenvolvimento","tag-eventos","tag-kde","tag-lakademy","tag-planet-mageia-english","tag-planeta-psl-pi","tag-planetkde-english","tag-python-backend"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1p2Jh-cz","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=\/wp\/v2\/posts\/779","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=779"}],"version-history":[{"count":3,"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=\/wp\/v2\/posts\/779\/revisions"}],"predecessor-version":[{"id":785,"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=\/wp\/v2\/posts\/779\/revisions\/785"}],"wp:attachment":[{"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=779"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=779"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=779"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}