1
- from typing import List , Optional , Tuple , Union
1
+ from typing import List , Optional , Tuple , Union , Generator
2
2
from warnings import warn
3
3
4
4
import napari .qt
@@ -41,6 +41,22 @@ def __contains__(self, val: int) -> bool:
41
41
return True
42
42
43
43
44
+ def _logical_lines (
45
+ nodes : List [tinycss2 .ast .Node ],
46
+ ) -> Generator [Tuple [tinycss2 .ast .Node , tinycss2 .ast .Node ], None , None ]:
47
+ """Generator to provide logical lines (thing: value) of css (terminated by ';')"""
48
+ logical_line = []
49
+ ident , dimension = None , None
50
+ for node in nodes :
51
+ if node == ";" :
52
+ yield (ident , dimension )
53
+ ident , dimension = None , None
54
+ elif node .type == "ident" :
55
+ ident = node
56
+ elif node .type == "dimension" :
57
+ dimension = node
58
+
59
+
44
60
def _has_id (nodes : List [tinycss2 .ast .Node ], id_name : str ) -> bool :
45
61
"""
46
62
Is `id_name` in IdentTokens in the list of CSS `nodes`?
@@ -61,12 +77,8 @@ def _get_dimension(
61
77
None if no IdentToken is found.
62
78
"""
63
79
cleaned_nodes = [node for node in nodes if node .type != "whitespace" ]
64
- for name , _ , value , _ in zip (* (iter (cleaned_nodes ),) * 4 ):
65
- if (
66
- name .type == "ident"
67
- and value .type == "dimension"
68
- and name .value == id_name
69
- ):
80
+ for name , value in _logical_lines (cleaned_nodes ):
81
+ if name .value == id_name :
70
82
return value .int_value
71
83
warn (f"Unable to find DimensionToken for { id_name } " , RuntimeWarning )
72
84
return None
0 commit comments