diff options
Diffstat (limited to 'ReckonPrimer.activity/display.py')
-rwxr-xr-x | ReckonPrimer.activity/display.py | 71 |
1 files changed, 68 insertions, 3 deletions
diff --git a/ReckonPrimer.activity/display.py b/ReckonPrimer.activity/display.py index a0b3eb4..a4b2bb4 100755 --- a/ReckonPrimer.activity/display.py +++ b/ReckonPrimer.activity/display.py @@ -10,6 +10,10 @@ from timer import Timer from sugar import profile from sugar.graphics import style from sugar.activity import activity +#BEGIN LPCHANGE +from sugar.datastore import datastore +import os +#END LPCHANGE class Display: """ @@ -248,6 +252,10 @@ class Display: def offer_setting(self,ex): """ Prepare display for update of settings. """ self._ex = ex #WN.LV either drop this or self.current_exercise + #BEGIN LPCHANGE + self.protocol_settings_string() + #END LPCHANGE + self._sett = self._ex.get_setting() #WN.LV make _sett local self.current_exercise = ex #WN.LV either drop this or self._ex @@ -278,6 +286,7 @@ class Display: prepares for calculations from 1 setting. for instance, a calculation might be on 1 ore more lines. """ + #self._mode = "learner" print("in display.init_calc") # make empty lines such that all calcs are entered at bottom for i in range(1,21): @@ -298,11 +307,13 @@ class Display: end_iterator = self.log_buffer.get_end_iter() mark = self.log_buffer.create_mark(None, end_iterator, True) self.log_view.scroll_mark_onscreen(mark) + +#BEGIN LPCHANGE def protocol_generated_calcs(self, calculations, change): print("DEBUG: in display.protocol_generated_calcs") end_iterator = self.log_buffer.get_end_iter() - self.log_buffer.insert_with_tags_by_name(end_iterator, "\n---------- " + change + " ----------" , "fixxxme!" ) + self.log_buffer.insert_with_tags_by_name(end_iterator, "\n---------- " + change + " ----------") for c in calculations: end_iterator = self.log_buffer.get_end_iter() @@ -313,10 +324,64 @@ class Display: to_format[2] + " " + \ to_format[3] + " " + \ to_format[4] - self.log_buffer.insert_with_tags_by_name(end_iterator, "\n" + printable_calc, "fixxxme!" ) + self.log_buffer.insert_with_tags_by_name(end_iterator, "\n" + printable_calc) - mark = self.log_buffer.create_mark(None, end_iterator, True) + end_iterator = self.log_buffer.get_end_iter() + mark = self.log_buffer.create_mark(None, end_iterator, False) + self.log_view.scroll_mark_onscreen(mark) + #self.log_view.scroll_to_iter(end_iterator, 0) + #self.log_view.set_justification(gtk.JUSTIFY_CENTER) + + + def protocol_settings_string(self): + """ + This method writes the settings of the exercise to the protocol. + """ + settings_string = self._ex.get_settings_string() + end_iterator = self.log_buffer.get_end_iter() + self.log_buffer.insert_with_tags_by_name(end_iterator, "\n---------- SETTINGS ----------") + end_iterator = self.log_buffer.get_end_iter() + self.log_buffer.insert_with_tags_by_name(end_iterator, "\n" + settings_string) + for i in range(1,21): + end_iterator = self.log_buffer.get_end_iter() + self.log_buffer.insert(end_iterator, "\n") + + mark = self.log_buffer.create_mark(None, end_iterator, False) self.log_view.scroll_mark_onscreen(mark) + #self.log_view.scroll_to_iter(end_iterator, 0) + #self.log_view.set_justification(gtk.JUSTIFY_CENTER) + + def write_protocol_to_journal(self): + """ + This method writes the whole protocol to the journal. + """ + #open file + logfile = open('data/protocol.txt', 'w') + #get string from textbuffer + log_string = self.log_buffer.get_text(self.log_buffer.get_start_iter(), self.log_buffer.get_end_iter(), True) + #remove empty lines + stripped_string = '' + for line in log_string.split('\n'): + if line.strip(): + stripped_string += line + '\n' + #write to file + print stripped_string + logfile.write(stripped_string) + logfile.write('\n') + logfile.close() + print '------------------------------------------------------------------' + print file('data/protocol.txt').read() + #make journal entry + journal_object = datastore.create() + journal_object.metadata['title'] = 'ReckonPrimer Protocol' + journal_object.metadata['mime_type'] = 'text/plain' + journal_object.file_path = os.getcwd() + '/data/protocol.txt' + #journal_object.file_path = 'data/protocol.txt' + datastore.write(journal_object) + journal_object.destroy() + + +#END LPCHANGE def input_digit(self, widget, dig, proterr, protok): """callback: input a digit and give feedback. |