From: <cl...@us...> - 2003-03-11 03:41:44
|
Update of /cvsroot/todo-manager/todo-manager In directory sc8-pr-cvs1:/tmp/cvs-serv13083 Modified Files: ChangeLog.txt interface.py main.py optionsdialog.py Log Message: Erik I. Bolsø suggested that an option should be added that enables autosave, this commit adds an option that enables saving a backup of the active task list everytime something changes. This works better for crash recovery. Once the user is done with the active list (quits, opens another file) the backup is removed. These backups are stored the the user's (.)todo-manager directory and the filename will begin with 'tmp'. Index: ChangeLog.txt =================================================================== RCS file: /cvsroot/todo-manager/todo-manager/ChangeLog.txt,v retrieving revision 1.37 retrieving revision 1.38 diff -u -d -r1.37 -r1.38 --- ChangeLog.txt 9 Mar 2003 17:18:13 -0000 1.37 +++ ChangeLog.txt 11 Mar 2003 03:41:40 -0000 1.38 @@ -1,5 +1,9 @@ ToDo Manager Change Log +latest: + * Added an option that saves a backup of the current task list in the + user's (.)todo-manager directory for crash recovery + Version 0.70.1 (03/08/2003): * Task group listings are now correct after opening a file Index: interface.py =================================================================== RCS file: /cvsroot/todo-manager/todo-manager/interface.py,v retrieving revision 1.40 retrieving revision 1.41 diff -u -d -r1.40 -r1.41 --- interface.py 9 Mar 2003 20:00:14 -0000 1.40 +++ interface.py 11 Mar 2003 03:41:40 -0000 1.41 @@ -385,6 +385,7 @@ dlg.set_option("loadplugins", app.get_setting("Core", "loadplugins", 2)) dlg.set_option("plugin_info", app.get_plugin_info()) dlg.set_option("timeformat", app.get_setting("Core", "timeformat", '')) + dlg.set_option("savebackup", app.get_setting("Core", "savebackup", FALSE)) dlg.set_option("savewinposition", app.get_setting(CONF_SECTION, "savewinposition", TRUE)) dlg.set_option("savewinsize", app.get_setting(CONF_SECTION, "savewinsize", TRUE)) @@ -420,6 +421,7 @@ app.save_setting("Core", "webbrowser", dlg.get_option("webbrowser", '')) app.save_setting("Core", "loadplugins", dlg.get_option("loadplugins", 2)) app.save_setting("Core", "timeformat", dlg.get_option("timeformat", '')) + app.save_setting("Core", "savebackup", dlg.get_option("savebackup", FALSE)) app.save_setting(CONF_SECTION, "savewinposition", dlg.get_option("savewinposition", 0)) app.save_setting(CONF_SECTION, "savewinsize", dlg.get_option("savewinsize", 0)) Index: main.py =================================================================== RCS file: /cvsroot/todo-manager/todo-manager/main.py,v retrieving revision 1.71 retrieving revision 1.72 diff -u -d -r1.71 -r1.72 --- main.py 9 Mar 2003 18:48:12 -0000 1.71 +++ main.py 11 Mar 2003 03:41:40 -0000 1.72 @@ -7,7 +7,7 @@ # The core application calls import locale -import os, sys +import os, sys, time # Set the locale to the user's setting try: @@ -64,12 +64,12 @@ self.__options = {} self.__config_file = None self.__default_file = None + self.__tmpfile = None # See if the program should continue executing after the args have been read if not parse_args(sys.argv[1:]): sys.exit(0) - # Get the config file and the default file wkdir = None userdir = get_user_directory() @@ -151,6 +151,8 @@ # Tell the interfaces that there is a new item self.interface_call(ALL, "insert_list_item", name) + self.__save_tmpfile() + self.__file_modified = TRUE return TRUE @@ -232,6 +234,8 @@ if key == "Group": self.interface_call(ALL, "update_list_groups", self.__get_task_groups()) + self.__save_tmpfile() + self.__file_modified = TRUE return TRUE @@ -283,6 +287,8 @@ self.interface_call(ALL, "remove_list_item", name) self.interface_call(ALL, "update_list_groups", self.__get_task_groups()) + self.__save_tmpfile() + self.__file_modified = TRUE return TRUE @@ -303,6 +309,8 @@ self.__current_file = None self.__file_modified = FALSE + self.__clear_tmpfile() + self.interface_call(ALL, "clear_list_items") self.interface_call(ALL, "update_list_groups", []) self.interface_call(ALL, "set_current_filename", _("Untitled")) @@ -378,6 +386,25 @@ for t in tasks: tf.save_task(t) + def __save_tmpfile(self): + if self.get_setting("Core", "savebackup", FALSE): + if not self.__tmpfile: + # Generate a temp filename + tmp = "tmp%d.tmf" %int(time.time()) + self.__tmpfile = os.path.join(get_user_directory(), tmp) + + # Write the file + file = open(self.__tmpfile, 'w') + self.__save_file(self.__dup_task_list(), file) + file.close() + + def __clear_tmpfile(self): + if self.__tmpfile: + if os.path.isfile(self.__tmpfile): + # Remove the file + os.remove(self.__tmpfile) + self.__tmpfile = None + def do_file_open(self, filename=None, ui=None): self.__ext_load_file(filename=filename, ui=ui) @@ -428,6 +455,8 @@ self.__file_modified = FALSE + self.__clear_tmpfile() + self.interface_call(ALL, "update_list_items", self.__get_task_names()) self.interface_call(ALL, "update_list_groups", self.__get_task_groups()) @@ -920,6 +949,8 @@ def __quit(self): """Stop all proccesses, save the configuration file, and destroy all task instances.""" + + self.__clear_tmpfile() if _load_config: self.__save_config() Index: optionsdialog.py =================================================================== RCS file: /cvsroot/todo-manager/todo-manager/optionsdialog.py,v retrieving revision 1.8 retrieving revision 1.9 diff -u -d -r1.8 -r1.9 --- optionsdialog.py 16 Dec 2002 22:24:33 -0000 1.8 +++ optionsdialog.py 11 Mar 2003 03:41:40 -0000 1.9 @@ -540,18 +540,28 @@ def load(self): self.format = StringVar() + self.savebackup = IntVar() self.format.set(get_option("timeformat", "")) + self.savebackup.set(get_option("savebackup", FALSE)) def close(self): set_option("timeformat", self.format.get()) + set_option("savebackup", self.savebackup.get()) return TRUE def body(self): Label(self, text=_("Date and Time Format"), font=section_font).grid(row=0, sticky=W) - frame = Frame(self) Label(frame, text=_("Format:")).grid(row=0, column=0, sticky=W) entry = Entry(frame, width=22, textvariable=self.format).grid(row=0, column=1, sticky=W) frame.grid(row=1, ipadx=15, sticky=W) + + self._spacer(self) + + Label(self, text=_("File Options"), font=section_font).grid(row=3, sticky=W) + frame = Frame(self) + Checkbutton(frame, text=_("Save backup files (for crash recovery)"), + variable=self.savebackup).grid(row=0, column=0, sticky=W) + frame.grid(row=4, ipadx=15, sticky=W) |