Loading launch.py +2 −0 Original line number Diff line number Diff line Loading @@ -209,6 +209,8 @@ def main(): for font in os.listdir(PATH_FONTS): if font.endswith(('.ttf','.otf')): QFontDatabase.addApplicationFont((PATH_FONTS/font).as_posix()) shared.FONT_FAMILIES = set(f.lower() for f in QFontDatabase.families()) yahei = QFont('Microsoft YaHei UI') if yahei.exactMatch() and not sys.platform == 'darwin': QGuiApplication.setFont(yahei) Loading ui/fontformat_commands.py +9 −14 Original line number Diff line number Diff line Loading @@ -18,25 +18,22 @@ local_default_set_kwargs = dict(set_selected=True, restore_cursor=True) class TextStyleUndoCommand(QUndoCommand): def __init__(self, style_func: Callable, redo_params: Dict, undo_params: Dict): def __init__(self, style_func: Callable, params: Dict, redo_values: List, undo_values: List): super().__init__() self.style_func = style_func self.redo_params = redo_params self.undo_params = undo_params self.params = params self.redo_values = redo_values self.undo_values = undo_values def redo(self) -> None: self.style_func(**self.redo_params) self.style_func(values=self.redo_values, **self.params) def undo(self) -> None: self.style_func(**self.undo_params) self.style_func(values=self.undo_values, **self.params) def font_formating(push_undostack: bool = False): """ let's hope it will make it easier to implement redo/undo behavior for these formatting op """ def func_wrapper(formatting_func): def wrapper(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem] = None, set_focus: bool = False, *args, **kwargs): Loading @@ -49,12 +46,10 @@ def font_formating(push_undostack: bool = False): blkitems = blkitems if isinstance(blkitems, List) else [blkitems] if len(blkitems) > 0: if push_undostack: redo_params = copy.deepcopy(kwargs) redo_params.update({'param_name': param_name, 'values': values, 'act_ffmt': act_ffmt, 'is_global': is_global, 'blkitems': blkitems}) undo_params = copy.deepcopy(kwargs) params = copy.deepcopy(kwargs) params.update({'param_name': param_name, 'act_ffmt': act_ffmt, 'is_global': is_global, 'blkitems': blkitems}) undo_values = [blkitem.getFontFormatAttr(param_name) for blkitem in blkitems] undo_params.update({'param_name': param_name, 'values': undo_values, 'act_ffmt': act_ffmt, 'is_global': is_global, 'blkitems': blkitems}) cmd = TextStyleUndoCommand(formatting_func, redo_params, undo_params) cmd = TextStyleUndoCommand(formatting_func, params, values, undo_values) SW.canvas.push_undo_command(cmd) else: formatting_func(param_name, values, act_ffmt, is_global, blkitems, *args, **kwargs) Loading ui/fontformatpanel.py +21 −7 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ from qtpy.QtWidgets import QComboBox, QMenu, QMessageBox, QStackedLayout, QGraph from qtpy.QtCore import Signal, Qt, QRectF from qtpy.QtGui import QDoubleValidator, QFocusEvent, QMouseEvent, QTextCursor, QFontMetrics, QIcon, QColor, QPixmap, QPainter, QContextMenuEvent, QKeyEvent from utils.fontformat import FontFormat from utils import shared from utils.config import pcfg, save_text_styles, text_styles Loading Loading @@ -33,6 +34,10 @@ class LineEdit(QLineEdit): def on_editing_finished(self): self._text_changed = False def focusOutEvent(self, e: QFocusEvent) -> None: self._text_changed = False return super().focusOutEvent(e) def on_return_pressed(self): if not self._text_changed: self.return_pressed_wochange.emit() Loading Loading @@ -319,20 +324,29 @@ class FontFamilyComboBox(QFontComboBox): def __init__(self, emit_if_focused=True, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.currentFontChanged.connect(self.on_fontfamily_changed) lineedit = LineEdit(parent=self) self.lineedit = lineedit = LineEdit(parent=self) lineedit.return_pressed_wochange.connect(self.apply_fontfamily) self.setLineEdit(lineedit) self.emit_if_focused = emit_if_focused self._current_font = self.currentFont().family().lower() def apply_fontfamily(self): if self.currentFont().exactMatch(): self.param_changed.emit('family', self.currentText()) ffamily = self.currentFont().family().lower() if ffamily in shared.FONT_FAMILIES: self.param_changed.emit('family', ffamily) self._current_font = ffamily def on_fontfamily_changed(self): if not self.hasFocus(): self._current_font = self.currentFont().family().lower() self.lineedit._text_changed = False if self.emit_if_focused and not self.hasFocus(): return if self.currentFont().exactMatch(): self.param_changed.emit('family', self.currentText()) ffamily = self.currentFont().family().lower() if self._current_font != ffamily: self.apply_fontfamily() CHEVRON_SIZE = 20 def chevron_down(): Loading ui/texteditshapecontrol.py +1 −8 Original line number Diff line number Diff line Loading @@ -195,14 +195,7 @@ class TextBlkShapeControl(QGraphicsRectItem): super().__init__() self.gv = parent self.ctrlblock_group = [ ControlBlockItem(self, 0), ControlBlockItem(self, 1), ControlBlockItem(self, 2), ControlBlockItem(self, 3), ControlBlockItem(self, 4), ControlBlockItem(self, 5), ControlBlockItem(self, 6), ControlBlockItem(self, 7), ControlBlockItem(self, idx) for idx in range(8) ] self.previewPixmap = QGraphicsPixmapItem(self) Loading utils/shared.py +2 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,8 @@ cache_path: str = osp.join(PROGRAM_PATH, '.btrans_cache/cache.json') CACHE_UPDATED = False check_local_file_hash = True FONT_FAMILIES: set = None def load_cache(): global cache_data if cache_data is None: Loading Loading
launch.py +2 −0 Original line number Diff line number Diff line Loading @@ -209,6 +209,8 @@ def main(): for font in os.listdir(PATH_FONTS): if font.endswith(('.ttf','.otf')): QFontDatabase.addApplicationFont((PATH_FONTS/font).as_posix()) shared.FONT_FAMILIES = set(f.lower() for f in QFontDatabase.families()) yahei = QFont('Microsoft YaHei UI') if yahei.exactMatch() and not sys.platform == 'darwin': QGuiApplication.setFont(yahei) Loading
ui/fontformat_commands.py +9 −14 Original line number Diff line number Diff line Loading @@ -18,25 +18,22 @@ local_default_set_kwargs = dict(set_selected=True, restore_cursor=True) class TextStyleUndoCommand(QUndoCommand): def __init__(self, style_func: Callable, redo_params: Dict, undo_params: Dict): def __init__(self, style_func: Callable, params: Dict, redo_values: List, undo_values: List): super().__init__() self.style_func = style_func self.redo_params = redo_params self.undo_params = undo_params self.params = params self.redo_values = redo_values self.undo_values = undo_values def redo(self) -> None: self.style_func(**self.redo_params) self.style_func(values=self.redo_values, **self.params) def undo(self) -> None: self.style_func(**self.undo_params) self.style_func(values=self.undo_values, **self.params) def font_formating(push_undostack: bool = False): """ let's hope it will make it easier to implement redo/undo behavior for these formatting op """ def func_wrapper(formatting_func): def wrapper(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem] = None, set_focus: bool = False, *args, **kwargs): Loading @@ -49,12 +46,10 @@ def font_formating(push_undostack: bool = False): blkitems = blkitems if isinstance(blkitems, List) else [blkitems] if len(blkitems) > 0: if push_undostack: redo_params = copy.deepcopy(kwargs) redo_params.update({'param_name': param_name, 'values': values, 'act_ffmt': act_ffmt, 'is_global': is_global, 'blkitems': blkitems}) undo_params = copy.deepcopy(kwargs) params = copy.deepcopy(kwargs) params.update({'param_name': param_name, 'act_ffmt': act_ffmt, 'is_global': is_global, 'blkitems': blkitems}) undo_values = [blkitem.getFontFormatAttr(param_name) for blkitem in blkitems] undo_params.update({'param_name': param_name, 'values': undo_values, 'act_ffmt': act_ffmt, 'is_global': is_global, 'blkitems': blkitems}) cmd = TextStyleUndoCommand(formatting_func, redo_params, undo_params) cmd = TextStyleUndoCommand(formatting_func, params, values, undo_values) SW.canvas.push_undo_command(cmd) else: formatting_func(param_name, values, act_ffmt, is_global, blkitems, *args, **kwargs) Loading
ui/fontformatpanel.py +21 −7 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ from qtpy.QtWidgets import QComboBox, QMenu, QMessageBox, QStackedLayout, QGraph from qtpy.QtCore import Signal, Qt, QRectF from qtpy.QtGui import QDoubleValidator, QFocusEvent, QMouseEvent, QTextCursor, QFontMetrics, QIcon, QColor, QPixmap, QPainter, QContextMenuEvent, QKeyEvent from utils.fontformat import FontFormat from utils import shared from utils.config import pcfg, save_text_styles, text_styles Loading Loading @@ -33,6 +34,10 @@ class LineEdit(QLineEdit): def on_editing_finished(self): self._text_changed = False def focusOutEvent(self, e: QFocusEvent) -> None: self._text_changed = False return super().focusOutEvent(e) def on_return_pressed(self): if not self._text_changed: self.return_pressed_wochange.emit() Loading Loading @@ -319,20 +324,29 @@ class FontFamilyComboBox(QFontComboBox): def __init__(self, emit_if_focused=True, *args, **kwargs) -> None: super().__init__(*args, **kwargs) self.currentFontChanged.connect(self.on_fontfamily_changed) lineedit = LineEdit(parent=self) self.lineedit = lineedit = LineEdit(parent=self) lineedit.return_pressed_wochange.connect(self.apply_fontfamily) self.setLineEdit(lineedit) self.emit_if_focused = emit_if_focused self._current_font = self.currentFont().family().lower() def apply_fontfamily(self): if self.currentFont().exactMatch(): self.param_changed.emit('family', self.currentText()) ffamily = self.currentFont().family().lower() if ffamily in shared.FONT_FAMILIES: self.param_changed.emit('family', ffamily) self._current_font = ffamily def on_fontfamily_changed(self): if not self.hasFocus(): self._current_font = self.currentFont().family().lower() self.lineedit._text_changed = False if self.emit_if_focused and not self.hasFocus(): return if self.currentFont().exactMatch(): self.param_changed.emit('family', self.currentText()) ffamily = self.currentFont().family().lower() if self._current_font != ffamily: self.apply_fontfamily() CHEVRON_SIZE = 20 def chevron_down(): Loading
ui/texteditshapecontrol.py +1 −8 Original line number Diff line number Diff line Loading @@ -195,14 +195,7 @@ class TextBlkShapeControl(QGraphicsRectItem): super().__init__() self.gv = parent self.ctrlblock_group = [ ControlBlockItem(self, 0), ControlBlockItem(self, 1), ControlBlockItem(self, 2), ControlBlockItem(self, 3), ControlBlockItem(self, 4), ControlBlockItem(self, 5), ControlBlockItem(self, 6), ControlBlockItem(self, 7), ControlBlockItem(self, idx) for idx in range(8) ] self.previewPixmap = QGraphicsPixmapItem(self) Loading
utils/shared.py +2 −0 Original line number Diff line number Diff line Loading @@ -91,6 +91,8 @@ cache_path: str = osp.join(PROGRAM_PATH, '.btrans_cache/cache.json') CACHE_UPDATED = False check_local_file_hash = True FONT_FAMILIES: set = None def load_cache(): global cache_data if cache_data is None: Loading