diff options
Diffstat (limited to 'lib/tartan')
| -rw-r--r-- | lib/tartan/fill_element.py | 3 | ||||
| -rw-r--r-- | lib/tartan/palette.py | 6 | ||||
| -rw-r--r-- | lib/tartan/svg.py | 7 |
3 files changed, 10 insertions, 6 deletions
diff --git a/lib/tartan/fill_element.py b/lib/tartan/fill_element.py index 34139e6c..6666181e 100644 --- a/lib/tartan/fill_element.py +++ b/lib/tartan/fill_element.py @@ -12,12 +12,13 @@ def prepare_tartan_fill_element(element: BaseElement) -> None: :param element: svg element with a fill color (path, rectangle, or circle) """ parent_group = element.getparent() - if parent_group.get_id().startswith('inkstitch-tartan'): + if parent_group is not None and parent_group.get_id().startswith('inkstitch-tartan'): # apply tartan group transform to element transform = element.transform @ parent_group.transform element.set('transform', transform) # remove tartan group and place element in parent group outer_group = parent_group.getparent() + assert outer_group is not None, f"Tartan element {element.get_id()} should have a parent group" outer_group.insert(outer_group.index(parent_group), element) outer_group.remove(parent_group) # make sure the element is invisible diff --git a/lib/tartan/palette.py b/lib/tartan/palette.py index d945eb83..25bd2100 100644 --- a/lib/tartan/palette.py +++ b/lib/tartan/palette.py @@ -5,12 +5,14 @@ # Additional credits to: https://github.com/clsn/pyTartan import re -from typing import List +from typing import TYPE_CHECKING, List, cast import wx from inkex import Color from .colors import string_to_color +if TYPE_CHECKING: + from ..gui.tartan.stripe_panel import StripePanel class Palette: @@ -59,7 +61,7 @@ class Palette: stripes = [] for stripe_sizer in outer_sizer.Children: stripe = {'render': 1, 'color': '#000000', 'width': '5'} - stripe_panel = stripe_sizer.GetWindow() + stripe_panel = cast('StripePanel', stripe_sizer.GetWindow()) stripe['render'] = stripe_panel.visibility.Get3StateValue() stripe['color'] = stripe_panel.colorpicker.GetColour().GetAsString(wx.C2S_HTML_SYNTAX) stripe['width'] = stripe_panel.stripe_width.GetValue() diff --git a/lib/tartan/svg.py b/lib/tartan/svg.py index 497d0199..62d737c9 100644 --- a/lib/tartan/svg.py +++ b/lib/tartan/svg.py @@ -7,7 +7,7 @@ import time from collections import defaultdict from copy import copy from itertools import chain -from typing import List, Optional, Tuple +from typing import List, Optional, Tuple, cast from inkex import BaseElement, Group, Path, PathElement from networkx import MultiGraph, is_empty @@ -66,12 +66,12 @@ class TartanSvgGroup: :param outline: the outline to be filled with the tartan pattern """ parent_group = outline.getparent() - if parent_group.get_id().startswith('inkstitch-tartan'): + if parent_group is not None and parent_group.get_id().startswith('inkstitch-tartan'): # remove everything but the tartan outline for child in parent_group.iterchildren(): if child != outline: parent_group.remove(child) - group = parent_group + group = cast(Group, parent_group) else: group = Group() group.set('id', f'inkstitch-tartan-{int(time.time())}') @@ -86,6 +86,7 @@ class TartanSvgGroup: # set outline invisible outline.style['display'] = 'none' group.append(outline) + return group def _generate_tartan_group_elements(self, group, outline_shape, transform): dimensions, rotation_center = self._get_dimensions(outline_shape) |
