+def validate():
+ return True
+
+
+class Dialog(Toplevel):
+ """
+ Adapted from http://www.effbot.org/tkinterbook/tkinter-dialog-windows.htm
+ """
+
+ def __init__(self, parent: Frame, title=None):
+ Toplevel.__init__(self, parent)
+ self.transient(parent)
+ if title:
+ self.title(title)
+ self.parent = parent
+ self.result = None
+ body = Frame(self)
+ self.initial_focus = self.body(body)
+ body.pack(padx=5, pady=5)
+ self.buttonbox()
+ self.grab_set()
+ if not self.initial_focus:
+ self.initial_focus = self
+ self.protocol("WM_DELETE_WINDOW", self.cancel)
+ self.geometry(
+ "+%d+%d" % (parent.winfo_rootx() + 600, parent.winfo_rooty() + 400)
+ )
+ self.initial_focus.focus_set()
+ self.wait_window(self)
+
+ def body(self, master):
+ raise NotImplementedError()
+
+ # noinspection PyAttributeOutsideInit
+ def buttonbox(self):
+ box = Frame(self)
+ self.accept = Button(
+ box,
+ text="Accept",
+ width=10,
+ state=DISABLED,
+ command=self.ok,
+ default=ACTIVE,
+ )
+ self.accept.pack(side=LEFT, padx=5, pady=5)
+ self.decline = Button(
+ box, text="Decline", width=10, state=DISABLED, command=self.cancel
+ )
+ self.decline.pack(side=LEFT, padx=5, pady=5)
+ self.bind("<Return>", self.ok)
+ self.bind("<Escape>", self.cancel)
+ box.pack()
+
+ # noinspection PyUnusedLocal
+ def ok(self, event=None):
+ if not validate():
+ self.initial_focus.focus_set() # put focus back
+ return
+ self.withdraw()
+ self.update_idletasks()
+ self.apply()
+ self.cancel()
+
+ # noinspection PyUnusedLocal
+ def cancel(self, event=None):
+ self.parent.focus_set()
+ self.destroy()
+
+ def apply(self):
+ raise NotImplementedError()
+
+ def activate_buttons(self):
+ self.accept.configure(state=NORMAL)
+ self.decline.configure(state=NORMAL)
+
+
+class TermsAndConditionsDialog(Dialog):
+ def __init__(self, parent, config: Config):
+ self.config = config
+ self.parent = parent
+ super().__init__(parent, config.terms_popup_title)
+
+ def body(self, master):
+ Label(master, text=self.config.terms_popup_message).grid(row=0, pady=5)
+ tc_link = Label(
+ master, text=self.config.terms_link_text, fg="blue", cursor="hand2"
+ )
+ ValidatorApp.underline(tc_link)
+ tc_link.bind("<Button-1>", self.open_terms)
+ tc_link.grid(row=1, pady=5)
+
+ # noinspection PyUnusedLocal
+ def open_terms(self, event):
+ webbrowser.open(self.config.terms_link_url)
+ self.activate_buttons()
+
+ def apply(self):
+ self.config.set_terms_accepted()
+
+