Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAgustin Zubiaga <olpc@xo-1b-99-29.localdomain>2011-12-06 00:39:31 (GMT)
committer Agustin Zubiaga <olpc@xo-1b-99-29.localdomain>2011-12-06 00:39:31 (GMT)
commita60de6a2365987d4c223a22c801f6984297e0927 (patch)
tree464dd7f9f69bd32839af8aadf83519720f5383bd
parentb124747fd79b14b6b4fa7b3d89724339b1ba7d5b (diff)
PEP8 now works, but has lot of bugs
-rw-r--r--activity.py13
-rw-r--r--editor.py3
-rw-r--r--file_choosers.py174
-rw-r--r--font_options.py40
-rwxr-xr-xpep8/pep8.pycbin0 -> 36035 bytes
-rw-r--r--pep8_check.py80
6 files changed, 195 insertions, 115 deletions
diff --git a/activity.py b/activity.py
index cbbbd44..362fb46 100644
--- a/activity.py
+++ b/activity.py
@@ -58,12 +58,17 @@ class JAMEdit(activity.Activity):
# ****** Editor ******
self.editor = Editor(self)
+ self.editor.set_size_request(800, 790)
scroll = gtk.ScrolledWindow()
scroll.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
scroll.add(self.editor)
scroll.show_all()
- self.set_canvas(scroll)
+ vbox = gtk.VBox()
+ vbox.add(scroll)
+ vbox.show_all()
+
+ self.set_canvas(vbox)
# ****** Toolbars ******
@@ -209,6 +214,12 @@ class JAMEdit(activity.Activity):
self.set_toolbar_box(self.toolbar_box)
+ # Barra de estado de PEP8 / PEP8 status bar
+ self.pep8_bar = gtk.Statusbar()
+ self.pep8_bar.label = gtk.Label()
+ self.pep8_bar.add(self.pep8_bar.label)
+ vbox.add(self.pep8_bar)
+
def change_font(self, widget, family, face, size):
self.editor.modify_font(pango.FontDescription("%s %s %d" % (family, face, size)))
diff --git a/editor.py b/editor.py
index 5e29610..ad50458 100644
--- a/editor.py
+++ b/editor.py
@@ -32,7 +32,6 @@ from sugar.graphics.toolcombobox import ToolComboBox
from pep8_check import PEP8_Check
-PEP8CHECKER = PEP8_Check()
LANGUAGE_MANAGER = gtksourceview2.language_manager_get_default()
LANGUAGES = LANGUAGE_MANAGER.get_language_ids()
@@ -68,7 +67,7 @@ class Editor(gtksourceview2.View):
self.activity = activity
- self.pep8 = PEP8_Check()
+ self.pep8 = PEP8_Check(self.activity)
self.show_all()
diff --git a/file_choosers.py b/file_choosers.py
index a005e2b..2eb5b04 100644
--- a/file_choosers.py
+++ b/file_choosers.py
@@ -1,86 +1,106 @@
#!/usr/bin/env python
-# -*- coding: utf-8 -*-
+# -*- coding: UTF-8 -*-
+
+# file_choosers.py by/por:
+# Daniel Francis <santiago.danielfrancis@gmail.com>
+# Agustin Zubiaga <aguzubiaga97@gmail.com>
+# Sugarlabs - CeibalJAM! - Uruguay
+
+# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+
import gtk
def open_file_dialog():
- dialog = gtk.FileChooserDialog(_("Open..."),
- None,
- gtk.FILE_CHOOSER_ACTION_OPEN,
- (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
- gtk.STOCK_OPEN, gtk.RESPONSE_OK))
- dialog.set_default_response(gtk.RESPONSE_OK)
-
- filter = gtk.FileFilter()
- filter.set_name(_("All files"))
- filter.add_pattern("*")
- dialog.add_filter(filter)
-
- filter = gtk.FileFilter()
- filter.set_name(_("All text files"))
- filter.add_mime_type("text/*")
- dialog.add_filter(filter)
-
- lang_ids = langs
- for i in lang_ids:
- lang = langsmanager.get_language(i)
- filter = gtk.FileFilter()
- filter.set_name(lang.get_name())
- for m in lang.get_mime_types():
- filter.add_mime_type(m)
- dialog.add_filter(filter)
- response = dialog.run()
- if response == gtk.RESPONSE_OK:
- to_return = dialog.get_filename()
- elif response == gtk.RESPONSE_CANCEL:
- to_return = None
- dialog.destroy()
- return to_return
+ dialog = gtk.FileChooserDialog(_("Open..."),
+ None,
+ gtk.FILE_CHOOSER_ACTION_OPEN,
+ (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
+ gtk.STOCK_OPEN, gtk.RESPONSE_OK))
+ dialog.set_default_response(gtk.RESPONSE_OK)
+
+ filter = gtk.FileFilter()
+ filter.set_name(_("All files"))
+ filter.add_pattern("*")
+ dialog.add_filter(filter)
+
+ filter = gtk.FileFilter()
+ filter.set_name(_("All text files"))
+ filter.add_mime_type("text/*")
+ dialog.add_filter(filter)
+
+ lang_ids = langs
+ for i in lang_ids:
+ lang = langsmanager.get_language(i)
+ filter = gtk.FileFilter()
+ filter.set_name(lang.get_name())
+ for m in lang.get_mime_types():
+ filter.add_mime_type(m)
+ dialog.add_filter(filter)
+ response = dialog.run()
+ if response == gtk.RESPONSE_OK:
+ to_return = dialog.get_filename()
+ elif response == gtk.RESPONSE_CANCEL:
+ to_return = None
+ dialog.destroy()
+ return to_return
def confirm_overwrite(widget):
- dialog = gtk.MessageDialog(type=gtk.MESSAGE_QUESTION)
- dialog.add_buttons(gtk.STOCK_NO, gtk.RESPONSE_CANCEL, gtk.STOCK_YES, gtk.RESPONSE_ACCEPT)
- dialog.set_markup("<b>%s</b>" % _("This file name already exists"))
- dialog.format_secondary_text(_("Overwrite the file?"))
- response = dialog.run()
- dialog.destroy()
- if response == gtk.RESPONSE_ACCEPT:
- return gtk.FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME
- else:
- return gtk.FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN
+ dialog = gtk.MessageDialog(type=gtk.MESSAGE_QUESTION)
+ dialog.add_buttons(gtk.STOCK_NO, gtk.RESPONSE_CANCEL, gtk.STOCK_YES, gtk.RESPONSE_ACCEPT)
+ dialog.set_markup("<b>%s</b>" % _("This file name already exists"))
+ dialog.format_secondary_text(_("Overwrite the file?"))
+ response = dialog.run()
+ dialog.destroy()
+ if response == gtk.RESPONSE_ACCEPT:
+ return gtk.FILE_CHOOSER_CONFIRMATION_ACCEPT_FILENAME
+ else:
+ return gtk.FILE_CHOOSER_CONFIRMATION_SELECT_AGAIN
def save_file_dialog():
- dialog = gtk.FileChooserDialog(_("Save..."),
- None,
- gtk.FILE_CHOOSER_ACTION_SAVE,
- (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
- gtk.STOCK_SAVE, gtk.RESPONSE_OK))
- dialog.set_default_response(gtk.RESPONSE_OK)
- dialog.set_do_overwrite_confirmation(True)
- dialog.connect("confirm-overwrite", confirm_overwrite)
-
- filter = gtk.FileFilter()
- filter.set_name(_("All files"))
- filter.add_pattern("*")
- dialog.add_filter(filter)
-
- filter = gtk.FileFilter()
- filter.set_name(_("All text files"))
- filter.add_mime_type("text/*")
- dialog.add_filter(filter)
-
- lang_ids = langs
- for i in lang_ids:
- lang = langsmanager.get_language(i)
- filter = gtk.FileFilter()
- filter.set_name(lang.get_name())
- for m in lang.get_mime_types():
- filter.add_mime_type(m)
- dialog.add_filter(filter)
- response = dialog.run()
- if response == gtk.RESPONSE_OK:
- to_return = dialog.get_filename()
- elif response == gtk.RESPONSE_CANCEL:
- to_return = None
- dialog.destroy()
- return to_return
+ dialog = gtk.FileChooserDialog(_("Save..."),
+ None,
+ gtk.FILE_CHOOSER_ACTION_SAVE,
+ (gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL,
+ gtk.STOCK_SAVE, gtk.RESPONSE_OK))
+ dialog.set_default_response(gtk.RESPONSE_OK)
+ dialog.set_do_overwrite_confirmation(True)
+ dialog.connect("confirm-overwrite", confirm_overwrite)
+
+ filter = gtk.FileFilter()
+ filter.set_name(_("All files"))
+ filter.add_pattern("*")
+ dialog.add_filter(filter)
+
+ filter = gtk.FileFilter()
+ filter.set_name(_("All text files"))
+ filter.add_mime_type("text/*")
+ dialog.add_filter(filter)
+
+ lang_ids = langs
+ for i in lang_ids:
+ lang = langsmanager.get_language(i)
+ filter = gtk.FileFilter()
+ filter.set_name(lang.get_name())
+ for m in lang.get_mime_types():
+ filter.add_mime_type(m)
+ dialog.add_filter(filter)
+ response = dialog.run()
+ if response == gtk.RESPONSE_OK:
+ to_return = dialog.get_filename()
+ elif response == gtk.RESPONSE_CANCEL:
+ to_return = None
+ dialog.destroy()
+ return to_return
diff --git a/font_options.py b/font_options.py
index 0a801d6..5cb6db7 100644
--- a/font_options.py
+++ b/font_options.py
@@ -1,26 +1,24 @@
#!/usr/bin/env python
-# -*- coding: utf-8 -*-
+# -*- coding: UTF-8 -*-
+
+# font_options.py by/por:
+# Daniel Francis <santiago.danielfrancis@gmail.com>
+# Agustin Zubiaga <aguzubiaga97@gmail.com>
+# Sugarlabs - CeibalJAM! - Uruguay
+
+# 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.
#
-# font_options.py
-#
-# Copyright 2011 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 2 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.
-#
-#
+# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
import gobject
import gtk
diff --git a/pep8/pep8.pyc b/pep8/pep8.pyc
new file mode 100755
index 0000000..fdbd10d
--- /dev/null
+++ b/pep8/pep8.pyc
Binary files differ
diff --git a/pep8_check.py b/pep8_check.py
index 04954e4..ec2d5ca 100644
--- a/pep8_check.py
+++ b/pep8_check.py
@@ -1,6 +1,27 @@
#!/usr/bin/env python
+# pep8_check.py by/por:
+# Agustin Zubiaga <aguzubiaga97@gmail.com>
+# Daniel Francis <santiago.danielfrancis@gmail.com>
+# Sugarlabs - CeibalJAM! - Uruguay
+
+# 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 St, Fifth Floor, Boston, MA 02110-1301 USA
+
+
import logging
+import gtk
log = logging.getLogger('EditJam')
log.setLevel(logging.DEBUG)
@@ -9,40 +30,71 @@ import commands
class PEP8_Check():
+ def __init__(self, activity): self.activity = activity
+
def check_file(self, text, editor):
tmp_file = open("/tmp/jamedit-pep8-chk.py", "w")
- tmp_file.write(text)
- tmp_file.close()
+ tmp_file.write(text)
+ tmp_file.close()
- chk = self.get_check()
+ chk = self.get_check()
- self.highlight_errors(editor, chk)
+ self.highlight_errors(editor, chk)
def highlight_errors(self, editor, chk):
- for key in chk.keys():
- # Here highlight errors whit tag pep8-error
- log.debug('%s: %s' % (key, chk[key]))
+ text = editor._get_all_text()
+ editor.buffer.set_text("")
+ num = -1
+ for line in text.split("\n"):
+ num += 1
+ if str(num) in chk:
+ line_iter = editor.buffer.get_iter_at_line(num-1)
+
+ editor.buffer.insert_with_tags(line_iter, line+"\n", editor.error_tag)
+ elif not num in chk:
+ char = 0
+ line_iter = editor.buffer.get_iter_at_line(num)
+ if num != len(text.split("\n")):
+ editor.buffer.insert_with_tags_by_name(line_iter, line+"\n")
+ else:
+ editor.buffer.insert_with_tags_by_name(line_iter, line)
+ editor.connect("move-cursor", self.set_bar_text, chk)
def get_check(self):
(status, output) = commands.getstatusoutput(
- "pep8 -r /tmp/jamedit-pep8-chk.py")
+ "python pep8/pep8.pyc --repeat /tmp/jamedit-pep8-chk.py")
check = self.interpret_output(output)
return check
def interpret_output(self, output):
checks = {}
- outputs = output.split("\n")
- for out in outputs:
+ outputs = output.split("\n")
+ for out in outputs:
try:
splits = out.split(":")
- line = splits[1]
+ line = splits[1]
character = splits[2]
- error = splits[3]
+ error = splits[3]
if line not in checks:
checks[line] = '%s:%s' % (character, error)
else:
checks[line] = '%s; %s:%s' % (
checks[line], character, error)
- except: pass
+ except: pass
+
+ return checks
- return checks
+ def set_bar_text(self, widget, step_size, count, extend_selection, check):
+ if step_size == gtk.MOVEMENT_DISPLAY_LINES:
+ cursor_position = widget.buffer.get_property("cursor-position")
+ offset_iter = widget.buffer.get_iter_at_offset(cursor_position)
+ line = offset_iter.get_line()
+ print line
+ if str(line) in check:
+ this_line_error = check[str(line)]
+ char = this_line_error.split(":")[0]
+ this_line_error = this_line_error.split(":")[1]
+ self.activity.pep8_bar.label.set_text(str(line)+":"+char+" "+this_line_error)
+ print this_line_error
+ self.activity.pep8_bar.show_all()
+ else: self.activity.pep8_bar.hide() \ No newline at end of file