def collection_append(self, mod_name, mod_id, hash_key=None): """ Функция находит все переводимые файлы выбранной модификации, создает для каждого временную папку в Коллекции и сохраняет данные в базу данных """ mod_path = get_mods_from_playset('get_mod_path', mod_name)[0][0].replace('/', '\\') images = get_info_from_db('get_images', ()) for image_data in images: if image_data[2] == mod_id: hash_key = image_data[0] break archive = [file for file in listdir(mod_path) if '.zip' in file] if archive: open_zip_file(f'{mod_path}\\{archive[0]}') try: for file_path in scan_for_files(mod_path): parser_main(mod_path, mod_id, file_path) collection_append(mod_id, hash_key, mod_name) message = 'files_was_added' call_success_message(self, message) self.findChild(QtWidgets.QDialog).close() self.close() except FileNotFoundError: message = 'files_not_found' call_error_message(self, message) self.findChild(QtWidgets.QDialog).close() if archive: remove_unpacked_files(mod_path)
def continue_last_translation(self): last_file: list = get_info_from_stack() if last_file: file = find_last_file(self.collection, last_file) message = ('continue_last_translation', file, file.original_file_name) call_accept_message(self, message, lambda: self.start_localisation(file)) else: message = 'all_is_complete' call_error_message(self, message)
def show_mods_list_window(self): try: mod_list_window = ModsListWindow(self) except FileNotFoundError as error: message = 'files_not_found' self.message = error.filename.split("\\")[-1] call_error_message(self, message) except JSONDecodeError as error: message = 'JSONDecodeError' self.message = error.msg call_error_message(self, message) else: mod_list_window.show()
def choose_file(self, file_type): file = QtWidgets.QFileDialog.getOpenFileName(directory=f'{drive}:\\Users\\{user}\\Desktop') if file[0]: if file[0].split('.')[-1] not in '.txt.yml.yaml': call_error_message(self, 'TypeError') else: self.files[file_type] = file[0] file_choosen_style(self.types[file_type]) else: try: self.files.pop(file_type) file_not_choosen_style(self.types[file_type]) except KeyError: pass
def update_localisation_using_chosen_file(self, localisation_file): chosen_file_path = QtWidgets.QFileDialog.getOpenFileName( directory=f'{drive}:\\Users\\{user}\\Desktop')[0] if chosen_file_path and chosen_file_path.split( '.')[-1] in '.txt.yml.yaml': log = update_translation((chosen_file_path, localisation_file), 'external_way') if log is not False: call_success_message(self, 'file_was_updated') self.paint_elements() else: # If file choosing was canceled call_error_message(self, 'invalid_file') self.findChild(QtWidgets.QDialog).close()
def make_sort(self): for mod in self.modList: mod.isEnabled = mod.checkboxes[0][0].isChecked() mod.sortRequired = mod.checkboxes[0][1].isChecked() try: status = sorting(self.modList, self.game_data, self.dlc_load, self.playset, self.ReverseSortingButton.isChecked()) if status in 'mods_was_sorted': message = status call_success_message(self, message) else: message = status call_error_message(self, message) except FileNotFoundError as error: message = 'FileNotFoundError' self.message = error.args[0] call_error_message(self, message) self.update_mod_list()
def save_localisation(self): try: self.file.tr_status = round((self.bar[0].value() / self.bar[0].maximum()) * 100) \ if self.bar[0].value() != self.bar[0].maximum() \ else 100 # meaning it's Complete self.file.pointer_pos = self.pointer collection_update(self.file, self.machine_text, self.user_text) message = 'file_was_updated' call_success_message(self, message) if self.file.tr_status == 100: put_lines(self.file) pop_stack() self.clean_state() except AttributeError: message = 'no_translation' call_error_message(self, message)
def compare(self): if not self.files: self.message = 'Вы не выбрали файлы' call_error_message(self, 'files_not_choosen') return False try: old_tr_file_path = self.files['ChooseOldTrFileButton'] new_ver_file_path = self.files['ChooseNewVerFileButton'] if old_tr_file_path.split('.')[-1] == new_ver_file_path.split('.')[-1]: update_lines(old_tr_file_path, new_ver_file_path) # self.close() else: raise KeyError except KeyError: self.clean_state() call_error_message(self, 'files_not_choosen') else: call_success_message(self, 'files_was_compared') self.close()
def start_localisation(self, file): try: self.parent.orig_text = open_file_for_resuming( file.source_file_path) self.parent.machine_text = open_file_for_resuming( file.machine_file_path) self.parent.user_text = open_file_for_resuming( file.user_input_file_path) self.parent.pointer = file.pointer_pos self.parent.check_new_line_symbol_string(True) self.parent.pointer_max_value = len(self.parent.orig_text) self.parent.file = file self.parent.init_helpers(True) self.parent.progressbar_set_maximum(len(self.parent.orig_text)) self.parent.set_lines() self.parent.ModIDLine.setText(file.mod_id) self.parent.mod_type_pixmap(file.mod_id) self.parent.ModNameLine.setText(file.mod_name) self.parent.FileNameLine.setText(file.original_file_name) self.close() except FileNotFoundError: call_error_message(self, 'missing_file') self.findChild(QtWidgets.QDialog).close()