diff options
author | Florent Pigout <florent.pigout@gmail.com> | 2011-10-17 21:13:56 (GMT) |
---|---|---|
committer | Florent Pigout <florent.pigout@gmail.com> | 2011-10-17 21:13:56 (GMT) |
commit | 853fad71dd7f0cdc7d5c221b9fdb9eee39efb0b1 (patch) | |
tree | 64aa2aff1ed357bc9b73bf6ce8d309c9bda1a6f6 | |
parent | b9e4c79d12cb003e0e4a712d7be7ab9a4a06f7d6 (diff) |
restore simple save/load `atoidejouer` journal entry feature
-rw-r--r-- | activity.py | 58 | ||||
-rw-r--r-- | atoidejouer/db/story.py | 10 |
2 files changed, 28 insertions, 40 deletions
diff --git a/activity.py b/activity.py index 8ccacb9..42e28c1 100644 --- a/activity.py +++ b/activity.py @@ -130,9 +130,6 @@ class AToiDeJouerActivity(activity.Activity): self.max_time = 0 # show self._toolbox.show() - # tmp var - _toolbar = None - self.__story_toolbar = None # init toolbars for _n in ['story', 'edit', 'help']: # init toolbar @@ -255,47 +252,34 @@ class AToiDeJouerActivity(activity.Activity): self._update_slider(toolbar) def read_file(self, file_path): - pass - """ - # init content - _data = None - # read file - _file = open(file_path, 'r') + # close db + story.DB().close() + # save content + _f_in = open(file_path) + _f_ou = open(storage.get_db_path('default'), 'wb') try: - _data = _file.read() + _f_ou.write(_f_in.read()) finally: - _file.close() - # parse json data - # self.graphic_keys.loads(_data) - # self.sound_keys.loads(_data) - # set activity new number of keys - # self.update_max_time() - # clear - # self.graphic_keys.ask_clear() - # switch to edit mode if no key - self._toolbox.set_current_toolbar(1) - self._change_screen(toolbar=self.__story_toolbar) - """ + _f_in.close() + _f_ou.close() + # reload db + story.DB(force=True) + # update max time + self.update_max_time() def write_file(self, file_path): - pass - """ - # content dict - _data_dict = { - 'graphic_names': self.graphic_keys._names, - 'graphic_keys': self.graphic_keys._keys, - 'sound_names': self.sound_keys._names, - 'sound_keys': self.sound_keys._keys, - } - # prepare content - _data = json.dumps(_data_dict) + # close db + story.DB().close() # save content - _f = open(file_path, 'wb') + _f_in = open(storage.get_db_path('default')) + _f_ou = open(file_path, 'wb') try: - _f.write(_data) + _f_ou.write(_f_in.read()) finally: - _f.close() - """ + _f_in.close() + _f_ou.close() + # reload db + story.DB(force=True) def close(self, skip_save=False): # stop the thread diff --git a/atoidejouer/db/story.py b/atoidejouer/db/story.py index d10cd87..426baa1 100644 --- a/atoidejouer/db/story.py +++ b/atoidejouer/db/story.py @@ -287,20 +287,19 @@ class DB(object): def __create(self): cur = self.con.cursor() - # remove all first try: cur.execute("drop table %s" % self.name) except Exception, e: pass - # create fresh db cur.execute(self.obj().create()) - # and close + self.con.commit() cur.close() def add(self, obj): cur = self.con.cursor() cur.execute(obj.insert()) count = cur.rowcount + self.con.commit() cur.close() return count @@ -345,6 +344,7 @@ class DB(object): cur = self.con.cursor() cur.execute(obj.update()) rowcount = cur.rowcount + self.con.commit() cur.close() return rowcount @@ -353,9 +353,13 @@ class DB(object): obj = self.obj() if obj is None else obj cur.execute(obj.delete(all=all)) rowcount = cur.rowcount + self.con.commit() cur.close() return rowcount + def close(self): + self.con.close() + # singleton instance instance = None |