From ba23d4993803277242eac3769125804472f8b135 Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 20 Jan 2008 16:31:37 +0000 Subject: [PATCH] Minor refactoring to address Owen's comments. - Use iterate_text() directly when saving, instead of adding ShellBuffer.save_to_stream(). - Document set_filename_and_modified(). --- Reinteract.xml | 3 +-- lib/reinteract/main.py | 2 +- lib/reinteract/rox_ui.py | 9 +++++---- lib/reinteract/shell_buffer.py | 10 +++++----- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Reinteract.xml b/Reinteract.xml index 874750b..fc2090d 100644 --- a/Reinteract.xml +++ b/Reinteract.xml @@ -1,7 +1,6 @@ - - Reinteract-ROX + Reinteract a system for interactive experimentation with python Reinteract is a system for interactive experimentation with python. You enter diff --git a/lib/reinteract/main.py b/lib/reinteract/main.py index 541d07a..e9643b6 100644 --- a/lib/reinteract/main.py +++ b/lib/reinteract/main.py @@ -156,7 +156,7 @@ def on_save(action): def save_as(): if use_rox: rox_ui.save_with_rox_savebox(buf) - return + return if use_hildon: chooser = hildon.FileChooserDialog(w, gtk.FILE_CHOOSER_ACTION_SAVE) diff --git a/lib/reinteract/rox_ui.py b/lib/reinteract/rox_ui.py index a70d113..8f26a4b 100644 --- a/lib/reinteract/rox_ui.py +++ b/lib/reinteract/rox_ui.py @@ -4,14 +4,15 @@ class ShellBufferSaveable(saving.Saveable): """Save a ShellBuffer using the ROX saving protocol.""" def __init__(self, buf): - self.buf = buf + self.buf = buf def save_to_stream(self, stream): - self.buf.save_to_stream(stream) + for chunk_text in self.buf.iterate_text(): + stream.write(chunk_text) def set_uri(self, uri): - self.buf.set_filename_and_modified(uri, False) - #notebook.set_path([os.path.dirname(os.path.abspath(filename))]) + self.buf.set_filename_and_modified(uri, False) + #notebook.set_path([os.path.dirname(os.path.abspath(filename))]) def save_with_rox_savebox(buf): box = saving.SaveBox(ShellBufferSaveable(buf), buf.filename or 'Worksheet') diff --git a/lib/reinteract/shell_buffer.py b/lib/reinteract/shell_buffer.py index 7fb761e..1944767 100755 --- a/lib/reinteract/shell_buffer.py +++ b/lib/reinteract/shell_buffer.py @@ -1172,6 +1172,9 @@ class ShellBuffer(gtk.TextBuffer, Worksheet): return result_chunk def set_filename_and_modified(self, filename, modified): + "Update the filename and modified fields, emitting 'filename-changed' and 'code-modified-changed' signals as appropriate." + # This method is needed by rox_ui, because saving to a file and updating the filename happen separately in the saving process. + filename_changed = filename != self.filename modified_changed = modified != self.code_modified @@ -1235,7 +1238,8 @@ class ShellBuffer(gtk.TextBuffer, Worksheet): success = False try: - self.save_to_stream(f) + for chunk_text in self.iterate_text(): + f.write(chunk_text) f.close() os.rename(tmpname, filename) @@ -1246,10 +1250,6 @@ class ShellBuffer(gtk.TextBuffer, Worksheet): if not success: f.close() os.remove(tmpname) - - def save_to_stream(self, stream): - for chunk_text in self.iterate_text(): - stream.write(chunk_text) if __name__ == '__main__': S = StatementChunk -- 2.11.4.GIT