{"id":1086,"date":"2013-07-26T15:58:49","date_gmt":"2013-07-26T15:58:49","guid":{"rendered":"http:\/\/blog.filipesaraiva.info\/?p=1086"},"modified":"2013-12-28T17:21:34","modified_gmt":"2013-12-28T17:21:34","slug":"python-backend-for-cantor-syntax-highlighting-tab-complete-and-interactive-mode","status":"publish","type":"post","link":"https:\/\/filipe.saraiva.tec.br\/blog\/?p=1086","title":{"rendered":"Python backend for Cantor &#8211; Syntax Highlighting, Tab Complete, and Interactive Mode"},"content":{"rendered":"<p style=\"text-align: justify;\">My GSoC&#8217;2013 project for <a href=\"http:\/\/blog.filipesaraiva.info\/?p=1083\" target=\"_blank\">development a python backend<\/a> for <a href=\"http:\/\/edu.kde.org\/cantor\/\" target=\"_blank\">Cantor<\/a> reach some objectives in before weeks.<\/p>\n<p style=\"text-align: justify;\">Firstly I developed preliminary versions of syntax highlighting and tab complete features. This version use XML file processing to provide a basic set of <a href=\"http:\/\/docs.python.org\/2\/reference\/lexical_analysis.html#keywords\" target=\"_blank\">keywords<\/a> and <a href=\"http:\/\/docs.python.org\/2\/library\/functions.html\" target=\"_blank\">built-in functions<\/a> to these features. To activate tab complete, press Tab button after some letter.\u00a0 You can see some screenshots of these features below (click mouse right-button and enlarge it):<\/p>\n<p><a href=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2013\/07\/python_syntax_highlighting.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1087\" data-permalink=\"https:\/\/filipe.saraiva.tec.br\/blog\/?attachment_id=1087\" data-orig-file=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_syntax_highlighting.png\" data-orig-size=\"1366,737\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"python_syntax_highlighting\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_syntax_highlighting-300x161.png\" data-large-file=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_syntax_highlighting-1024x552.png\" class=\"aligncenter size-large wp-image-1087\" alt=\"python_syntax_highlighting\" src=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2013\/07\/python_syntax_highlighting-1024x552.png\" width=\"698\" height=\"375\" srcset=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_syntax_highlighting-1024x552.png 1024w, https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_syntax_highlighting-300x161.png 300w\" sizes=\"auto, (max-width: 698px) 100vw, 698px\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>A simple syntax highlighting<\/em><\/p>\n<p style=\"text-align: center;\"><a href=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2013\/07\/python_backend.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1088\" data-permalink=\"https:\/\/filipe.saraiva.tec.br\/blog\/?attachment_id=1088\" data-orig-file=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend.png\" data-orig-size=\"1366,768\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"python_backend\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend-300x168.png\" data-large-file=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend-1024x575.png\" class=\"aligncenter size-large wp-image-1088\" alt=\"python_backend\" src=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2013\/07\/python_backend-1024x575.png\" width=\"698\" height=\"375\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>More syntax highlighting and tab complete<\/em><\/p>\n<p style=\"text-align: justify;\">Next, the\u00a0<a href=\"http:\/\/blog.filipesaraiva.info\/?p=779\" target=\"_blank\">preliminary version\u00a0 of the backend developed during LaKademy<\/a> was build to support <a href=\"http:\/\/docs.python.org\/2\/tutorial\/interpreter.html#using-the-python-interpreter\" target=\"_blank\">python script mode<\/a>. But it would be more interesting to support <a href=\"http:\/\/docs.python.org\/2\/tutorial\/interpreter.html#interactive-mode\" target=\"_blank\">python interactive mode<\/a> 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.<\/p>\n<p style=\"text-align: justify;\">This solution use <a href=\"http:\/\/docs.python.org\/2\/c-api\/veryhigh.html#PyRun_SimpleString\" target=\"_blank\">PyRun_SimpleString<\/a> from <a href=\"http:\/\/docs.python.org\/2\/c-api\/\" target=\"_blank\">python\/C API<\/a> 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, <a href=\"http:\/\/docs.python.org\/2\/c-api\/veryhigh.html#PyRun_InteractiveOne\" target=\"_blank\">PyRun_InteractiveOne<\/a>, 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.<\/p>\n<p style=\"text-align: justify;\">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:<\/p>\n<p style=\"text-align: center;\"><em><a href=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2013\/07\/python_backend_aninhado1.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1089\" data-permalink=\"https:\/\/filipe.saraiva.tec.br\/blog\/?attachment_id=1089\" data-orig-file=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend_aninhado1.png\" data-orig-size=\"1366,737\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"python_backend_aninhado1\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend_aninhado1-300x161.png\" data-large-file=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend_aninhado1-1024x552.png\" class=\"aligncenter size-large wp-image-1089\" alt=\"python_backend_aninhado1\" src=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2013\/07\/python_backend_aninhado1-1024x552.png\" width=\"698\" height=\"375\" srcset=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend_aninhado1-1024x552.png 1024w, https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend_aninhado1-300x161.png 300w\" sizes=\"auto, (max-width: 698px) 100vw, 698px\" \/><\/a><em>More examples of syntax highlighting and python interact<\/em>ive mode<\/em><\/p>\n<p><a href=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2013\/07\/python_backend_aninhado2.png\"><img loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1090\" data-permalink=\"https:\/\/filipe.saraiva.tec.br\/blog\/?attachment_id=1090\" data-orig-file=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend_aninhado2.png\" data-orig-size=\"1366,737\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;}\" data-image-title=\"python_backend_aninhado2\" data-image-description=\"\" data-image-caption=\"\" data-medium-file=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend_aninhado2-300x161.png\" data-large-file=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend_aninhado2-1024x552.png\" class=\"aligncenter size-large wp-image-1090\" alt=\"python_backend_aninhado2\" src=\"http:\/\/blog.filipesaraiva.info\/wp-content\/uploads\/2013\/07\/python_backend_aninhado2-1024x552.png\" width=\"698\" height=\"375\" srcset=\"https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend_aninhado2-1024x552.png 1024w, https:\/\/filipe.saraiva.tec.br\/blog\/wp-content\/uploads\/2013\/07\/python_backend_aninhado2-300x161.png 300w\" sizes=\"auto, (max-width: 698px) 100vw, 698px\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><em>More examples of syntax highlighting and python interactive mode<\/em><\/p>\n<p style=\"text-align: justify;\">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 <a href=\"http:\/\/docs.python.org\/2\/library\/functions.html#dir\" target=\"_blank\">dir<\/a> 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.<\/p>\n<p style=\"text-align: justify;\">Python backend is available in <a href=\"https:\/\/projects.kde.org\/projects\/kde\/kdeedu\/cantor\/repository\/show?rev=python-backend\" target=\"_blank\">python-backend branch in Cantor repository<\/a>. You can test it, but remember this code is not stable and\u00a0finalized for now.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My GSoC&#8217;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&hellip;&nbsp;<a href=\"https:\/\/filipe.saraiva.tec.br\/blog\/?p=1086\" class=\"\" rel=\"bookmark\">Continue a ler &raquo;<span class=\"screen-reader-text\">Python backend for Cantor &#8211; Syntax Highlighting, Tab Complete, and Interactive Mode<\/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":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[9],"tags":[58,48,11,47,101,26,51,109,104,41,52,108,80],"class_list":["post-1086","post","type-post","status-publish","format-standard","hentry","category-software-livre","tag-cantor","tag-comunidade","tag-desenvolvimento","tag-gsoc","tag-gsoc2013-python-backend","tag-kde","tag-planet-mageia-english","tag-planet-python","tag-planet-scipy","tag-planeta-psl-pi","tag-planetkde-english","tag-python","tag-python-backend"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p1p2Jh-hw","jetpack_sharing_enabled":true,"jetpack_likes_enabled":false,"_links":{"self":[{"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1086","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=1086"}],"version-history":[{"count":2,"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1086\/revisions"}],"predecessor-version":[{"id":1149,"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1086\/revisions\/1149"}],"wp:attachment":[{"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1086"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1086"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/filipe.saraiva.tec.br\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1086"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}