Loading ballontranslator/dl/textdetector/textblock.py +0 −2 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ class TextBlock(object): underline: bool = False, italic: bool = False, _alignment: int = -1, alpha: float = 255, rich_text: str = "", _bounding_rect: List = None, accumulate_color = True, Loading Loading @@ -81,7 +80,6 @@ class TextBlock(object): self.bold: bool = bold self.underline: bool = underline self.italic: bool = italic self.alpha = alpha self.rich_text = rich_text self.line_spacing = line_spacing self.letter_spacing = letter_spacing Loading ballontranslator/ui/fontformatpanel.py +13 −6 Original line number Diff line number Diff line import functools from typing import List, Tuple, Union import copy from qtpy.QtWidgets import QHBoxLayout, QVBoxLayout, QFrame, QFontComboBox, QApplication, QPushButton, QCheckBox, QLabel from qtpy.QtCore import Signal, Qt Loading @@ -22,7 +23,6 @@ def restore_textcursor(formatting_func): def wrapper(blkitem: TextBlkItem, *args, **kwargs): if blkitem is None: return stroke_width_before = blkitem.stroke_width cursor = blkitem.textCursor() set_all = not cursor.hasSelection() pos1 = cursor.position() Loading @@ -38,7 +38,6 @@ def restore_textcursor(formatting_func): else: cursor.setPosition(pos1) blkitem.setTextCursor(cursor) if blkitem.stroke_width != stroke_width_before: blkitem.repaint_background() return wrapper Loading Loading @@ -466,8 +465,8 @@ class FontFormatPanel(Widget): self.effectBtn = EffectBtn(self) self.effectBtn.setText(self.tr("Effect")) self.effectBtn.clicked.connect(self.on_effectbtn_clicked) self.effect_widget = TextEffectPanel() self.effect_widget.hide() self.effect_panel = TextEffectPanel() self.effect_panel.hide() FONTFORMAT_SPACING = 6 Loading Loading @@ -656,4 +655,12 @@ class FontFormatPanel(Widget): self.fontfmtLabel.setText(f'TextBlock #{textblk_item.idx}') def on_effectbtn_clicked(self): self.effect_widget.show() No newline at end of file self.effect_panel.active_fontfmt = self.active_format self.effect_panel.fontfmt = copy.deepcopy(self.active_format) self.effect_panel.updatePanels() self.effect_panel.show() # def on_apply_effect(self): # if self.textblk_item is not None: # self.textblk_item.update_effect(self.active_format) No newline at end of file ballontranslator/ui/mainwindow.py +2 −2 Original line number Diff line number Diff line Loading @@ -108,8 +108,8 @@ class MainWindow(QMainWindow): self.drawingPanel = DrawingPanel(self.canvas, self.configPanel.inpaint_config_panel) self.textPanel = TextPanel(self.app, self.canvas) self.textPanel.formatpanel.effect_widget.setParent(self) self.textPanel.formatpanel.effect_widget.setWindowFlags(Qt.WindowType.Window | Qt.WindowType.CustomizeWindowHint) self.textPanel.formatpanel.effect_panel.setParent(self) self.textPanel.formatpanel.effect_panel.setWindowFlags(Qt.WindowType.Window | Qt.WindowType.CustomizeWindowHint) self.st_manager = SceneTextManager(self.app, self.canvas, self.textPanel) # comic trans pannel Loading ballontranslator/ui/misc.py +2 −3 Original line number Diff line number Diff line Loading @@ -100,14 +100,14 @@ class FontFormat: alignment: int = 0, vertical: bool = False, weight: int = 50, alpha: int = 255, line_spacing: float = 1.2, letter_spacing: float = 1., opacity: float = 1., shadow_radius: float = 0., shadow_strength: float = 1., shadow_color: Tuple = (0, 0, 0), shadow_offset: List = [0, 0]) -> None: shadow_offset: List = [0, 0], **kwargs) -> None: self.family = family if family is not None else DEFAULT_FONT_FAMILY self.size = size self.stroke_width = stroke_width Loading @@ -116,7 +116,6 @@ class FontFormat: self.bold = bold self.underline = underline self.italic = italic self.alpha = alpha self.weight: int = weight self.alignment: int = alignment self.vertical: bool = vertical Loading ballontranslator/ui/scenetext_manager.py +26 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,25 @@ class ApplyFontformatCommand(QUndoCommand): return False class ApplyEffectCommand(QUndoCommand): def __init__(self, items: List[TextBlkItem], fontformat: FontFormat): super(ApplyEffectCommand, self).__init__() self.items = items self.old_fmt_lst: List[FontFormat] = [] self.new_fmt = fontformat for item in items: self.old_fmt_lst.append(item.get_fontformat()) def redo(self): for item in self.items: item.update_effect(self.new_fmt) item.update() def undo(self): for item, fmt in zip(self.items, self.old_fmt_lst): item.update_effect(fmt) item.update() class ReshapeItemCommand(QUndoCommand): def __init__(self, item: TextBlkItem, parent=None): super(ReshapeItemCommand, self).__init__(parent) Loading Loading @@ -246,6 +265,7 @@ class SceneTextManager(QObject): self.textEditList = textpanel.textEditList self.formatpanel = textpanel.formatpanel self.formatpanel.effect_panel.apply.connect(self.on_apply_effect) self.formatpanel.global_format_changed.connect(self.onGlobalFormatChanged) self.imgtrans_proj = self.canvas.imgtrans_proj Loading Loading @@ -693,6 +713,12 @@ class SceneTextManager(QObject): if len(selected_blks) > 0: self.canvasUndoStack.push(ApplyFontformatCommand(selected_blks, fontformat)) def on_apply_effect(self): format = self.formatpanel.active_format selected_blks = self.get_selected_blkitems() if len(selected_blks) > 0: self.canvasUndoStack.push(ApplyEffectCommand(selected_blks, format)) def get_selected_blkitems(self) -> List[TextBlkItem]: selections = self.canvas.selectedItems() selected_blks = [] Loading Loading
ballontranslator/dl/textdetector/textblock.py +0 −2 Original line number Diff line number Diff line Loading @@ -37,7 +37,6 @@ class TextBlock(object): underline: bool = False, italic: bool = False, _alignment: int = -1, alpha: float = 255, rich_text: str = "", _bounding_rect: List = None, accumulate_color = True, Loading Loading @@ -81,7 +80,6 @@ class TextBlock(object): self.bold: bool = bold self.underline: bool = underline self.italic: bool = italic self.alpha = alpha self.rich_text = rich_text self.line_spacing = line_spacing self.letter_spacing = letter_spacing Loading
ballontranslator/ui/fontformatpanel.py +13 −6 Original line number Diff line number Diff line import functools from typing import List, Tuple, Union import copy from qtpy.QtWidgets import QHBoxLayout, QVBoxLayout, QFrame, QFontComboBox, QApplication, QPushButton, QCheckBox, QLabel from qtpy.QtCore import Signal, Qt Loading @@ -22,7 +23,6 @@ def restore_textcursor(formatting_func): def wrapper(blkitem: TextBlkItem, *args, **kwargs): if blkitem is None: return stroke_width_before = blkitem.stroke_width cursor = blkitem.textCursor() set_all = not cursor.hasSelection() pos1 = cursor.position() Loading @@ -38,7 +38,6 @@ def restore_textcursor(formatting_func): else: cursor.setPosition(pos1) blkitem.setTextCursor(cursor) if blkitem.stroke_width != stroke_width_before: blkitem.repaint_background() return wrapper Loading Loading @@ -466,8 +465,8 @@ class FontFormatPanel(Widget): self.effectBtn = EffectBtn(self) self.effectBtn.setText(self.tr("Effect")) self.effectBtn.clicked.connect(self.on_effectbtn_clicked) self.effect_widget = TextEffectPanel() self.effect_widget.hide() self.effect_panel = TextEffectPanel() self.effect_panel.hide() FONTFORMAT_SPACING = 6 Loading Loading @@ -656,4 +655,12 @@ class FontFormatPanel(Widget): self.fontfmtLabel.setText(f'TextBlock #{textblk_item.idx}') def on_effectbtn_clicked(self): self.effect_widget.show() No newline at end of file self.effect_panel.active_fontfmt = self.active_format self.effect_panel.fontfmt = copy.deepcopy(self.active_format) self.effect_panel.updatePanels() self.effect_panel.show() # def on_apply_effect(self): # if self.textblk_item is not None: # self.textblk_item.update_effect(self.active_format) No newline at end of file
ballontranslator/ui/mainwindow.py +2 −2 Original line number Diff line number Diff line Loading @@ -108,8 +108,8 @@ class MainWindow(QMainWindow): self.drawingPanel = DrawingPanel(self.canvas, self.configPanel.inpaint_config_panel) self.textPanel = TextPanel(self.app, self.canvas) self.textPanel.formatpanel.effect_widget.setParent(self) self.textPanel.formatpanel.effect_widget.setWindowFlags(Qt.WindowType.Window | Qt.WindowType.CustomizeWindowHint) self.textPanel.formatpanel.effect_panel.setParent(self) self.textPanel.formatpanel.effect_panel.setWindowFlags(Qt.WindowType.Window | Qt.WindowType.CustomizeWindowHint) self.st_manager = SceneTextManager(self.app, self.canvas, self.textPanel) # comic trans pannel Loading
ballontranslator/ui/misc.py +2 −3 Original line number Diff line number Diff line Loading @@ -100,14 +100,14 @@ class FontFormat: alignment: int = 0, vertical: bool = False, weight: int = 50, alpha: int = 255, line_spacing: float = 1.2, letter_spacing: float = 1., opacity: float = 1., shadow_radius: float = 0., shadow_strength: float = 1., shadow_color: Tuple = (0, 0, 0), shadow_offset: List = [0, 0]) -> None: shadow_offset: List = [0, 0], **kwargs) -> None: self.family = family if family is not None else DEFAULT_FONT_FAMILY self.size = size self.stroke_width = stroke_width Loading @@ -116,7 +116,6 @@ class FontFormat: self.bold = bold self.underline = underline self.italic = italic self.alpha = alpha self.weight: int = weight self.alignment: int = alignment self.vertical: bool = vertical Loading
ballontranslator/ui/scenetext_manager.py +26 −0 Original line number Diff line number Diff line Loading @@ -75,6 +75,25 @@ class ApplyFontformatCommand(QUndoCommand): return False class ApplyEffectCommand(QUndoCommand): def __init__(self, items: List[TextBlkItem], fontformat: FontFormat): super(ApplyEffectCommand, self).__init__() self.items = items self.old_fmt_lst: List[FontFormat] = [] self.new_fmt = fontformat for item in items: self.old_fmt_lst.append(item.get_fontformat()) def redo(self): for item in self.items: item.update_effect(self.new_fmt) item.update() def undo(self): for item, fmt in zip(self.items, self.old_fmt_lst): item.update_effect(fmt) item.update() class ReshapeItemCommand(QUndoCommand): def __init__(self, item: TextBlkItem, parent=None): super(ReshapeItemCommand, self).__init__(parent) Loading Loading @@ -246,6 +265,7 @@ class SceneTextManager(QObject): self.textEditList = textpanel.textEditList self.formatpanel = textpanel.formatpanel self.formatpanel.effect_panel.apply.connect(self.on_apply_effect) self.formatpanel.global_format_changed.connect(self.onGlobalFormatChanged) self.imgtrans_proj = self.canvas.imgtrans_proj Loading Loading @@ -693,6 +713,12 @@ class SceneTextManager(QObject): if len(selected_blks) > 0: self.canvasUndoStack.push(ApplyFontformatCommand(selected_blks, fontformat)) def on_apply_effect(self): format = self.formatpanel.active_format selected_blks = self.get_selected_blkitems() if len(selected_blks) > 0: self.canvasUndoStack.push(ApplyEffectCommand(selected_blks, format)) def get_selected_blkitems(self) -> List[TextBlkItem]: selections = self.canvas.selectedItems() selected_blks = [] Loading