Skip to content

Commit 7dafb70

Browse files
author
Steve Canny
committed
style: add BaseStyle.quick_format getter
1 parent 82fbefc commit 7dafb70

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-1
lines changed

docx/oxml/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ def OxmlElement(nsptag_str, attrs=None, nsdecls=None):
116116
from .styles import CT_Style, CT_Styles
117117
register_element_cls('w:basedOn', CT_String)
118118
register_element_cls('w:name', CT_String)
119+
register_element_cls('w:qFormat', CT_OnOff)
119120
register_element_cls('w:semiHidden', CT_OnOff)
120121
register_element_cls('w:style', CT_Style)
121122
register_element_cls('w:styles', CT_Styles)

docx/oxml/styles.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class CT_Style(BaseOxmlElement):
4646
uiPriority = ZeroOrOne('w:uiPriority', successors=_tag_seq[8:])
4747
semiHidden = ZeroOrOne('w:semiHidden', successors=_tag_seq[9:])
4848
unhideWhenUsed = ZeroOrOne('w:unhideWhenUsed', successors=_tag_seq[10:])
49+
qFormat = ZeroOrOne('w:qFormat', successors=_tag_seq[11:])
4950
pPr = ZeroOrOne('w:pPr', successors=_tag_seq[17:])
5051
rPr = ZeroOrOne('w:rPr', successors=_tag_seq[18:])
5152
del _tag_seq
@@ -110,6 +111,16 @@ def name_val(self, value):
110111
name = self._add_name()
111112
name.val = value
112113

114+
@property
115+
def qFormat_val(self):
116+
"""
117+
Value of `w:qFormat/@w:val` or |False| if not present.
118+
"""
119+
qFormat = self.qFormat
120+
if qFormat is None:
121+
return False
122+
return qFormat.val
123+
113124
@property
114125
def semiHidden_val(self):
115126
"""

docx/styles/style.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ def priority(self):
101101
def priority(self, value):
102102
self._element.uiPriority_val = value
103103

104+
@property
105+
def quick_style(self):
106+
"""
107+
|True| if this style should be displayed in the style gallery when
108+
:attr:`.hidden` is |False|. Read/write Boolean.
109+
"""
110+
return self._element.qFormat_val
111+
104112
@property
105113
def style_id(self):
106114
"""

features/sty-style-props.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ Feature: Get and set style properties
8181
| 42 | None | None |
8282

8383

84-
@wip
8584
Scenario Outline: Get quick-style value
8685
Given a style having quick-style set <setting>
8786
Then style.quick_style is <value>

tests/styles/test_style.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ def it_can_change_its_unhide_when_used_value(self, unhide_set_fixture):
150150
style.unhide_when_used = value
151151
assert style._element.xml == expected_xml
152152

153+
def it_knows_its_quick_style_setting(self, quick_get_fixture):
154+
style, expected_value = quick_get_fixture
155+
assert style.quick_style == expected_value
156+
153157
def it_can_delete_itself_from_the_document(self, delete_fixture):
154158
style, styles, expected_xml = delete_fixture
155159
style.delete()
@@ -265,6 +269,17 @@ def priority_set_fixture(self, request):
265269
expected_xml = xml(expected_cxml)
266270
return style, value, expected_xml
267271

272+
@pytest.fixture(params=[
273+
('w:style', False),
274+
('w:style/w:qFormat', True),
275+
('w:style/w:qFormat{w:val=0}', False),
276+
('w:style/w:qFormat{w:val=on}', True),
277+
])
278+
def quick_get_fixture(self, request):
279+
style_cxml, expected_value = request.param
280+
style = BaseStyle(element(style_cxml))
281+
return style, expected_value
282+
268283
@pytest.fixture(params=[
269284
('w:style', WD_STYLE_TYPE.PARAGRAPH),
270285
('w:style{w:type=paragraph}', WD_STYLE_TYPE.PARAGRAPH),

0 commit comments

Comments
 (0)