From 901dcec6333268824e0bfe42d811586b8c735d0d Mon Sep 17 00:00:00 2001 From: kagenihisomi Date: Mon, 29 Jan 2024 19:43:02 +1100 Subject: [PATCH] fix: Multiple textblock select applies the font style changes --- ui/fontformat_commands.py | 40 +++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/ui/fontformat_commands.py b/ui/fontformat_commands.py index a344c904..88bcd6ff 100644 --- a/ui/fontformat_commands.py +++ b/ui/fontformat_commands.py @@ -10,6 +10,7 @@ from . import shared_widget as SW from utils.fontformat import FontFormat from .textitem import TextBlkItem +from itertools import cycle global_default_set_kwargs = dict(set_selected=False, restore_cursor=False) local_default_set_kwargs = dict(set_selected=True, restore_cursor=True) @@ -63,29 +64,36 @@ def wrapper(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, @font_formating() def ffmt_change_family(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs - for blkitem, value in zip(blkitems, values): + vals = cycle(values) + for blkitem, value in zip(blkitems, vals): blkitem.setFontFamily(value, **set_kwargs) @font_formating() def ffmt_change_italic(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs - for blkitem, value in zip(blkitems, values): + vals = cycle(values) + for blkitem, value in zip(blkitems, vals): blkitem.setFontItalic(value, **set_kwargs) @font_formating() def ffmt_change_underline(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs - for blkitem, value in zip(blkitems, values): + vals = cycle(values) + for blkitem, value in zip(blkitems, vals): blkitem.setFontUnderline(value, **set_kwargs) @font_formating() def ffmt_change_weight(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs - for blkitem, value in zip(blkitems, values): + vals = cycle(values) + for blkitem, value in zip(blkitems, vals): blkitem.setFontWeight(value, **set_kwargs) @font_formating() def ffmt_change_bold(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem] = None, **kwargs): + """ + In PyQT, bold is a font weight, unlike italics and underline + """ if not isinstance(blkitems, List): blkitems = [blkitems] if not isinstance(values, List): @@ -99,44 +107,51 @@ def ffmt_change_bold(param_name: str, values: str, act_ffmt: FontFormat, is_glob @font_formating(push_undostack=True) def ffmt_change_letter_spacing(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs - for blkitem, value in zip(blkitems, values): + vals = cycle(values) + for blkitem, value in zip(blkitems, vals): blkitem.setLetterSpacing(value, **set_kwargs) @font_formating(push_undostack=True) def ffmt_change_line_spacing(param_name: str, values: str, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs - for blkitem, value in zip(blkitems, values): + vals = cycle(values) + for blkitem, value in zip(blkitems, vals): blkitem.setLineSpacing(value, **set_kwargs) @font_formating(push_undostack=True) def ffmt_change_vertical(param_name: str, values: bool, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): # set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs - for blkitem, value in zip(blkitems, values): + vals = cycle(values) + for blkitem, value in zip(blkitems, vals): blkitem.setVertical(value) @font_formating() def ffmt_change_frgb(param_name: str, values: tuple, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs - for blkitem, value in zip(blkitems, values): + vals = cycle(values) + for blkitem, value in zip(blkitems, vals): blkitem.setFontColor(value, **set_kwargs) @font_formating(push_undostack=True) def ffmt_change_srgb(param_name: str, values: tuple, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs - for blkitem, value in zip(blkitems, values): + vals = cycle(values) + for blkitem, value in zip(blkitems, vals): blkitem.setStrokeColor(value, **set_kwargs) @font_formating(push_undostack=True) def ffmt_change_stroke_width(param_name: str, values: float, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs - for blkitem, value in zip(blkitems, values): + vals = cycle(values) + for blkitem, value in zip(blkitems, vals): blkitem.blk.stroke_decide_by_colordiff = False blkitem.setStrokeWidth(value, **set_kwargs) @font_formating() def ffmt_change_size(param_name: str, values: float, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): set_kwargs = global_default_set_kwargs if is_global else local_default_set_kwargs - for blkitem, value in zip(blkitems, values): + vals = cycle(values) + for blkitem, value in zip(blkitems, vals): if value < 0: continue blkitem.setFontSize(value, **set_kwargs) @@ -144,5 +159,6 @@ def ffmt_change_size(param_name: str, values: float, act_ffmt: FontFormat, is_gl @font_formating(push_undostack=True) def ffmt_change_alignment(param_name: str, values: float, act_ffmt: FontFormat, is_global: bool, blkitems: List[TextBlkItem], **kwargs): restore_cursor = not is_global - for blkitem, value in zip(blkitems, values): + vals = cycle(values) + for blkitem, value in zip(blkitems, vals): blkitem.setAlignment(value, restore_cursor=restore_cursor) \ No newline at end of file