Commit b338b420 authored by dmMaze's avatar dmMaze
Browse files

add options to export to txt files in headless mode #623

parent 554edc3d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ parser.add_argument("--requirements", default='requirements.txt')
parser.add_argument("--headless", action='store_true', help='run without GUI')
parser.add_argument("--exec_dirs", default='', help='translation queue (project directories) separated by comma')
parser.add_argument("--ldpi", default=None, type=float, help='logical dots perinch')
parser.add_argument("--export-translation-txt", action='store_true', help='save translation to txt file once RUN completed')
parser.add_argument("--export-source-txt", action='store_true', help='save source to txt file once RUN completed')
args, _ = parser.parse_known_args()


@@ -161,6 +163,7 @@ def main():
    from utils import config as program_config

    from qtpy.QtCore import QTranslator, QLocale, Qt
    shared.args = args
    shared.DEFAULT_DISPLAY_LANG = QLocale.system().name().replace('en_CN', 'zh_CN')
    shared.HEADLESS = args.headless
    shared.load_cache()
+6 −4
Original line number Diff line number Diff line
@@ -6,6 +6,7 @@ import subprocess
from functools import partial
import time

from tqdm import tqdm
from qtpy.QtWidgets import QAction, QFileDialog, QMenu, QHBoxLayout, QVBoxLayout, QApplication, QStackedWidget, QSplitter, QListWidget, QShortcut, QListWidgetItem, QMessageBox, QTextEdit, QPlainTextEdit
from qtpy.QtCore import Qt, QPoint, QSize, QEvent, Signal
from qtpy.QtGui import QContextMenuEvent, QTextCursor, QGuiApplication, QIcon, QCloseEvent, QKeySequence, QKeyEvent, QPainter, QClipboard
@@ -915,6 +916,10 @@ class MainWindow(mainwindow_cls):
        self.postprocess_mt_toggle = True
        if pcfg.module.empty_runcache and not shared.HEADLESS:
            self.module_manager.unload_all_models()
        if shared.args.export_translation_txt:
            self.on_export_txt('translation')
        if shared.args.export_source_txt:
            self.on_export_txt('source')
        if shared.HEADLESS:
            self.run_next_dir()

@@ -1182,9 +1187,7 @@ class MainWindow(mainwindow_cls):
    def on_export_txt(self, dump_target, suffix='.txt'):
        try:
            self.imgtrans_proj.dump_txt(dump_target=dump_target, suffix=suffix)
            msg = QMessageBox()
            msg.setText(self.tr('Text file exported to ') + self.imgtrans_proj.dump_txt_path(dump_target, suffix))
            msg.exec_()
            create_info_dialog(self.tr('Text file exported to ') + self.imgtrans_proj.dump_txt_path(dump_target, suffix))
        except Exception as e:
            create_error_dialog(e, self.tr('Failed to export as TEXT file'))

@@ -1346,7 +1349,6 @@ class MainWindow(mainwindow_cls):
            self.app.quit()
            return
        d = self.exec_dirs.pop(0)
        from tqdm import tqdm
        
        LOGGER.info(f'translating {d} ...')
        self.openDir(d)
+1 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ ON_MACOS = sys.platform == 'darwin'
ON_WINDOWS = sys.platform == 'win32'
HEADLESS = False
DEBUG = False
args = None

FUZZY_MATCH_IMAGE_NAME = False