Loading __main__.py +16 −5 Original line number Diff line number Diff line import sys import argparse import os.path as osp import os from PyQt5.QtWidgets import QApplication from PyQt5.QtCore import QTranslator, QLocale from ui.mainwindow import MainWindow from ui.constants import PROGRAM_PATH, LIBS_PATH from ui.constants import PROGRAM_PATH def main(): parser = argparse.ArgumentParser() parser.add_argument("--proj-dir", default='', type=str, help='Open project directory on startup') args = parser.parse_args() if __name__ == '__main__': import os os.chdir(PROGRAM_PATH) app = QApplication(sys.argv) translator = QTranslator() Loading @@ -15,8 +22,12 @@ if __name__ == '__main__': osp.dirname(osp.abspath(__file__)) + "/translate", ) app.installTranslator(translator) ballontrans = MainWindow(app) ballontrans = MainWindow(app, open_dir=args.proj_dir) # ballontrans.openDir(r'data/testpacks/manga2') ballontrans.show() sys.exit(app.exec()) if __name__ == '__main__': main() # import os ui/canvas.py +0 −4 Original line number Diff line number Diff line Loading @@ -12,14 +12,10 @@ from .texteditshapecontrol import TextBlkShapeControl from .stylewidgets import FadeLabel from .image_edit import StrokeItem, PenStrokeItem, PenStrokeCommand, ImageEditMode CANVAS_MODE_TEXTEDIT = 1 CANVAS_SCALE_MAX = 3.0 CANVAS_SCALE_MIN = 0.1 CANVAS_SCALE_SPEED = 0.1 PROJ_NAME = 'proj.json' TST_HTML = '<html><p>xxxxxx</p><p style="font-size:15pt">AAAAA</p><p>、测试、</p><br /><p style="font-size:20pt">测测测测测试</p></html>' class CustomGV(QGraphicsView): do_scale = True ctrl_pressed = False Loading ui/configpanel.py +60 −24 Original line number Diff line number Diff line Loading @@ -29,21 +29,24 @@ class ConfigTextLabel(QLabel): class ConfigSubBlock(Widget): pressed = pyqtSignal(int, int) def __init__(self, widget: Union[QWidget, QLayout], name: str = None, discription: str = None) -> None: def __init__(self, widget: Union[QWidget, QLayout], name: str = None, discription: str = None, vertical_layout=True) -> None: super().__init__() self.idx0: int = None self.idx1: int = None self.vlayout = QVBoxLayout(self) if vertical_layout: layout = QVBoxLayout(self) else: layout = QHBoxLayout(self) self.name = name if name is not None: textlabel = ConfigTextLabel(name, CONFIG_FONTSIZE_CONTENT, QFont.DemiBold) self.vlayout.addWidget(textlabel) layout.addWidget(textlabel) if discription is not None: self.vlayout.addWidget(ConfigTextLabel(discription, CONFIG_FONTSIZE_CONTENT-2)) layout.addWidget(ConfigTextLabel(discription, CONFIG_FONTSIZE_CONTENT-2)) if isinstance(widget, QWidget): self.vlayout.addWidget(widget) layout.addWidget(widget) else: self.vlayout.addLayout(widget) layout.addLayout(widget) self.setContentsMargins(24, 6, 24, 6) def setIdx(self, idx0: int, idx1: int) -> None: Loading @@ -62,9 +65,9 @@ class ConfigBlock(Widget): self.header = ConfigTextLabel(header, CONFIG_FONTSIZE_HEADER) self.vlayout = QVBoxLayout(self) self.vlayout.addWidget(self.header) # self.addCombobox(['xxxx', 'asdfasd'], 'detect model', 'select model for detection') self.setContentsMargins(24, 24, 24, 24) self.label_list = [] self.subblock_list = [] self.index: int = 0 def setIndex(self, index: int): Loading @@ -79,6 +82,7 @@ class ConfigBlock(Widget): self.vlayout.addWidget(sublock) sublock.setIdx(self.index, len(self.label_list)-1) sublock.pressed.connect(lambda idx0, idx1: self.sublock_pressed.emit(idx0, idx1)) self.subblock_list.append(sublock) def addCombobox(self, sel: List[str], name: str, discription: str = None): combox = ConfigComboBox() Loading @@ -91,11 +95,22 @@ class ConfigBlock(Widget): self.addSublock(sublock) return sublock def addCheckBox(self, name: str, discription: str = None): def addCheckBox(self, name: str, discription: str = None) -> QCheckBox: checkbox = QCheckBox() if discription is not None: checkbox.setText(discription) sublock = ConfigSubBlock(checkbox, name) vertical_layout = True else: vertical_layout = False sublock = ConfigSubBlock(checkbox, name, vertical_layout=vertical_layout) if vertical_layout is False: sublock.layout().addItem(QSpacerItem(0, 0, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)) self.addSublock(sublock) return checkbox def getSubBlockbyIdx(self, idx: int) -> ConfigSubBlock: print(idx) return self.subblock_list[idx] class ConfigContent(QScrollArea): Loading Loading @@ -126,7 +141,7 @@ class ConfigContent(QScrollArea): else: self.active_label = block.header self.active_label.setActiveBackground() self.ensureWidgetVisible(self.active_label) # self.ensureWidgetVisible(self.active_label) def deactiveLabel(self): if self.active_label is not None: Loading Loading @@ -216,6 +231,15 @@ class ConfigTable(QTreeView): self.tableitem_pressed.emit(idx0, idx1) class GeneralPanel(QWidget): def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) layout = QVBoxLayout(self) class ConfigPanel(Widget): def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) Loading @@ -223,21 +247,23 @@ class ConfigPanel(Widget): self.configTable = ConfigTable() self.configTable.tableitem_pressed.connect(self.onTableItemPressed) self.configContent = ConfigContent() dlConfigPanel, dltableitem = self.addConfigBlock(self.tr('DL Module')) generalConfigPanel, generalTableItem = self.addConfigBlock(self.tr('General')) dlConfigPanel, dltableitem = self.addConfigBlock('DL Module') label_text_det = self.tr('Text Detection') label_text_ocr = self.tr('OCR') label_inpaint = self.tr('Inpaint') label_translator = self.tr('Translator') dl_text_det = TableItem(label_text_det, CONFIG_FONTSIZE_TABLE) dl_text_ocr = TableItem(label_text_ocr, CONFIG_FONTSIZE_TABLE) dl_inpaint = TableItem(label_inpaint, CONFIG_FONTSIZE_TABLE) dl_translator = TableItem(label_translator, CONFIG_FONTSIZE_TABLE) label_startup = self.tr('Startup') dltableitem.appendRows([ dl_text_det, dl_text_ocr, dl_inpaint, dl_translator TableItem(label_text_det, CONFIG_FONTSIZE_TABLE), TableItem(label_text_ocr, CONFIG_FONTSIZE_TABLE), TableItem(label_inpaint, CONFIG_FONTSIZE_TABLE), TableItem(label_translator, CONFIG_FONTSIZE_TABLE) ]) generalTableItem.appendRows([ TableItem(label_startup, CONFIG_FONTSIZE_TABLE) ]) dlConfigPanel.addTextLabel(label_text_det) Loading @@ -256,6 +282,10 @@ class ConfigPanel(Widget): self.trans_config_panel = TranslatorConfigPanel(self.tr('Translator')) self.trans_sub_block = dlConfigPanel.addBlock(self.trans_config_panel) generalConfigPanel.addTextLabel(self.tr('Startup')) self.open_on_startup_checker = generalConfigPanel.addCheckBox(self.tr('Reopen last project on startup')) self.open_on_startup_checker.stateChanged.connect(self.on_open_onstartup_changed) splitter = QSplitter(Qt.Horizontal) splitter.addWidget(self.configTable) splitter.addWidget(self.configContent) Loading @@ -281,6 +311,11 @@ class ConfigPanel(Widget): def onTableItemPressed(self, idx0, idx1): self.configContent.setActiveLabel(idx0, idx1) cb: ConfigBlock = self.configContent.config_block_list[idx0] self.configContent.ensureWidgetVisible(cb.getSubBlockbyIdx(idx1)) def on_open_onstartup_changed(self): self.config.open_recent_on_startup = self.open_on_startup_checker.isChecked() def focusOnTranslator(self): idx0, idx1 = self.trans_sub_block.idx0, self.trans_sub_block.idx1 Loading @@ -288,10 +323,11 @@ class ConfigPanel(Widget): self.configTable.tableitem_pressed.emit(idx0, idx1) def showEvent(self, e) -> None: self.inpaint_sub_block.vlayout.addWidget(self.inpaint_config_panel) self.inpaint_sub_block.layout().addWidget(self.inpaint_config_panel) return super().showEvent(e) def hideEvent(self, e) -> None: self.inpaint_sub_block.vlayout.removeWidget(self.inpaint_config_panel) self.inpaint_sub_block.layout().removeWidget(self.inpaint_config_panel) return super().hideEvent(e) No newline at end of file ui/dl_manager.py +0 −2 Original line number Diff line number Diff line Loading @@ -471,7 +471,6 @@ class DLManager(QObject): ocr_panel.paramwidget_edited.connect(self.on_ocrparam_edited) ocr_panel.ocr_changed.connect(self.setOCR) self.setTextDetector() self.setOCR() if self.dl_config.enable_translate: Loading Loading @@ -619,7 +618,6 @@ class DLManager(QObject): self.ocr_thread.setOCR(ocr) def on_finish_setdetector(self): # return if self.textdetector is not None: self.dl_config.textdetector = self.textdetector.name self.logger.info('Text detector set to {}'.format(self.textdetector.name)) Loading ui/mainwindow.py +12 −1 Original line number Diff line number Diff line Loading @@ -481,7 +481,7 @@ class MainWindow(FrameLessMainWindow): proj_directory = None imgtrans_proj: ProjImgTrans = ProjImgTrans() save_on_page_changed = True def __init__(self, app: QApplication, *args, **kwargs) -> None: def __init__(self, app: QApplication, open_dir='', *args, **kwargs) -> None: super().__init__(*args, **kwargs) global DPI, LDPI DPI = QGuiApplication.primaryScreen().physicalDotsPerInch() Loading @@ -493,6 +493,14 @@ class MainWindow(FrameLessMainWindow): self.setupShortcuts() self.showMaximized() if open_dir != '' and osp.exists(open_dir): self.openDir(open_dir) elif self.config.open_recent_on_startup: if len(self.leftBar.recent_proj_list) > 0: proj_dir = self.leftBar.recent_proj_list[0] if osp.exists(proj_dir): self.openDir(proj_dir) def setupUi(self): screen_size = QApplication.desktop().screenGeometry().size() self.setMinimumWidth(screen_size.width()*0.5) Loading Loading @@ -620,6 +628,9 @@ class MainWindow(FrameLessMainWindow): self.drawingPanel.set_config(self.config.drawpanel) self.drawingPanel.initDLModule(dl_manager) if self.config.open_recent_on_startup: self.configPanel.open_on_startup_checker.setChecked(True) def setupLogger(self): from utils.logger import logger self.logger = logger Loading Loading
__main__.py +16 −5 Original line number Diff line number Diff line import sys import argparse import os.path as osp import os from PyQt5.QtWidgets import QApplication from PyQt5.QtCore import QTranslator, QLocale from ui.mainwindow import MainWindow from ui.constants import PROGRAM_PATH, LIBS_PATH from ui.constants import PROGRAM_PATH def main(): parser = argparse.ArgumentParser() parser.add_argument("--proj-dir", default='', type=str, help='Open project directory on startup') args = parser.parse_args() if __name__ == '__main__': import os os.chdir(PROGRAM_PATH) app = QApplication(sys.argv) translator = QTranslator() Loading @@ -15,8 +22,12 @@ if __name__ == '__main__': osp.dirname(osp.abspath(__file__)) + "/translate", ) app.installTranslator(translator) ballontrans = MainWindow(app) ballontrans = MainWindow(app, open_dir=args.proj_dir) # ballontrans.openDir(r'data/testpacks/manga2') ballontrans.show() sys.exit(app.exec()) if __name__ == '__main__': main() # import os
ui/canvas.py +0 −4 Original line number Diff line number Diff line Loading @@ -12,14 +12,10 @@ from .texteditshapecontrol import TextBlkShapeControl from .stylewidgets import FadeLabel from .image_edit import StrokeItem, PenStrokeItem, PenStrokeCommand, ImageEditMode CANVAS_MODE_TEXTEDIT = 1 CANVAS_SCALE_MAX = 3.0 CANVAS_SCALE_MIN = 0.1 CANVAS_SCALE_SPEED = 0.1 PROJ_NAME = 'proj.json' TST_HTML = '<html><p>xxxxxx</p><p style="font-size:15pt">AAAAA</p><p>、测试、</p><br /><p style="font-size:20pt">测测测测测试</p></html>' class CustomGV(QGraphicsView): do_scale = True ctrl_pressed = False Loading
ui/configpanel.py +60 −24 Original line number Diff line number Diff line Loading @@ -29,21 +29,24 @@ class ConfigTextLabel(QLabel): class ConfigSubBlock(Widget): pressed = pyqtSignal(int, int) def __init__(self, widget: Union[QWidget, QLayout], name: str = None, discription: str = None) -> None: def __init__(self, widget: Union[QWidget, QLayout], name: str = None, discription: str = None, vertical_layout=True) -> None: super().__init__() self.idx0: int = None self.idx1: int = None self.vlayout = QVBoxLayout(self) if vertical_layout: layout = QVBoxLayout(self) else: layout = QHBoxLayout(self) self.name = name if name is not None: textlabel = ConfigTextLabel(name, CONFIG_FONTSIZE_CONTENT, QFont.DemiBold) self.vlayout.addWidget(textlabel) layout.addWidget(textlabel) if discription is not None: self.vlayout.addWidget(ConfigTextLabel(discription, CONFIG_FONTSIZE_CONTENT-2)) layout.addWidget(ConfigTextLabel(discription, CONFIG_FONTSIZE_CONTENT-2)) if isinstance(widget, QWidget): self.vlayout.addWidget(widget) layout.addWidget(widget) else: self.vlayout.addLayout(widget) layout.addLayout(widget) self.setContentsMargins(24, 6, 24, 6) def setIdx(self, idx0: int, idx1: int) -> None: Loading @@ -62,9 +65,9 @@ class ConfigBlock(Widget): self.header = ConfigTextLabel(header, CONFIG_FONTSIZE_HEADER) self.vlayout = QVBoxLayout(self) self.vlayout.addWidget(self.header) # self.addCombobox(['xxxx', 'asdfasd'], 'detect model', 'select model for detection') self.setContentsMargins(24, 24, 24, 24) self.label_list = [] self.subblock_list = [] self.index: int = 0 def setIndex(self, index: int): Loading @@ -79,6 +82,7 @@ class ConfigBlock(Widget): self.vlayout.addWidget(sublock) sublock.setIdx(self.index, len(self.label_list)-1) sublock.pressed.connect(lambda idx0, idx1: self.sublock_pressed.emit(idx0, idx1)) self.subblock_list.append(sublock) def addCombobox(self, sel: List[str], name: str, discription: str = None): combox = ConfigComboBox() Loading @@ -91,11 +95,22 @@ class ConfigBlock(Widget): self.addSublock(sublock) return sublock def addCheckBox(self, name: str, discription: str = None): def addCheckBox(self, name: str, discription: str = None) -> QCheckBox: checkbox = QCheckBox() if discription is not None: checkbox.setText(discription) sublock = ConfigSubBlock(checkbox, name) vertical_layout = True else: vertical_layout = False sublock = ConfigSubBlock(checkbox, name, vertical_layout=vertical_layout) if vertical_layout is False: sublock.layout().addItem(QSpacerItem(0, 0, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Expanding)) self.addSublock(sublock) return checkbox def getSubBlockbyIdx(self, idx: int) -> ConfigSubBlock: print(idx) return self.subblock_list[idx] class ConfigContent(QScrollArea): Loading Loading @@ -126,7 +141,7 @@ class ConfigContent(QScrollArea): else: self.active_label = block.header self.active_label.setActiveBackground() self.ensureWidgetVisible(self.active_label) # self.ensureWidgetVisible(self.active_label) def deactiveLabel(self): if self.active_label is not None: Loading Loading @@ -216,6 +231,15 @@ class ConfigTable(QTreeView): self.tableitem_pressed.emit(idx0, idx1) class GeneralPanel(QWidget): def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) layout = QVBoxLayout(self) class ConfigPanel(Widget): def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) Loading @@ -223,21 +247,23 @@ class ConfigPanel(Widget): self.configTable = ConfigTable() self.configTable.tableitem_pressed.connect(self.onTableItemPressed) self.configContent = ConfigContent() dlConfigPanel, dltableitem = self.addConfigBlock(self.tr('DL Module')) generalConfigPanel, generalTableItem = self.addConfigBlock(self.tr('General')) dlConfigPanel, dltableitem = self.addConfigBlock('DL Module') label_text_det = self.tr('Text Detection') label_text_ocr = self.tr('OCR') label_inpaint = self.tr('Inpaint') label_translator = self.tr('Translator') dl_text_det = TableItem(label_text_det, CONFIG_FONTSIZE_TABLE) dl_text_ocr = TableItem(label_text_ocr, CONFIG_FONTSIZE_TABLE) dl_inpaint = TableItem(label_inpaint, CONFIG_FONTSIZE_TABLE) dl_translator = TableItem(label_translator, CONFIG_FONTSIZE_TABLE) label_startup = self.tr('Startup') dltableitem.appendRows([ dl_text_det, dl_text_ocr, dl_inpaint, dl_translator TableItem(label_text_det, CONFIG_FONTSIZE_TABLE), TableItem(label_text_ocr, CONFIG_FONTSIZE_TABLE), TableItem(label_inpaint, CONFIG_FONTSIZE_TABLE), TableItem(label_translator, CONFIG_FONTSIZE_TABLE) ]) generalTableItem.appendRows([ TableItem(label_startup, CONFIG_FONTSIZE_TABLE) ]) dlConfigPanel.addTextLabel(label_text_det) Loading @@ -256,6 +282,10 @@ class ConfigPanel(Widget): self.trans_config_panel = TranslatorConfigPanel(self.tr('Translator')) self.trans_sub_block = dlConfigPanel.addBlock(self.trans_config_panel) generalConfigPanel.addTextLabel(self.tr('Startup')) self.open_on_startup_checker = generalConfigPanel.addCheckBox(self.tr('Reopen last project on startup')) self.open_on_startup_checker.stateChanged.connect(self.on_open_onstartup_changed) splitter = QSplitter(Qt.Horizontal) splitter.addWidget(self.configTable) splitter.addWidget(self.configContent) Loading @@ -281,6 +311,11 @@ class ConfigPanel(Widget): def onTableItemPressed(self, idx0, idx1): self.configContent.setActiveLabel(idx0, idx1) cb: ConfigBlock = self.configContent.config_block_list[idx0] self.configContent.ensureWidgetVisible(cb.getSubBlockbyIdx(idx1)) def on_open_onstartup_changed(self): self.config.open_recent_on_startup = self.open_on_startup_checker.isChecked() def focusOnTranslator(self): idx0, idx1 = self.trans_sub_block.idx0, self.trans_sub_block.idx1 Loading @@ -288,10 +323,11 @@ class ConfigPanel(Widget): self.configTable.tableitem_pressed.emit(idx0, idx1) def showEvent(self, e) -> None: self.inpaint_sub_block.vlayout.addWidget(self.inpaint_config_panel) self.inpaint_sub_block.layout().addWidget(self.inpaint_config_panel) return super().showEvent(e) def hideEvent(self, e) -> None: self.inpaint_sub_block.vlayout.removeWidget(self.inpaint_config_panel) self.inpaint_sub_block.layout().removeWidget(self.inpaint_config_panel) return super().hideEvent(e) No newline at end of file
ui/dl_manager.py +0 −2 Original line number Diff line number Diff line Loading @@ -471,7 +471,6 @@ class DLManager(QObject): ocr_panel.paramwidget_edited.connect(self.on_ocrparam_edited) ocr_panel.ocr_changed.connect(self.setOCR) self.setTextDetector() self.setOCR() if self.dl_config.enable_translate: Loading Loading @@ -619,7 +618,6 @@ class DLManager(QObject): self.ocr_thread.setOCR(ocr) def on_finish_setdetector(self): # return if self.textdetector is not None: self.dl_config.textdetector = self.textdetector.name self.logger.info('Text detector set to {}'.format(self.textdetector.name)) Loading
ui/mainwindow.py +12 −1 Original line number Diff line number Diff line Loading @@ -481,7 +481,7 @@ class MainWindow(FrameLessMainWindow): proj_directory = None imgtrans_proj: ProjImgTrans = ProjImgTrans() save_on_page_changed = True def __init__(self, app: QApplication, *args, **kwargs) -> None: def __init__(self, app: QApplication, open_dir='', *args, **kwargs) -> None: super().__init__(*args, **kwargs) global DPI, LDPI DPI = QGuiApplication.primaryScreen().physicalDotsPerInch() Loading @@ -493,6 +493,14 @@ class MainWindow(FrameLessMainWindow): self.setupShortcuts() self.showMaximized() if open_dir != '' and osp.exists(open_dir): self.openDir(open_dir) elif self.config.open_recent_on_startup: if len(self.leftBar.recent_proj_list) > 0: proj_dir = self.leftBar.recent_proj_list[0] if osp.exists(proj_dir): self.openDir(proj_dir) def setupUi(self): screen_size = QApplication.desktop().screenGeometry().size() self.setMinimumWidth(screen_size.width()*0.5) Loading Loading @@ -620,6 +628,9 @@ class MainWindow(FrameLessMainWindow): self.drawingPanel.set_config(self.config.drawpanel) self.drawingPanel.initDLModule(dl_manager) if self.config.open_recent_on_startup: self.configPanel.open_on_startup_checker.setChecked(True) def setupLogger(self): from utils.logger import logger self.logger = logger Loading