[文档]classTabStops(ElementProxy):"""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 directly. """def__init__(self,element):super(TabStops,self).__init__(element,None)self._pPr=elementdef__delitem__(self,idx):"""Remove the tab at offset `idx` in this sequence."""tabs=self._pPr.tabstry:tabs.remove(tabs[idx])except(AttributeError,IndexError):raiseIndexError("tab index out of range")iflen(tabs)==0:self._pPr.remove(tabs)def__getitem__(self,idx):"""Enables list-style access by index."""tabs=self._pPr.tabsiftabsisNone:raiseIndexError("TabStops object is empty")tab=tabs.tab_lst[idx]returnTabStop(tab)def__iter__(self):"""Generate a TabStop object for each of the w:tab elements, in XML document order."""tabs=self._pPr.tabsiftabsisnotNone:fortabintabs.tab_lst:yieldTabStop(tab)def__len__(self):tabs=self._pPr.tabsiftabsisNone:return0returnlen(tabs.tab_lst)
[文档]defadd_tab_stop(self,position,alignment=WD_TAB_ALIGNMENT.LEFT,leader=WD_TAB_LEADER.SPACES):"""Add a new tab stop at `position`, a |Length| object specifying the location of the tab stop relative to the paragraph edge. A negative `position` value is valid and appears in hanging indentation. Tab alignment defaults to left, but may be specified by passing a member of the :ref:`WdTabAlignment` enumeration as `alignment`. An optional leader character can be specified by passing a member of the :ref:`WdTabLeader` enumeration as `leader`. """tabs=self._pPr.get_or_add_tabs()tab=tabs.insert_tab_in_order(position,alignment,leader)returnTabStop(tab)
[文档]defclear_all(self):"""Remove all custom tab stops."""self._pPr._remove_tabs()
[文档]classTabStop(ElementProxy):"""An individual tab stop applying to a paragraph or style. Accessed using list semantics on its containing |TabStops| object. """def__init__(self,element):super(TabStop,self).__init__(element,None)self._tab=element@propertydefalignment(self):"""A member of :ref:`WdTabAlignment` specifying the alignment setting for this tab stop. Read/write. """returnself._tab.val@alignment.setterdefalignment(self,value):self._tab.val=value@propertydefleader(self):"""A member of :ref:`WdTabLeader` specifying a repeating character used as a "leader", filling in the space spanned by this tab. Assigning |None| produces the same result as assigning `WD_TAB_LEADER.SPACES`. Read/write. """returnself._tab.leader@leader.setterdefleader(self,value):self._tab.leader=value@propertydefposition(self):"""A |Length| object representing the distance of this tab stop from the inside edge of the paragraph. May be positive or negative. Read/write. """returnself._tab.pos@position.setterdefposition(self,value):tab=self._tabtabs=tab.getparent()self._tab=tabs.insert_tab_in_order(value,tab.val,tab.leader)tabs.remove(tab)