class ResetPassword(Gtk.Box): def __init__(self, win): Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL) self.win = win self.win.set_decorated(False) self.win.set_main_widget(self) self.heading = Heading( _("Reset your password"), _("We'll send a new password to your email") ) self.pack_start(self.heading.container, False, False, 10) self.labelled_entries = LabelledEntries([ {"heading": _("Email"), "subheading": ""} ]) align = Gtk.Alignment(xscale=0, xalign=0.5) self.pack_start(align, False, False, 15) self.labelled_entries.set(0, 0, 1, 1) self.labelled_entries.set_hexpand(True) align.add(self.labelled_entries) # Read email from file user_email = get_email() self.email_entry = self.labelled_entries.get_entry(0) self.email_entry.set_text(user_email) self.email_entry.connect("key-release-event", self.activate) self.button = KanoButton(_("Reset password").upper()) self.button.pack_and_align() self.button.connect("button-release-event", self.activate) self.button.connect("key-release-event", self.activate) self.button.set_padding(30, 30, 0, 0) self.pack_start(self.button.align, False, False, 0) self.win.show_all() def activate(self, widget, event): if not hasattr(event, 'keyval') or event.keyval == 65293: watch_cursor = Gdk.Cursor(Gdk.CursorType.WATCH) self.win.get_window().set_cursor(watch_cursor) self.button.set_sensitive(False) self.button.start_spinner() thread = threading.Thread(target=self.send_new_password) thread.start() def send_new_password(self): # User may change email email = self.labelled_entries.get_entry(0).get_text() success, text = reset_password(email) if success: title = _("Success!") description = _("Sent new password to your email") button_dict = { _("Go to login screen").upper(): {"return_value": 12}, _("Quit").upper(): {"return_value": 10, "color": "red"} } else: title = _("Something went wrong!") description = text button_dict = { _("Quit").upper(): {"return_value": 10, "color": "red"}, _("Try again").upper(): {"return_value": 11} } GObject.idle_add( self.finished_thread_cb, title, description, button_dict ) def finished_thread_cb(self, title, description, button_dict): kdialog = KanoDialog( title, description, button_dict=button_dict, parent_window=self.win ) response = kdialog.run() self.win.get_window().set_cursor(None) self.button.stop_spinner() self.button.set_sensitive(True) if response == 10: Gtk.main_quit() # stay put elif response == 11: pass elif response == 12: self.go_to_login_screen() def go_to_login_screen(self): self.win.remove_main_widget() Login(self.win)
class RecoverUsername(Gtk.Box): def __init__(self, win): Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL) self.win = win self.win.set_decorated(False) self.win.set_main_widget(self) self.heading = Heading(_("Forgotten your username"), _("We'll send a reminder to your email")) self.pack_start(self.heading.container, False, False, 10) self.labelled_entries = LabelledEntries([{ 'heading': _("Email"), 'subheading': "" }]) align = Gtk.Alignment(xscale=0, xalign=0.5) self.pack_start(align, False, False, 15) self.labelled_entries.set(0, 0, 1, 1) self.labelled_entries.set_hexpand(True) align.add(self.labelled_entries) self.email_entry = self.labelled_entries.get_entry(0) self.email_entry.set_text("") self.email_entry.connect('key-release-event', self.activate) self.button = KanoButton(_("REQUEST REMINDER")) self.button.pack_and_align() self.button.connect('button-release-event', self.activate) self.button.connect('key-release-event', self.activate) self.button.set_padding(30, 30, 0, 0) self.pack_start(self.button.align, False, False, 0) self.email_entry.grab_focus() self.win.show_all() def activate(self, widget, event): if not hasattr(event, 'keyval') or event.keyval == 65293: watch_cursor = Gdk.Cursor(Gdk.CursorType.WATCH) self.win.get_window().set_cursor(watch_cursor) self.button.set_sensitive(False) self.button.start_spinner() thread = threading.Thread(target=self.send_new_password) thread.start() def send_new_password(self): # User may change email email = self.labelled_entries.get_entry(0).get_text() success, text = recover_username(email) if success: title = _("Success!") description = _("Sent a reminder to your email") button_dict = { _("GO TO LOGIN SCREEN"): { 'return_value': 12 }, _("QUIT"): { 'return_value': 10, 'color': 'red' } } else: title = _("Something went wrong!") description = text button_dict = { _("QUIT"): { 'return_value': 10, 'color': 'red' }, _("TRY AGAIN"): { 'return_value': 11 } } GObject.idle_add(self.finished_thread_cb, title, description, button_dict) def finished_thread_cb(self, title, description, button_dict): kdialog = KanoDialog(title, description, button_dict=button_dict, parent_window=self.win) response = kdialog.run() self.win.get_window().set_cursor(None) self.button.stop_spinner() self.button.set_sensitive(True) if response == 10: Gtk.main_quit() # stay put elif response == 11: pass elif response == 12: self.go_to_login_screen() def go_to_login_screen(self): self.win.remove_main_widget() Login(self.win)