class LoggedIn(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title='Profile') self.set_size_request(200, 150) self.set_decorated(False) self.set_position(Gtk.WindowPosition.CENTER) self.set_resizable(False) self.ok_button = KanoButton(_("OK")) self.ok_button.pack_and_align() self.ok_button.set_padding(20, 20, 0, 0) self.ok_button.connect("clicked", Gtk.main_quit) self.title = Heading(_("Logged in!"), _("You're already logged in")) self.main_container = Gtk.Box( orientation=Gtk.Orientation.VERTICAL, spacing=0) self.add(self.main_container) self.main_container.pack_start(self.title.container, False, False, 0) self.main_container.pack_start(self.ok_button.align, False, False, 0) # To get a logout button, uncomment out the lines below #self.logout_button = OrangeButton(_("Log out?")) #self.logout_button.connect("clicked", self.logout) #self.main_container.pack_start(self.logout_button, False, False, 0) self.connect('delete-event', Gtk.main_quit) self.show_all() def logged_out_screen(self): for child in self.main_container: self.main_container.remove(child) self.title.set_text(_("Logged out!"), "") self.main_container.pack_start(self.title.container, False, False, 0) self.main_container.pack_start(self.alignment, False, False, 0) def logout(self, event): remove_token() self.logged_out_screen() def close_window(self, event, button, win): self.ok_button.disconnect_handlers() cursor.arrow_cursor(None, None, win) Gtk.main_quit()
class LoggedIn(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title='Profile') self.set_size_request(200, 150) self.set_decorated(False) self.set_position(Gtk.WindowPosition.CENTER) self.set_resizable(False) self.ok_button = KanoButton(_("OK")) self.ok_button.pack_and_align() self.ok_button.set_padding(20, 20, 0, 0) self.ok_button.connect('clicked', Gtk.main_quit) self.title = Heading(_("Logged in!"), _("You're already logged in")) self.main_container = Gtk.Box( orientation=Gtk.Orientation.VERTICAL, spacing=0) self.add(self.main_container) self.main_container.pack_start(self.title.container, False, False, 0) self.main_container.pack_start(self.ok_button.align, False, False, 0) # To get a logout button, uncomment out the lines below #self.logout_button = OrangeButton(_("Log out?")) #self.logout_button.connect('clicked', self.logout) #self.main_container.pack_start(self.logout_button, False, False, 0) self.connect('delete-event', Gtk.main_quit) self.show_all() def logged_out_screen(self): for child in self.main_container: self.main_container.remove(child) self.title.set_text(_("Logged out!"), "") self.main_container.pack_start(self.title.container, False, False, 0) self.main_container.pack_start(self.alignment, False, False, 0) def logout(self, event): remove_token() self.logged_out_screen() def close_window(self, event, button, win): self.ok_button.disconnect_handlers() cursor.arrow_cursor(None, None, win) Gtk.main_quit()
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)