From: Jakob Cornell Date: Mon, 13 Jan 2020 01:46:25 +0000 (-0600) Subject: Fix save confirmation bug, UX refinements X-Git-Url: https://jcornell.net/gitweb/gitweb.cgi?a=commitdiff_plain;h=e240132fc63eb1f2d4b43c34b4ae19ff7b861f60;p=tutoring-tool.git Fix save confirmation bug, UX refinements --- diff --git a/main.py b/main.py index 8ceae69..14e9c26 100644 --- a/main.py +++ b/main.py @@ -129,7 +129,7 @@ class MainModel(Model): self.state_mgr = state_mgr state = self.state_mgr.load() self.state = state or new_app_state() - if self.state['student'] is not None and self.state['student'] not in self.data: + if self.state['student'] not in self.data: self.state['student'] = None self.saved = False @@ -137,6 +137,8 @@ class MainModel(Model): def on_linked(self): self.view.set_student_list(self.view_names()) + if self.state['student'] is None and self.data: + self.select_auto() self.view.set_student(self.state['student']) def view_names(self): @@ -146,14 +148,14 @@ class MainModel(Model): if name in self.data: raise ValueError() else: - self.data[name] = [] self.dirty = True + self.data[name] = [] self.view.set_student_list(self.view_names()) self.view.update_controls() def delete_student(self, name): - del self.data[name] self.dirty = True + del self.data[name] self.view.set_student_list(self.view_names()) if self.state['student'] == name: self.select_auto() @@ -161,6 +163,7 @@ class MainModel(Model): def rename_student(self, curr_name, new_name): if new_name != curr_name: + self.dirty = True if new_name in self.data: raise ValueError("Name already in use") else: @@ -207,14 +210,23 @@ class MainView(View): self.root.title("Tutoring Tool") self.root.resizable(False, False) + def on_save_err(): + messagebox.showerror("Error", "Error saving data") + def on_close(): + self.controller.save_state() if self.editor_views: next(iter(self.editor_views.values())).root.lift() elif self.controller.dirty: result = messagebox.askyesnocancel("Confirm", "You have unsaved changes. Save before exiting?") if result is True: - self.controller.save_state() - if result is not None: + try: + self.controller.save_data() + except: + on_save_err() + else: + self.root.destroy() + elif result is False: self.root.destroy() else: self.root.destroy() @@ -224,7 +236,7 @@ class MainView(View): try: self.controller.save_data() except: - messagebox.showerror("Error", "Error saving data") + on_save_err() menu = tk.Menu(self.root) self.root.config(menu = menu) file_menu = tk.Menu(menu, tearoff = 0) @@ -243,7 +255,7 @@ class MainView(View): self.student_sel.configure(width = 25) def on_student_add(): - result = simpledialog.askstring("New student", "Name") + result = simpledialog.askstring("New student", "Name:") if result: try: self.controller.add_student(result) @@ -253,7 +265,10 @@ class MainView(View): def on_student_rename(): curr = self.controller.current_student() - name = simpledialog.askstring("Rename student", "New name for {}".format(curr)) + name = simpledialog.askstring( + "Rename student", "New name for {}:".format(curr), + initialvalue = curr, + ) if name: try: self.controller.rename_student(curr, name) @@ -568,8 +583,9 @@ class DataEditView(View): class DataEditController(Controller): def update_data(self, records): + differ = records != self.base_model.data[self.student_name] self.base_model.data[self.student_name] = records - self.base_model.dirty = True + self.base_model.dirty = differ class VertScrollingFrame(tk.Frame):