Loading ballontranslator/dl/textdetector/textblock.py +45 −34 Original line number Diff line number Diff line from typing import List from typing import List, Tuple import numpy as np from shapely.geometry import Polygon import math Loading Loading @@ -44,6 +44,11 @@ class TextBlock(object): default_stroke_width = 0.2, font_weight = 50, _target_lang: str = "", opacity: float = 1., shadow_radius: float = 0., shadow_strength: float = 1., shadow_color: Tuple = (0, 0, 0), shadow_offset: List = [0, 0], **kwargs) -> None: self.xyxy = [int(num) for num in xyxy] # boundingbox of textblock self.lines = [] if lines is None else lines # polygons of textlines Loading Loading @@ -88,6 +93,12 @@ class TextBlock(object): self.font_weight = font_weight self.accumulate_color = accumulate_color self.opacity = opacity self.shadow_radius = shadow_radius self.shadow_strength = shadow_strength self.shadow_color = shadow_color self.shadow_offset = shadow_offset def adjust_bbox(self, with_bbox=False): lines = self.lines_array().astype(np.int32) if with_bbox: Loading ballontranslator/ui/combobox.py 0 → 100644 +62 −0 Original line number Diff line number Diff line from qtpy.QtWidgets import QComboBox from qtpy.QtCore import Signal, Qt from qtpy.QtGui import QDoubleValidator, QFocusEvent, QKeyEvent from typing import List class SizeComboBox(QComboBox): apply_change = Signal(float) def __init__(self, val_range: List = None, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.text_changed_by_user = False self.editTextChanged.connect(self.on_text_changed) self.currentIndexChanged.connect(self.on_current_index_changed) self.setEditable(True) self.min_val = val_range[0] self.max_val = val_range[1] validator = QDoubleValidator() if val_range is not None: validator.setTop(val_range[1]) validator.setBottom(val_range[0]) validator.setNotation(QDoubleValidator.Notation.StandardNotation) self.setValidator(validator) self.lineEdit().setValidator(validator) self._value = 0 def keyPressEvent(self, e: QKeyEvent) -> None: key = e.key() if key == Qt.Key.Key_Return or key == Qt.Key.Key_Enter: self.check_change() super().keyPressEvent(e) def focusInEvent(self, e: QFocusEvent) -> None: super().focusInEvent(e) self.text_changed_by_user = False def on_text_changed(self): if self.hasFocus(): self.text_changed_by_user = True def on_current_index_changed(self): if self.hasFocus(): self.check_change() def value(self) -> float: txt = self.currentText() try: val = float(txt) self._value = val return val except: return self._value def setValue(self, value: float): value = min(self.max_val, max(self.min_val, value)) self.setCurrentText(str(round(value, 2))) def check_change(self): if self.text_changed_by_user: self.text_changed_by_user = False self.apply_change.emit(self.value()) No newline at end of file ballontranslator/ui/constants.py +5 −0 Original line number Diff line number Diff line Loading @@ -19,9 +19,14 @@ CONFIG_COMBOBOX_SHORT = 200 CONFIG_COMBOBOX_MIDEAN = 332 CONFIG_COMBOBOX_LONG = 468 HORSLIDER_FIXHEIGHT = 36 WIDGET_SPACING_CLOSE = 8 TEXTEDIT_FIXWIDTH = 350 TEXTEFFECT_FIXWIDTH = 400 TEXTEFFECT_MAXHEIGHT = 500 LEFTBAR_WIDTH = 60 LEFTBTN_WIDTH = 38 Loading ballontranslator/ui/drawingpanel.py +4 −8 Original line number Diff line number Diff line Loading @@ -67,8 +67,7 @@ class InpaintPanel(Widget): super().__init__(*args, **kwargs) self.inpainter_panel = inpainter_panel self.thicknessSlider = PaintQSlider(self.tr('pen thickness ') + 'value px', Qt.Orientation.Horizontal) self.thicknessSlider.setFixedHeight(50) self.thicknessSlider = PaintQSlider(self.tr('pen thickness ') + 'value px') self.thicknessSlider.setRange(MIN_PEN_SIZE, MAX_PEN_SIZE) self.thicknessSlider.valueChanged.connect(self.on_thickness_changed) Loading Loading @@ -105,12 +104,10 @@ class PenConfigPanel(Widget): colorChanged = Signal(list) def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.thicknessSlider = PaintQSlider(self.tr('pen thickness ') + 'value px', Qt.Orientation.Horizontal) self.thicknessSlider.setFixedHeight(32) self.thicknessSlider = PaintQSlider(self.tr('pen thickness ') + 'value px') self.thicknessSlider.setRange(MIN_PEN_SIZE, MAX_PEN_SIZE) self.thicknessSlider.valueChanged.connect(self.on_thickness_changed) self.alphaSlider = PaintQSlider(self.tr('alpha value'), Qt.Orientation.Horizontal) self.alphaSlider.setFixedHeight(32) self.alphaSlider = PaintQSlider(self.tr('alpha value')) self.alphaSlider.setRange(0, 255) self.alphaSlider.valueChanged.connect(self.on_alpha_changed) Loading Loading @@ -284,8 +281,7 @@ class DrawingPanel(Widget): self.toolConfigStackwidget.addWidget(self.penConfigPanel) self.toolConfigStackwidget.addWidget(self.rectPanel) self.maskTransperancySlider = PaintQSlider(' value%', Qt.Orientation.Horizontal) self.maskTransperancySlider.setFixedHeight(32) self.maskTransperancySlider = PaintQSlider(' value%') self.maskTransperancySlider.valueChanged.connect(self.canvas.setMaskTransparencyBySlider) masklayout = QHBoxLayout() masklayout.addWidget(ToolNameLabel(220, self.tr('Mask Transparency'))) Loading ballontranslator/ui/fontformatpanel.py +8 −69 Original line number Diff line number Diff line import functools from typing import List, Tuple, Union from qtpy.QtWidgets import QHBoxLayout, QVBoxLayout, QFrame, QFontComboBox, QComboBox, QApplication, QPushButton, QCheckBox, QLabel from qtpy.QtWidgets import QHBoxLayout, QVBoxLayout, QFrame, QFontComboBox, QApplication, QPushButton, QCheckBox, QLabel from qtpy.QtCore import Signal, Qt from qtpy.QtGui import QColor, QTextCharFormat, QDoubleValidator, QMouseEvent, QFont, QTextCursor, QFocusEvent, QKeyEvent from qtpy.QtGui import QColor, QTextCharFormat, QMouseEvent, QFont, QTextCursor from .stylewidgets import Widget, ColorPicker from .misc import FontFormat, set_html_color, pt2px from .textitem import TextBlkItem from .canvas import Canvas from .constants import CONFIG_FONTSIZE_CONTENT, WIDGET_SPACING_CLOSE from .text_graphical_effect import EffectBtn from .text_graphical_effect import EffectBtn, TextEffectPanel from .combobox import SizeComboBox from . import constants as C from utils.logger import logger as LOGGER # restore text cursor status after formatting def restore_textcursor(formatting_func): Loading Loading @@ -250,64 +249,6 @@ class FormatGroupBtn(QFrame): def setUnderline(self): self.set_underline.emit(self.underlineBtn.isChecked()) class SizeComboBox(QComboBox): apply_change = Signal(float) def __init__(self, val_range: List = None, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.text_changed_by_user = False self.editTextChanged.connect(self.on_text_changed) self.currentIndexChanged.connect(self.on_current_index_changed) self.setEditable(True) self.min_val = val_range[0] self.max_val = val_range[1] validator = QDoubleValidator() if val_range is not None: validator.setTop(val_range[1]) validator.setBottom(val_range[0]) validator.setNotation(QDoubleValidator.Notation.StandardNotation) self.setValidator(validator) self.lineEdit().setValidator(validator) self._value = 0 def keyPressEvent(self, e: QKeyEvent) -> None: key = e.key() if key == Qt.Key.Key_Return or key == Qt.Key.Key_Enter: self.check_change() super().keyPressEvent(e) def focusInEvent(self, e: QFocusEvent) -> None: super().focusInEvent(e) self.text_changed_by_user = False def on_text_changed(self): if self.hasFocus(): self.text_changed_by_user = True def on_current_index_changed(self): if self.hasFocus(): self.check_change() def value(self) -> float: txt = self.currentText() try: val = float(txt) self._value = val return val except: LOGGER.warning(f'SizeComboBox invalid input: {txt}, return {self._value}') return self._value def setValue(self, value: float): value = min(self.max_val, max(self.min_val, value)) self.setCurrentText(str(round(value, 2))) def check_change(self): if self.text_changed_by_user: self.text_changed_by_user = False self.apply_change.emit(self.value()) class FontSizeBox(QFrame): apply_fontsize = Signal(float) Loading @@ -319,17 +260,13 @@ class FontSizeBox(QFrame): self.downBtn.setObjectName("FsizeIncrementDown") self.upBtn.clicked.connect(self.onUpBtnClicked) self.downBtn.clicked.connect(self.onDownBtnClicked) self.fcombobox = SizeComboBox([0, 10000], self) self.fcombobox = SizeComboBox([1, 1000], self) self.fcombobox.addItems([ "5", "5.5", "6.5", "7.5", "8", "9", "10", "10.5", "11", "12", "14", "16", "18", "20", '22', "26", "28", "36", "48", "56", "72" ]) self.fcombobox.apply_change.connect(self.on_fbox_apply_change) validator = QDoubleValidator() validator.setTop(1000) validator.setBottom(1) self.fcombobox.setValidator(validator) hlayout = QHBoxLayout(self) vlayout = QVBoxLayout() Loading Loading @@ -529,6 +466,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() FONTFORMAT_SPACING = 6 Loading Loading @@ -717,4 +656,4 @@ class FontFormatPanel(Widget): self.fontfmtLabel.setText(f'TextBlock #{textblk_item.idx}') def on_effectbtn_clicked(self): print('eff cliced!') No newline at end of file self.effect_widget.show() No newline at end of file Loading
ballontranslator/dl/textdetector/textblock.py +45 −34 Original line number Diff line number Diff line from typing import List from typing import List, Tuple import numpy as np from shapely.geometry import Polygon import math Loading Loading @@ -44,6 +44,11 @@ class TextBlock(object): default_stroke_width = 0.2, font_weight = 50, _target_lang: str = "", opacity: float = 1., shadow_radius: float = 0., shadow_strength: float = 1., shadow_color: Tuple = (0, 0, 0), shadow_offset: List = [0, 0], **kwargs) -> None: self.xyxy = [int(num) for num in xyxy] # boundingbox of textblock self.lines = [] if lines is None else lines # polygons of textlines Loading Loading @@ -88,6 +93,12 @@ class TextBlock(object): self.font_weight = font_weight self.accumulate_color = accumulate_color self.opacity = opacity self.shadow_radius = shadow_radius self.shadow_strength = shadow_strength self.shadow_color = shadow_color self.shadow_offset = shadow_offset def adjust_bbox(self, with_bbox=False): lines = self.lines_array().astype(np.int32) if with_bbox: Loading
ballontranslator/ui/combobox.py 0 → 100644 +62 −0 Original line number Diff line number Diff line from qtpy.QtWidgets import QComboBox from qtpy.QtCore import Signal, Qt from qtpy.QtGui import QDoubleValidator, QFocusEvent, QKeyEvent from typing import List class SizeComboBox(QComboBox): apply_change = Signal(float) def __init__(self, val_range: List = None, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.text_changed_by_user = False self.editTextChanged.connect(self.on_text_changed) self.currentIndexChanged.connect(self.on_current_index_changed) self.setEditable(True) self.min_val = val_range[0] self.max_val = val_range[1] validator = QDoubleValidator() if val_range is not None: validator.setTop(val_range[1]) validator.setBottom(val_range[0]) validator.setNotation(QDoubleValidator.Notation.StandardNotation) self.setValidator(validator) self.lineEdit().setValidator(validator) self._value = 0 def keyPressEvent(self, e: QKeyEvent) -> None: key = e.key() if key == Qt.Key.Key_Return or key == Qt.Key.Key_Enter: self.check_change() super().keyPressEvent(e) def focusInEvent(self, e: QFocusEvent) -> None: super().focusInEvent(e) self.text_changed_by_user = False def on_text_changed(self): if self.hasFocus(): self.text_changed_by_user = True def on_current_index_changed(self): if self.hasFocus(): self.check_change() def value(self) -> float: txt = self.currentText() try: val = float(txt) self._value = val return val except: return self._value def setValue(self, value: float): value = min(self.max_val, max(self.min_val, value)) self.setCurrentText(str(round(value, 2))) def check_change(self): if self.text_changed_by_user: self.text_changed_by_user = False self.apply_change.emit(self.value()) No newline at end of file
ballontranslator/ui/constants.py +5 −0 Original line number Diff line number Diff line Loading @@ -19,9 +19,14 @@ CONFIG_COMBOBOX_SHORT = 200 CONFIG_COMBOBOX_MIDEAN = 332 CONFIG_COMBOBOX_LONG = 468 HORSLIDER_FIXHEIGHT = 36 WIDGET_SPACING_CLOSE = 8 TEXTEDIT_FIXWIDTH = 350 TEXTEFFECT_FIXWIDTH = 400 TEXTEFFECT_MAXHEIGHT = 500 LEFTBAR_WIDTH = 60 LEFTBTN_WIDTH = 38 Loading
ballontranslator/ui/drawingpanel.py +4 −8 Original line number Diff line number Diff line Loading @@ -67,8 +67,7 @@ class InpaintPanel(Widget): super().__init__(*args, **kwargs) self.inpainter_panel = inpainter_panel self.thicknessSlider = PaintQSlider(self.tr('pen thickness ') + 'value px', Qt.Orientation.Horizontal) self.thicknessSlider.setFixedHeight(50) self.thicknessSlider = PaintQSlider(self.tr('pen thickness ') + 'value px') self.thicknessSlider.setRange(MIN_PEN_SIZE, MAX_PEN_SIZE) self.thicknessSlider.valueChanged.connect(self.on_thickness_changed) Loading Loading @@ -105,12 +104,10 @@ class PenConfigPanel(Widget): colorChanged = Signal(list) def __init__(self, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.thicknessSlider = PaintQSlider(self.tr('pen thickness ') + 'value px', Qt.Orientation.Horizontal) self.thicknessSlider.setFixedHeight(32) self.thicknessSlider = PaintQSlider(self.tr('pen thickness ') + 'value px') self.thicknessSlider.setRange(MIN_PEN_SIZE, MAX_PEN_SIZE) self.thicknessSlider.valueChanged.connect(self.on_thickness_changed) self.alphaSlider = PaintQSlider(self.tr('alpha value'), Qt.Orientation.Horizontal) self.alphaSlider.setFixedHeight(32) self.alphaSlider = PaintQSlider(self.tr('alpha value')) self.alphaSlider.setRange(0, 255) self.alphaSlider.valueChanged.connect(self.on_alpha_changed) Loading Loading @@ -284,8 +281,7 @@ class DrawingPanel(Widget): self.toolConfigStackwidget.addWidget(self.penConfigPanel) self.toolConfigStackwidget.addWidget(self.rectPanel) self.maskTransperancySlider = PaintQSlider(' value%', Qt.Orientation.Horizontal) self.maskTransperancySlider.setFixedHeight(32) self.maskTransperancySlider = PaintQSlider(' value%') self.maskTransperancySlider.valueChanged.connect(self.canvas.setMaskTransparencyBySlider) masklayout = QHBoxLayout() masklayout.addWidget(ToolNameLabel(220, self.tr('Mask Transparency'))) Loading
ballontranslator/ui/fontformatpanel.py +8 −69 Original line number Diff line number Diff line import functools from typing import List, Tuple, Union from qtpy.QtWidgets import QHBoxLayout, QVBoxLayout, QFrame, QFontComboBox, QComboBox, QApplication, QPushButton, QCheckBox, QLabel from qtpy.QtWidgets import QHBoxLayout, QVBoxLayout, QFrame, QFontComboBox, QApplication, QPushButton, QCheckBox, QLabel from qtpy.QtCore import Signal, Qt from qtpy.QtGui import QColor, QTextCharFormat, QDoubleValidator, QMouseEvent, QFont, QTextCursor, QFocusEvent, QKeyEvent from qtpy.QtGui import QColor, QTextCharFormat, QMouseEvent, QFont, QTextCursor from .stylewidgets import Widget, ColorPicker from .misc import FontFormat, set_html_color, pt2px from .textitem import TextBlkItem from .canvas import Canvas from .constants import CONFIG_FONTSIZE_CONTENT, WIDGET_SPACING_CLOSE from .text_graphical_effect import EffectBtn from .text_graphical_effect import EffectBtn, TextEffectPanel from .combobox import SizeComboBox from . import constants as C from utils.logger import logger as LOGGER # restore text cursor status after formatting def restore_textcursor(formatting_func): Loading Loading @@ -250,64 +249,6 @@ class FormatGroupBtn(QFrame): def setUnderline(self): self.set_underline.emit(self.underlineBtn.isChecked()) class SizeComboBox(QComboBox): apply_change = Signal(float) def __init__(self, val_range: List = None, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.text_changed_by_user = False self.editTextChanged.connect(self.on_text_changed) self.currentIndexChanged.connect(self.on_current_index_changed) self.setEditable(True) self.min_val = val_range[0] self.max_val = val_range[1] validator = QDoubleValidator() if val_range is not None: validator.setTop(val_range[1]) validator.setBottom(val_range[0]) validator.setNotation(QDoubleValidator.Notation.StandardNotation) self.setValidator(validator) self.lineEdit().setValidator(validator) self._value = 0 def keyPressEvent(self, e: QKeyEvent) -> None: key = e.key() if key == Qt.Key.Key_Return or key == Qt.Key.Key_Enter: self.check_change() super().keyPressEvent(e) def focusInEvent(self, e: QFocusEvent) -> None: super().focusInEvent(e) self.text_changed_by_user = False def on_text_changed(self): if self.hasFocus(): self.text_changed_by_user = True def on_current_index_changed(self): if self.hasFocus(): self.check_change() def value(self) -> float: txt = self.currentText() try: val = float(txt) self._value = val return val except: LOGGER.warning(f'SizeComboBox invalid input: {txt}, return {self._value}') return self._value def setValue(self, value: float): value = min(self.max_val, max(self.min_val, value)) self.setCurrentText(str(round(value, 2))) def check_change(self): if self.text_changed_by_user: self.text_changed_by_user = False self.apply_change.emit(self.value()) class FontSizeBox(QFrame): apply_fontsize = Signal(float) Loading @@ -319,17 +260,13 @@ class FontSizeBox(QFrame): self.downBtn.setObjectName("FsizeIncrementDown") self.upBtn.clicked.connect(self.onUpBtnClicked) self.downBtn.clicked.connect(self.onDownBtnClicked) self.fcombobox = SizeComboBox([0, 10000], self) self.fcombobox = SizeComboBox([1, 1000], self) self.fcombobox.addItems([ "5", "5.5", "6.5", "7.5", "8", "9", "10", "10.5", "11", "12", "14", "16", "18", "20", '22', "26", "28", "36", "48", "56", "72" ]) self.fcombobox.apply_change.connect(self.on_fbox_apply_change) validator = QDoubleValidator() validator.setTop(1000) validator.setBottom(1) self.fcombobox.setValidator(validator) hlayout = QHBoxLayout(self) vlayout = QVBoxLayout() Loading Loading @@ -529,6 +466,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() FONTFORMAT_SPACING = 6 Loading Loading @@ -717,4 +656,4 @@ class FontFormatPanel(Widget): self.fontfmtLabel.setText(f'TextBlock #{textblk_item.idx}') def on_effectbtn_clicked(self): print('eff cliced!') No newline at end of file self.effect_widget.show() No newline at end of file