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
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):
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()
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:
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()
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)
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)
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)
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):