def import_files(self, event): dialog = wx.DirDialog(self, 'Select directory', style=wx.DD_DIR_MUST_EXIST) if dialog.ShowModal() == wx.ID_OK: path = dialog.GetPath() dialog = wx.TextEntryDialog(self, 'Enter name for imported mod', 'Import mod', '') if dialog.ShowModal() == wx.ID_OK: name = dialog.GetValue() fname = encode_filename(name) dialog1 = ProgressDialog(self, 'Importing mod') dialog2 = ProgressDialog(self, 'Saving .dfmod') def process(): try: mod_dataset = decode_directory(path, callback=dialog1) mod = Mod(name, os.path.join('mods', fname), self.core_dataset, self.core_dataset.difference(mod_dataset)) encode_mod(mod, callback=dialog2) except: self.show_current_exception() dialog1.Close() dialog2.Close() self.reload_mods() thread_wrapper(process)()
def save(self, event, exit=False): if self.mod: self.mod.objects = self.objects dialog = ProgressDialog(self, 'Saving mod') # All this must be in the other thread so it doesn't get out of order def process(): if self.mod: # Working from a .dfmod file encode_mod(self.mod, overwrite=True, callback=dialog) else: # Working in standalone mode if os.path.isdir(self.path): encode_objects(self.objects, self.path, callback=dialog) else: dir, fname = os.path.split(self.path) encode_objects(self.objects, dir, callback=dialog) self.unsaved_changes = False if self.parent: self.parent.reload_mods(progress=False) if exit: self.Close(True) thread_wrapper(process)()