MCPcopy
hub / github.com/python-openxml/python-docx / TabStops

Class TabStops

src/docx/text/tabstops.py:7–69  ·  view source on GitHub ↗

A sequence of |TabStop| objects providing access to the tab stops of a paragraph or paragraph style. Supports iteration, indexed access, del, and len(). It is accesed using the :attr:`~.ParagraphFormat.tab_stops` property of ParagraphFormat; it is not intended to be constructed dire

Source from the content-addressed store, hash-verified

5
6
7class TabStops(ElementProxy):
8 """A sequence of |TabStop| objects providing access to the tab stops of a paragraph
9 or paragraph style.
10
11 Supports iteration, indexed access, del, and len(). It is accesed using the
12 :attr:`~.ParagraphFormat.tab_stops` property of ParagraphFormat; it is not intended
13 to be constructed directly.
14 """
15
16 def __init__(self, element):
17 super(TabStops, self).__init__(element, None)
18 self._pPr = element
19
20 def __delitem__(self, idx):
21 """Remove the tab at offset `idx` in this sequence."""
22 tabs = self._pPr.tabs
23 try:
24 tabs.remove(tabs[idx])
25 except (AttributeError, IndexError):
26 raise IndexError("tab index out of range")
27
28 if len(tabs) == 0:
29 self._pPr.remove(tabs)
30
31 def __getitem__(self, idx):
32 """Enables list-style access by index."""
33 tabs = self._pPr.tabs
34 if tabs is None:
35 raise IndexError("TabStops object is empty")
36 tab = tabs.tab_lst[idx]
37 return TabStop(tab)
38
39 def __iter__(self):
40 """Generate a TabStop object for each of the w:tab elements, in XML document
41 order."""
42 tabs = self._pPr.tabs
43 if tabs is not None:
44 for tab in tabs.tab_lst:
45 yield TabStop(tab)
46
47 def __len__(self):
48 tabs = self._pPr.tabs
49 if tabs is None:
50 return 0
51 return len(tabs.tab_lst)
52
53 def add_tab_stop(self, position, alignment=WD_TAB_ALIGNMENT.LEFT, leader=WD_TAB_LEADER.SPACES):
54 """Add a new tab stop at `position`, a |Length| object specifying the location
55 of the tab stop relative to the paragraph edge.
56
57 A negative `position` value is valid and appears in hanging indentation. Tab
58 alignment defaults to left, but may be specified by passing a member of the
59 :ref:`WdTabAlignment` enumeration as `alignment`. An optional leader character
60 can be specified by passing a member of the :ref:`WdTabLeader` enumeration as
61 `leader`.
62 """
63 tabs = self._pPr.get_or_add_tabs()
64 tab = tabs.insert_tab_in_order(position, alignment, leader)

Callers 9

tab_stopsMethod · 0.90
clear_all_fixtureMethod · 0.90
del_fixtureMethod · 0.90
del_raises_fixtureMethod · 0.90
add_tab_fixtureMethod · 0.90
index_fixtureMethod · 0.90
iter_fixtureMethod · 0.90
len_fixtureMethod · 0.90

Calls

no outgoing calls

Tested by 8

clear_all_fixtureMethod · 0.72
del_fixtureMethod · 0.72
del_raises_fixtureMethod · 0.72
add_tab_fixtureMethod · 0.72
index_fixtureMethod · 0.72
iter_fixtureMethod · 0.72
len_fixtureMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…