From f2610f823e086040ff5d32032e98e6616925a31e Mon Sep 17 00:00:00 2001 From: Laurent BERNABE Date: Mon, 30 May 2011 14:06:30 +0000 Subject: Changed heriarchical structure --- diff --git a/COPYING b/COPYING index bec541f..bec541f 100755..100644 --- a/COPYING +++ b/COPYING diff --git a/InputDialog.py b/InputDialog.py new file mode 100755 index 0000000..9ce1e89 --- /dev/null +++ b/InputDialog.py @@ -0,0 +1,68 @@ +# InputDialog.py Own implementation of InputDialog +# +# Copyright (C) 2011 Laurent BERNABE +# +# 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 +# St, Fifth Floor, Boston, MA 02110-1301 USA + +import pygtk +pygtk.require('2.0') +import gtk + +class InputDialog(gtk.MessageDialog): + ''' + Creates an input dialog with + => a label (for the prompt) + => a text entry + => ok_button and cancel_button + ''' + + + def __init__(self, prompt, parent=None): + ''' + Constructor(prompt, parent=None) + prompt argument : the text of the dialog + parent : the parent control + ''' + gtk.MessageDialog.__init__(self, + parent, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, + gtk.BUTTONS_OK_CANCEL, prompt) + self.__entry = gtk.Entry() + self.vbox.pack_start(self.__entry, True, True, 0) + self.connect("delete-event", lambda widget, event : self.__close() ) + + def run(self): + ''' + Run() + Runs the dialog + ''' + self.show_all() + response = super(InputDialog,self).run() + if response == gtk.RESPONSE_OK : + text = self.__entry.get_text() + else : + text = None + self.destroy() + return text + + def __close(self): + ''' + __close() + Closes the dialog and returns None + ''' + self.destroy() + return None \ No newline at end of file diff --git a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/sugar_launcher/Launcher.py b/Launcher.py index 6aa9e3c..10208c6 100644..100755 --- a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/sugar_launcher/Launcher.py +++ b/Launcher.py @@ -1,8 +1,24 @@ -''' -Created on 10 mai 2011 +# Launcher.py Launches the program in Sugar environment +# +# Copyright (C) 2011 Laurent BERNABE +# +# 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 +# St, Fifth Floor, Boston, MA 02110-1301 USA -@author: laurent_bernabe -''' from gettext import gettext as _ from sugar.activity import activity @@ -84,4 +100,20 @@ class Launcher(activity.Activity): drawing_toolbar.insert(drawing_toolbar_read_button, 1) #-------------------- toolbox.add_toolbar(_('Drawing'), drawing_toolbar) - drawing_toolbar.show_all() \ No newline at end of file + drawing_toolbar.show_all() + + def read_file(self, file_path): + ''' + Manages sugar activity resume from entry journal + ''' + saves_text_file = open(file_path, 'r') + self.__wrapped_drawing_area.readFiguresFromTextFile(saves_text_file) + saves_text_file.close() + + def write_file(self, file_path): + ''' + Manages sugar activity journal entry updating + ''' + saves_text_file = open(file_path, 'w') + self.__wrapped_drawing_area.saveFiguresInTextFile(saves_text_file) + saves_text_file.close() \ No newline at end of file diff --git a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/gui/MenuActions.py b/MenuActions.py index 095024d..1b81f48 100644..100755 --- a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/gui/MenuActions.py +++ b/MenuActions.py @@ -1,8 +1,24 @@ -''' -Created on 12 mai 2011 +# MenuActions.py Stores the actions for the MenuItems +# +# Copyright (C) 2011 Laurent BERNABE +# +# 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 +# St, Fifth Floor, Boston, MA 02110-1301 USA -@author: laurent_bernabe -''' from gettext import gettext as _ from com.gmail.bernabe.laurent.sugar_olpc.learning_writing.gui.InputDialog import \ InputDialog diff --git a/PurePyGTKLauncher.py b/PurePyGTKLauncher.py new file mode 100755 index 0000000..bdf291a --- /dev/null +++ b/PurePyGTKLauncher.py @@ -0,0 +1,27 @@ +# PurePyGTKLauncher.py Launch the application in non-Sugar environments +# +# Copyright (C) 2011 Laurent BERNABE +# +# 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 +# St, Fifth Floor, Boston, MA 02110-1301 USA + +import gtk +from com.gmail.bernabe.laurent.sugar_olpc.learning_writing.pure_pygtk_launcher.TheWindow import TheWindow + +if __name__ == '__main__': + TheWindow() + gtk.main() \ No newline at end of file diff --git a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/gui/TheDrawingAreaEventBox.py b/TheDrawingAreaEventBox.py index 03c26e7..630483a 100644..100755 --- a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/gui/TheDrawingAreaEventBox.py +++ b/TheDrawingAreaEventBox.py @@ -1,8 +1,24 @@ -''' -Created on 10 mai 2011 +# TheDrawingAreaEventBox.py Manages the drawing component +# +# Copyright (C) 2011 Laurent BERNABE +# +# 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 +# St, Fifth Floor, Boston, MA 02110-1301 USA -@author: laurent_bernabe -''' import pygtk pygtk.require('2.0') import gtk @@ -213,4 +229,40 @@ class TheDrawingAreaEventBox(gtk.EventBox): self.__updater_delay_milliseconds, self.__regularlyUpdatePaintForReadingMode ) - \ No newline at end of file + + def saveFiguresInTextFile(self, text_file): + ''' + Save the points in a file opened with function 'open' in write mode. + Be careful !!! Do not pass a file opened in binary mode !!! + And also, remember to close the file after this method call !!! + => saveFiguresInTextFile(text_file) + ''' + for current_figure in self.__figures : + if current_figure: + text_file.write("New\n") + for point_coordinates in current_figure: + if point_coordinates: + text_file.write("%d#%d " % point_coordinates) + text_file.write("\n") + + def readFiguresFromTextFile(self, text_file): + ''' + Read the points from a file opened with function 'open' in read mode. + Be careful !!! Do not pass a filed opened in a binary mode !!! + And also, remember to close the file after this method call !!! + => readFiguresFromTextFile(text_file) + ''' + new_figures_array = [] + for current_line in text_file.readlines(): + if current_line != "New" : + new_figure = [] + for current_point_string in current_line.split(' '): + if current_point_string: + current_point_string_parts = current_point_string.split('#') + new_figure.append((int(current_point_string_parts[0]), + int(current_point_string_parts[1]))) + if new_figure: + new_figures_array.append(new_figure) + self.__figures = new_figures_array + self.__drawingArea.queue_draw() + \ No newline at end of file diff --git a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/pure_pygtk_launcher/TheWindow.py b/TheWindow.py index d45e418..3ea365b 100644..100755 --- a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/pure_pygtk_launcher/TheWindow.py +++ b/TheWindow.py @@ -1,8 +1,24 @@ -''' -Created on 10 mai 2011 +# TheWindow.py Manages the window in non-Sugar environments +# +# Copyright (C) 2011 Laurent BERNABE +# +# 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 +# St, Fifth Floor, Boston, MA 02110-1301 USA -@author: laurent_bernabe -''' import pygtk from com.gmail.bernabe.laurent.sugar_olpc.learning_writing.gui.MenuActions \ diff --git a/activity/activity.info b/activity/activity.info index da6c6d6..c45895e 100755..100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -2,7 +2,7 @@ name = LearningWriting bundle_id = com.gmail.bernabe.laurent.sugar_olpc.learning_writing service_name = com.gmail.bernabe.laurent.sugar_olpc.learning_writing -exec = sugar-activity com.gmail.bernabe.laurent.sugar_olpc.learning_writing.sugar_launcher.Launcher.Launcher +exec = sugar-activity Launcher.Launcher icon = activity-icon activity_version = 1 mime_types = text/plain diff --git a/com/__init__.py b/com/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/com/__init__.py +++ /dev/null diff --git a/com/gmail/__init__.py b/com/gmail/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/com/gmail/__init__.py +++ /dev/null diff --git a/com/gmail/bernabe/__init__.py b/com/gmail/bernabe/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/com/gmail/bernabe/__init__.py +++ /dev/null diff --git a/com/gmail/bernabe/laurent/__init__.py b/com/gmail/bernabe/laurent/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/com/gmail/bernabe/laurent/__init__.py +++ /dev/null diff --git a/com/gmail/bernabe/laurent/sugar_olpc/__init__.py b/com/gmail/bernabe/laurent/sugar_olpc/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/com/gmail/bernabe/laurent/sugar_olpc/__init__.py +++ /dev/null diff --git a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/__init__.py b/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/__init__.py +++ /dev/null diff --git a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/gui/InputDialog.py b/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/gui/InputDialog.py deleted file mode 100644 index fc06d01..0000000 --- a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/gui/InputDialog.py +++ /dev/null @@ -1,53 +0,0 @@ -''' -Created on 13 mai 2011 - -@author: laurent_bernabe -''' - -import pygtk -pygtk.require('2.0') -import gtk - -class InputDialog(gtk.MessageDialog): - ''' - Creates an input dialog with - => a label (for the prompt) - => a text entry - => ok_button and cancel_button - ''' - - - def __init__(self, prompt, parent=None): - ''' - Constructor(prompt, parent=None) - prompt argument : the text of the dialog - parent : the parent control - ''' - gtk.MessageDialog.__init__(self, - parent, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, - gtk.BUTTONS_OK_CANCEL, prompt) - self.__entry = gtk.Entry() - self.vbox.pack_start(self.__entry, True, True, 0) - self.connect("delete-event", lambda widget, event : self.__close() ) - - def run(self): - ''' - Run() - Runs the dialog - ''' - self.show_all() - response = super(InputDialog,self).run() - if response == gtk.RESPONSE_OK : - text = self.__entry.get_text() - else : - text = None - self.destroy() - return text - - def __close(self): - ''' - __close() - Closes the dialog and returns None - ''' - self.destroy() - return None \ No newline at end of file diff --git a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/gui/__init__.py b/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/gui/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/gui/__init__.py +++ /dev/null diff --git a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/pure_pygtk_launcher/PurePyGTKLauncher.py b/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/pure_pygtk_launcher/PurePyGTKLauncher.py deleted file mode 100644 index 204552d..0000000 --- a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/pure_pygtk_launcher/PurePyGTKLauncher.py +++ /dev/null @@ -1,12 +0,0 @@ -''' -Created on 10 mai 2011 - -@author: laurent_bernabe -''' - -import gtk -from com.gmail.bernabe.laurent.sugar_olpc.learning_writing.pure_pygtk_launcher.TheWindow import TheWindow - -if __name__ == '__main__': - TheWindow() - gtk.main() \ No newline at end of file diff --git a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/pure_pygtk_launcher/__init__.py b/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/pure_pygtk_launcher/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/pure_pygtk_launcher/__init__.py +++ /dev/null diff --git a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/sugar_launcher/__init__.py b/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/sugar_launcher/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/com/gmail/bernabe/laurent/sugar_olpc/learning_writing/sugar_launcher/__init__.py +++ /dev/null -- cgit v0.9.1