diff options
author | Agustin Zubiaga <aguzubiaga97@gmail.com> | 2011-12-17 20:07:48 (GMT) |
---|---|---|
committer | Agustin Zubiaga <aguzubiaga97@gmail.com> | 2011-12-17 20:07:48 (GMT) |
commit | 678210eff0604cd49fecdbfe2cdea4f1e59589af (patch) | |
tree | 2eba7fb16cb6b6a5aa591f750dc60b2e01f28b5f | |
parent | 5f13ea95102b9b8b5e5359f86e70d1d75524c5a7 (diff) |
Add a python console and a button for hide and show the console. Also added a module view_changes but is inactive
Signed-off-by: Agustin Zubiaga <aguzubiaga97@gmail.com>
-rw-r--r-- | activity.py | 48 | ||||
-rw-r--r-- | icons/python-console.svg | 70 | ||||
-rw-r--r-- | python_console.py | 67 | ||||
-rw-r--r-- | view_changes.py | 93 |
4 files changed, 268 insertions, 10 deletions
diff --git a/activity.py b/activity.py index 586787d..de122d3 100644 --- a/activity.py +++ b/activity.py @@ -45,6 +45,7 @@ from sugar.activity import activity from pep8_check import PEP8_Check from font_options import FontToolbarButton from editor import Editor, LANGUAGE_MANAGER, LANGUAGES +from python_console import PythonConsole import file_choosers file_choosers.langsmanager = LANGUAGE_MANAGER file_choosers.langs = LANGUAGES @@ -207,6 +208,17 @@ class JAMEdit(activity.Activity): self._search_next.connect('clicked', self.editor._search_next_cb) self.toolbox.toolbar.insert(self._search_next, -1) + + # Barra de estado de PEP8 / PEP8 status bar + self.pep8 = PEP8_Check(self) + + self.pep8_bar = gtk.Statusbar() + #self.pep8.connect("show-bar", (lambda w, bar: bar.show_all()), self.pep8_bar) + #self.pep8.connect("hide-bar", (lambda w, bar: bar.hide()), self.pep8_bar) + self.pep8_bar.label = gtk.Label() + #self.pep8.connect("bar-text", (lambda w, t, l: l.set_text(t)), self.pep8_bar.label) + self.pep8_bar.add(self.pep8_bar.label) + vbox.pack_end(self.pep8_bar, False, True, 0) # Preferencias / preferences @@ -223,6 +235,24 @@ class JAMEdit(activity.Activity): self.editor._make_languages_combo(preferences_toolbar) self.editor.make_style_combo(preferences_toolbar) + + separator = gtk.SeparatorToolItem() + separator.set_draw(False) + separator.set_expand(True) + preferences_toolbar.insert(separator, -1) + separator.show_all() + + self.python_console = PythonConsole() + self.python_console.showed = False + vbox.pack_end(self.python_console, False, True, 0) + + self.python_console.hide() + + python_console_btn = ToolButton("python-console") + python_console_btn.set_tooltip(_("Show or hide the python console")) + python_console_btn.connect("clicked", self.show_python_console) + preferences_toolbar.insert(python_console_btn, -1) + python_console_btn.show_all() preferences = ToolbarButton() preferences.props.page = preferences_toolbar @@ -254,17 +284,15 @@ class JAMEdit(activity.Activity): self.toolbar_box.show_all() self.set_toolbar_box(self.toolbar_box) - - # Barra de estado de PEP8 / PEP8 status bar - self.pep8 = PEP8_Check() - self.pep8_bar = gtk.Statusbar() - self.pep8.connect("show-bar", (lambda w, bar: bar.show_all()), self.pep8_bar) - self.pep8.connect("hide-bar", (lambda w, bar: bar.hide()), self.pep8_bar) - self.pep8_bar.label = gtk.Label() - self.pep8.connect("bar-text", (lambda w, t, l: l.set_text(t)), self.pep8_bar.label) - self.pep8_bar.add(self.pep8_bar.label) - vbox.pack_end(self.pep8_bar, False, True, 0) + def show_python_console(self, widget): + if not self.python_console.showed: + self.python_console.show() + self.python_console.showed = True + + else: + self.python_console.hide() + self.python_console.showed = False def _search_entry_activate_cb(self, entry): self.editor.set_search_text(entry.props.text) diff --git a/icons/python-console.svg b/icons/python-console.svg new file mode 100644 index 0000000..8efcaed --- /dev/null +++ b/icons/python-console.svg @@ -0,0 +1,70 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<svg + xmlns:dc="http://purl.org/dc/elements/1.1/" + xmlns:cc="http://creativecommons.org/ns#" + xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" + xmlns:svg="http://www.w3.org/2000/svg" + xmlns="http://www.w3.org/2000/svg" + xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" + xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" + enable-background="new 0 0 55 55" + height="55px" + version="1.1" + viewBox="0 0 55 55" + width="55px" + x="0px" + xml:space="preserve" + y="0px" + id="svg2" + inkscape:version="0.48.2 r9819" + sodipodi:docname="new.svg"><metadata + id="metadata23"><rdf:RDF><cc:Work + rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type + rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title></dc:title></cc:Work></rdf:RDF></metadata><defs + id="defs21"><inkscape:path-effect + effect="spiro" + id="path-effect2994" + is_visible="true" /><inkscape:path-effect + effect="spiro" + id="path-effect2994-7" + is_visible="true" /><inkscape:path-effect + effect="spiro" + id="path-effect2994-8" + is_visible="true" /></defs><sodipodi:namedview + pagecolor="#ffffff" + bordercolor="#666666" + borderopacity="1" + objecttolerance="10" + gridtolerance="10" + guidetolerance="10" + inkscape:pageopacity="0" + inkscape:pageshadow="2" + inkscape:window-width="1280" + inkscape:window-height="746" + id="namedview19" + showgrid="false" + inkscape:zoom="3.7297716" + inkscape:cx="5.5537966" + inkscape:cy="27.502882" + inkscape:window-x="0" + inkscape:window-y="26" + inkscape:window-maximized="1" + inkscape:current-layer="svg2" /><path + style="fill:#ffffff;stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" + d="M 5.8984845,16.659851 22.789599,26.311916 6.9709362,35.695869 23.057712,26.311916 5.8984845,16.659851" + id="path2992" + inkscape:path-effect="#path-effect2994" + inkscape:original-d="M 5.8984845,16.659851 22.789599,26.311916 6.9709362,35.695869 23.057712,26.311916 z" + inkscape:connector-curvature="0" /><path + style="fill:#ffffff;stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" + d="M 20.10847,17.06202 36.999584,26.714085 21.180922,36.098038 37.267697,26.714085 20.10847,17.06202" + id="path2992-8" + inkscape:path-effect="#path-effect2994-7" + inkscape:original-d="m 20.10847,17.06202 16.891114,9.652065 -15.818662,9.383953 16.086775,-9.383953 z" + inkscape:connector-curvature="0" /><path + style="fill:#ffffff;stroke:#ffffff;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;stroke-miterlimit:4;stroke-dasharray:none" + d="M 33.514116,16.525794 50.40523,26.177859 34.586568,35.561812 50.673343,26.177859 33.514116,16.525794" + id="path2992-84" + inkscape:path-effect="#path-effect2994-8" + inkscape:original-d="M 33.514116,16.525794 50.40523,26.177859 34.586568,35.561812 50.673343,26.177859 z" + inkscape:connector-curvature="0" /></svg>
\ No newline at end of file diff --git a/python_console.py b/python_console.py new file mode 100644 index 0000000..ece3d12 --- /dev/null +++ b/python_console.py @@ -0,0 +1,67 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +# python_console.py by/por: +# Agustin Zubiaga <aguszs97@gmail.com> +# Daniel Francis <santiago.danielfrancis@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + + +import gtk +import vte + +from signal import SIGTERM + +import os +import sys + + +class PythonConsole(vte.Terminal): + + def __init__(self): + vte.Terminal.__init__(self) + + self.fork_command("python") + + self.set_size_request(800, 150) + + def _clear_console(self): + self.grab_focus() + self.feed("\x1B[H\x1B[J\x1B[0;39m") + +class PythonCodeRun(vte.Terminal): + + def __init__(self): + vte.Terminal.__init__(self) + + self.set_size_request(800, 150) + + def _run(self, file): + self.process_id = self.fork_command \ + (command = "/bin/sh", + argv = ["/bin/sh", "-c", + "python %s; sleep 1" % file]) + def _stop(self): + try: + os.kill(self.process_id, SIGTERM) + self._clear_console() + except: + pass + + def _clear_console(self): + self.grab_focus() + self.feed("\x1B[H\x1B[J\x1B[0;39m") diff --git a/view_changes.py b/view_changes.py new file mode 100644 index 0000000..f88194c --- /dev/null +++ b/view_changes.py @@ -0,0 +1,93 @@ +#!/usr/bin/env python +# -*- coding: UTF-8 -*- + +# view_changes.py by/por: +# Agustin Zubiaga <aguszs97@gmail.com> +# Daniel Francis <santiago.danielfrancis@gmail.com> +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1301, USA. + +import os +import shutil +import gtksourceview2 + +LANGUAGE_MANAGER = gtksourceview2.language_manager_get_default() +DIFF_LANG = LANGUAGE_MANAGER.get_language("diff") +STYLE_MANAGER = gtksourceview2.style_scheme_manager_get_default() +STYLE_MANAGER.append_search_path(os.path.join(os.environ["PWD"], + "styles")) +JAMEDIT_CHANGES_STYLE = STYLE_MANAGER.get_scheme("jamedit-changes") + +TMP = "/tmp/" + + +class View_Changes(): + + def __init__(self): + self.tmp_file = None + self.patch_name = None + + def save_old_file(self, file): + tmp_file = os.path.join(TMP, "jamedit-changes-file-1") + num = 0 + + # If tmp_file exists: + while os.path.exists(tmp_file): + num += 1 + tmp_file = os.path.join(TMP, "jamedit-changes-file-"+str(num)) + + shutil.copyfile(file, tmp_file) + + self.old_file = tmp_file + + def get_patch_name(self): + num = self.old_file.split("-")[-1] + patch = os.path.join(TMP, "jamedit-changes-patch-"+num+".patch") + self.patch_name = patch + + return patch + + def get_changes(self, new_file): + os.system("diff %s %s > %s" % (self.old_file, + new_file, + self.get_patch_name())) + + os.remove(self.old_file) + self.old_file = new_file + + changes = open(self.patch_name, "r") + changes_text = changes.read() + changes.close() + + os.remove(self.patch_name) + + return changes_text + + def get_changes_with_textview(self, new_file): + changes = self.get_changes(new_file) + + textview = gtksourceview2.View() + textview.buffer = gtksourceview2.Buffer() + textview.set_buffer(textview.buffer) + textview.buffer.set_text(changes) + textview.set_editable(False) + textview.set_cursor_visible(False) + textview.buffer.set_highlight_syntax(True) + textview.buffer.set_language(DIFF_LANG) + textview.buffer.set_style_scheme(JAMEDIT_CHANGES_STYLE) + textview.show_all() + + return textview |