Unverified Commit 042486b4 authored by Sergey Pinus's avatar Sergey Pinus Committed by GitHub
Browse files

Merge branch 'dmMaze:dev' into paddle_ocr

parents 49ffb886 a4c50344
Loading
Loading
Loading
Loading
+18 −1
Original line number Diff line number Diff line
@@ -322,10 +322,14 @@ QMenu::item:selected {
}

QDialog {
    font-size: 7px;
    font-size: 14px;
    background-color: @widgetBackgroundColor;
}

QDialog QPushButton {
    padding: 5px 15px;
}

QGroupBox {
    background-color: @emptyContentBackgroundColor;
}
@@ -1002,6 +1006,19 @@ TextStyleLabel {
    border-radius: 7px;
}

SmallParamLabel {
    font-size: 12px;
    height: 20px;
}

SmallComboBox {
    height: 20px;
    font-size: 12px;
    /* padding-left: 8px; */
    border: 1px solid @borderColor;
    background-color: @transtexteditBackgroundColor;
}

ArrowLeftButton {
    image: url(icons/arrow-left.svg);
    border: none;
+6 −0
Original line number Diff line number Diff line
@@ -885,6 +885,12 @@
        <source>Failed to load project from</source>
        <translation>无法从所选路径加载项目</translation>
    </message>
    <message>
        <location filename="../ui/mainwindow.py" line="1081"/>
        <source>Are you sure to run image translation again?
All existing translation results will be cleared!</source>
        <translation>确定要重新运行吗现有翻译结果将被清空</translation>
    </message>
</context>
<context>
    <name>ModuleManager</name>
+71 −0
Original line number Diff line number Diff line
@@ -26,6 +26,39 @@ def read_jpg_metadata(imgpath: str):
    bubdict = json.loads(user_comment)
    return bubdict

page_start_pattern = re.compile(r'^###\s+', re.MULTILINE)
text_blkid_start_pattern = re.compile(r'^\d+\.', re.MULTILINE)

def parse_txt_translation(file_path: str):
    with open(file_path, 'r', encoding='utf8') as f:
        content = f.read()
    page_start = None
    page_list = []
    for matched in page_start_pattern.finditer(content):
        start, end = matched.span()
        if page_start is not None:
            page_list.append({'page_content': content[page_start: start]})
        page_start = start
    if page_start is not None:
        page_list.append({'page_content': content[page_start:]})

    for page_dict in page_list:
        page_content = page_dict['page_content']
        page_dict['page_name'] = page_start_pattern.sub('', page_content.split('\n')[0]).strip()
        blkid_start = blkid_end = None
        blk_list = []
        for matched in text_blkid_start_pattern.finditer(page_content):
            start, end = matched.span()
            if blkid_start is not None:
                blk_list.append(page_content[blkid_end: start].strip())
            blkid_start = start
            blkid_end = end
        if blkid_start is not None:
            blk_list.append(page_content[blkid_end:])
        page_dict['blk_list'] = blk_list

    return page_list


class TextBlkEncoder(NumpyEncoder):
    def default(self, obj):
@@ -139,6 +172,40 @@ class ProjImgTrans:
            if len(self.pages) > 0:
                self.set_current_img_byidx(0)

    def load_translation_from_txt(self, file_path: str):
        page_list = parse_txt_translation(file_path)
        missing_pages = []
        unmatched_pages = []
        unexpected_pages = []
        matched_pages = []
        for page_dict in page_list:
            page_name = page_dict['page_name']
            if page_name in self.pages:
                matched_pages.append(page_name)
            else:
                unexpected_pages.append(page_name)
                continue
            blklist = self.pages[page_name]
            n_blk = len(blklist)
            src_blk_list = page_dict['blk_list']
            n_src_blk = len(src_blk_list)
            if n_src_blk != n_blk:
                LOGGER.warning(f'Unmatched text blocks in {page_name}, number of text blocks in this page vs source file: {n_blk}-{n_src_blk}')
                unmatched_pages.append(page_name)
            for blkid in range(min(n_blk, n_src_blk)):
                blk = blklist[blkid]
                blk.rich_text = ''
                blk.translation = src_blk_list[blkid]

        matched_pages = set(matched_pages)
        if len(matched_pages) != self.num_pages:
            for page_name in self.pages:
                if page_name not in matched_pages:
                    missing_pages.append(page_name)
        
        all_matched = len(missing_pages) == 0 and len(unmatched_pages) == 0 and len(unexpected_pages) == 0
        return all_matched, {'missing_pages': missing_pages, 'unmatched_pages': unmatched_pages, 'unexpected_pages': unexpected_pages, 'matched_pages': matched_pages}

    def load_from_json(self, json_path: str):
        old_dir = self.directory
        directory = osp.dirname(json_path)
@@ -306,6 +373,10 @@ class ProjImgTrans:
    def is_empty(self):
        return len(self.pages) == 0

    @property
    def is_all_pages_no_text(self):
        return all([len(blklist) == 0 for blklist in self.pages.values()])

    @property
    def img_valid(self):
        return self.img_array is not None
+2 −2
Original line number Diff line number Diff line
from .scrollbar import ScrollBar
from .combobox import ComboBox, ConfigComboBox, ParamComboBox, SizeComboBox
from .combobox import ComboBox, ConfigComboBox, ParamComboBox, SizeComboBox, SmallComboBox
from .widget import Widget, SeparatorWidget
from .view_panel import PanelGroupBox, PanelArea, PanelAreaContent, ViewWidget, ExpandLabel
from .message import MessageBox, TaskProgressBar, FrameLessMessageBox, ProgressMessageBox, ImgtransProgressMessageBox
from .flow_layout import FlowLayout
from .label import FadeLabel, ColorPickerLabel, ClickableLabel, CheckableLabel, TextCheckerLabel
from .label import FadeLabel, ColorPickerLabel, ClickableLabel, CheckableLabel, TextCheckerLabel, ParamNameLabel, SmallParamLabel
from .slider import PaintQSlider
from .helper import isDarkTheme, themeColor
from .push_button import NoBorderPushBtn
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,10 @@ class ComboBox(QComboBox):
            return self.scrollWidget.wheelEvent(*args, **kwargs)
        

class SmallComboBox(ComboBox):
    pass


class ConfigComboBox(ComboBox):

    def __init__(self, fix_size=True, scrollWidget: QWidget = None, *args, **kwargs) -> None:
Loading