def __init__(self, parent): table, self.dialog = create_table_dialog(parent, "Save from memory", 3, 2) self.file = FselEntry(self.dialog) table_add_widget_row(table, 0, "File name:", self.file.get_container()) self.address = table_add_entry_row(table, 1, "Save address:", 6) self.address.connect("activate", dialog_apply_cb, self.dialog) self.length = table_add_entry_row(table, 2, "Number of bytes:", 6) self.length.connect("activate", dialog_apply_cb, self.dialog)
def _create_dialog(self, config): paths = config.get_paths() table, self.dialog = create_table_dialog(self.parent, "File path settings", len(paths), 2) paths.sort() row = 0 self.paths = [] for (key, path, label) in paths: fsel = FselEntry(self.dialog, self._validate_fname, key) fsel.set_filename(path) self.paths.append((key, fsel)) table_add_widget_row(table, row, label, fsel.get_container()) row += 1 table.show_all()
class SaveDialog: def __init__(self, parent): table, self.dialog = create_table_dialog(parent, "Save from memory", 3, 2) self.fsel = FselEntry(self.dialog, "Memory save file name:") table_add_widget_row(table, 0, 0, "File name:", self.fsel.get_container()) self.address = table_add_entry_row(table, 1, 0, "Save address:", 6) self.address.connect("activate", dialog_apply_cb, self.dialog) self.length = table_add_entry_row(table, 2, 0, "Number of bytes:", 6) self.length.connect("activate", dialog_apply_cb, self.dialog) def run(self, address): "run(address) -> (filename,address,length), all as strings" if address: self.address.set_text("%06X" % address) self.dialog.show_all() filename = length = None while 1: response = self.dialog.run() if response == Gtk.ResponseType.APPLY: filename = self.fsel.get_filename() address_txt = self.address.get_text() length_txt = self.length.get_text() if filename and address_txt and length_txt: try: address = int(address_txt, 16) except ValueError: ErrorDialog( self.dialog).run("address needs to be in hex") continue try: length = int(length_txt) except ValueError: ErrorDialog( self.dialog).run("length needs to be a number") continue if os.path.exists(filename): question = "File:\n%s\nexists, replace?" % filename if not AskDialog(self.dialog).run(question): continue break else: ErrorDialog(self.dialog).run("please fill the field(s)") else: break self.dialog.hide() return (filename, address, length)
class SaveDialog: def __init__(self, parent): table, self.dialog = create_table_dialog(parent, "Save from memory", 3, 2) self.file = FselEntry(self.dialog) table_add_widget_row(table, 0, "File name:", self.file.get_container()) self.address = table_add_entry_row(table, 1, "Save address:", 6) self.address.connect("activate", dialog_apply_cb, self.dialog) self.length = table_add_entry_row(table, 2, "Number of bytes:", 6) self.length.connect("activate", dialog_apply_cb, self.dialog) def run(self, address): "run(address) -> (filename,address,length), all as strings" if address: self.address.set_text("%06X" % address) self.dialog.show_all() filename = length = None while 1: response = self.dialog.run() if response == gtk.RESPONSE_APPLY: filename = self.file.get_filename() address_txt = self.address.get_text() length_txt = self.length.get_text() if filename and address_txt and length_txt: try: address = int(address_txt, 16) except ValueError: ErrorDialog(self.dialog).run("address needs to be in hex") continue try: length = int(length_txt) except ValueError: ErrorDialog(self.dialog).run("length needs to be a number") continue if os.path.exists(filename): question = "File:\n%s\nexists, replace?" % filename if not AskDialog(self.dialog).run(question): continue break else: ErrorDialog(self.dialog).run("please fill the field(s)") else: break self.dialog.hide() return (filename, address, length)