def unlock(self): notepad = store.get_value("notepad") decrypted_notes = decrypt(notepad["notes"], self.password_entry.get_text()) if decrypted_notes == None: dialog = Gtk.MessageDialog(transient_for=self.get_toplevel(), message_type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.OK, text="Bad Decrypt") dialog.format_secondary_text( "You may have entered an incorrect password.") dialog.run() dialog.destroy() self.password_entry.set_text("") else: notepad["notes"] = loads(decrypted_notes) store.set_value("password", self.password_entry.get_text()) store.set_value("notepad", notepad) store.get_value("notepad_editor").open_notepad() store.get_value("stack").set_visible_child_name("notepad_editor")
def create_notepad(self): password = self.password_entry.get_text() if password != self.password_copy_entry.get_text(): dialog = Gtk.MessageDialog(transient_for=self.get_toplevel(), message_type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.OK, text="Cannot Create Notepad") dialog.format_secondary_text("Passwords do not match.") dialog.run() dialog.destroy() elif len(password) < 8: dialog = Gtk.MessageDialog(transient_for=self.get_toplevel(), message_type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.OK, text="Cannot Create Notepad") dialog.format_secondary_text( "Passwords must be at least 8 characters long.") dialog.run() dialog.destroy() else: store.set_value("password", password) store.set_value( "notepad", { "untitled_number": 1, "notes": [{ "name": "Untitled Note 1", "content": "Your first note." }] }) self.clear() store.get_value("notepad_editor").open_notepad() store.get_value("stack").set_visible_child_name("notepad_editor")
def delete_note(self): if len(store.get_value("notepad")["notes"]) > 1: dialog = Gtk.MessageDialog( transient_for=self.get_toplevel(), message_type=Gtk.MessageType.QUESTION, buttons=Gtk.ButtonsType.YES_NO, text="Delete Note" ) dialog.format_secondary_text("Are you sure you want to delete this note?") response = dialog.run() dialog.destroy() if response == Gtk.ResponseType.YES: notepad = store.get_value("notepad") del notepad["notes"][self.notebook.get_current_page()] self.notebook.remove_page(self.notebook.get_current_page()) store.set_value("notepad", notepad) else: dialog = Gtk.MessageDialog( transient_for=self.get_toplevel(), message_type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.OK, text="Cannot Delete Note" ) dialog.format_secondary_text("You cannot delete the final note.") dialog.run() dialog.destroy()
def load_notepad(self): file_chooser = Gtk.FileChooserDialog( title="Encpad", parent=self.get_toplevel(), action=Gtk.FileChooserAction.OPEN, buttons=("Cancel", Gtk.ResponseType.CANCEL, "Open", Gtk.ResponseType.OK)) response = file_chooser.run() filename = file_chooser.get_filename() file_chooser.destroy() if response == Gtk.ResponseType.OK: try: with open(filename, "r") as file: parsed_notepad = loads( b64decode( bytes( file.read().replace( store.get_value("ENCRYPTED_DISCLAIMER"), "", 1), "utf-8")).decode("utf-8")) if parsed_notepad["version"] != store.get_value("VERSION"): dialog = Gtk.MessageDialog( transient_for=self.get_toplevel(), message_type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.YES_NO, text="Version Mismatch") dialog.format_secondary_text( ("This notepad was saved in version %s, " + "but you are using %s.\n" + "Are you sure you want to proceed? " + "Doing so may cause notepad corruption.") % (parsed_notepad["version"], store.get_value("VERSION"))) response = dialog.run() dialog.destroy() if response == Gtk.ResponseType.NO: return store.set_value("notepad", parsed_notepad) store.get_value("stack").set_visible_child_name( "unlock_notepad") except Exception: dialog = Gtk.MessageDialog( transient_for=self.get_toplevel(), message_type=Gtk.MessageType.WARNING, buttons=Gtk.ButtonsType.OK, text="Loading Failed") dialog.format_secondary_text("Could not load notepad!") response = dialog.run() dialog.destroy()
def __init__(self): Gtk.Window.__init__(self, title="Encpad") store.set_value("password", None) store.set_value("notepad", None) self.set_border_width(20) self.set_default_size(360, 560) self.set_resizable(False) stack = Gtk.Stack() stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT) stack.set_transition_duration(350) store.set_value("stack", stack) store.set_value("notepad_editor", NotepadEditor()) stack.add_named(Welcome(), "welcome") stack.add_named(UnlockNotepad(), "unlock_notepad") stack.add_named(CreateNewNotepad(), "create_new_notepad") stack.add_named(store.get_value("notepad_editor"), "notepad_editor") stack.set_visible_child_name("welcome") self.connect("delete-event", self.window_delete) self.add(stack)
def new_note(self): untitled_number = store.get_value("notepad")["untitled_number"] + 1 store.get_value("notepad")["untitled_number"] += 1 note = { "name": "Untitled Note %d" % untitled_number, "content": "A new note" } index = self.init_editor(note) store.get_value("notepad")["notes"].append(note) store.set_value("confirm_close", True) self.notebook.set_current_page(index)
import gi gi.require_version("Gtk", "3.0") from gi.repository import Gtk from store import store from create_new_notepad import CreateNewNotepad from notepad_editor import NotepadEditor from unlock_notepad import UnlockNotepad from welcome import Welcome store.set_value("VERSION", "0.1.0-beta") store.set_value( "ENCRYPTED_DISCLAIMER", "[DANGER]\n" + "This file is ENCRYPTED. It must be opened in Encpad " + "(or a compatible editor/viewer)!\n" + "Do NOT edit this file in a normal text editor -- " + "doing so may cause permanent data loss!\n" + "-=-=-=-=-=-=-=-=-=-=-=-\n") def dialog(window, message_type, buttons, title, message): dialog = Gtk.MessageDialog(transient_for=window, message_type=message_type, buttons=buttons, text=title) dialog.format_secondary_text(message) dialog.run() dialog.destroy()
def text_changed(self, text_view): self.note["content"] = self.buffer.get_text( self.buffer.get_start_iter(), self.buffer.get_end_iter(), True) store.set_value("confirm_close", True)
def name_changed(self, entry): self.note["name"] = self.name_entry.get_text() self.on_name_updated(self.note["name"]) store.set_value("confirm_close", True)