Class WriteDrawPages
Introduction
The WriteDrawPages
class represents the collection of draw pages in a Writer document.
This class contains several python magic methods to make it behave like a collection.
Getting Number of Pages
To get the number of pages in a draw document, use the built in len()
method:
>>> doc = WriteDoc(Write.create_doc())
>>> len(doc.draw_pages)
1
Getting a Draw Page
Get Draw Page by Index.
>>> doc = WriteDoc(Write.create_doc())
>>> doc.draw_pages[0]
<ooodev.write.WriteDrawPage object at 0x7f8b1c0b4a90>
To get the last sheet in a document, use the -1
index:
>>> doc = WriteDoc(Write.create_doc())
>>> doc.draw_pages[-1]
<ooodev.write.WriteDrawPage object at 0x7f8b1c0b4a90>
Alternatively, you can get a draw page direct from Class WriteDoc using the draw_page
property.
Deleting a Draw Page
To delete a sheet, use the del
keyword:
Delete by draw page index.
>>> doc = WriteDoc(Write.create_doc())
>>> # other code
>>> del doc.draw_pages[0]
Iterating over Draw Pages
To iterate over the draw pages in a document, use the for
keyword:
>>> doc = WriteDoc(Write.create_doc())
>>> for draw_page in doc.draw_pages:
... print(draw_page.name)
Class Declaration
- class ooodev.write.WriteDrawPages(owner, slides, lo_inst=None)[source]
Bases:
LoInstPropsPartial
,DrawPagesComp
,WriteDocPropPartial
,QiPartial
Class for managing Writer Draw Pages.
- __delitem__(_item)[source]
Removes a draw page from the document.
- Parameters:
_item (int | WriteDrawPage[WriteDoc] | XDrawPage) – Index, name, or object of the draw page.
- Raises:
TypeError – If the item is not a supported type.
- Return type:
None
- __getitem__(idx)[source]
Gets the draw page at the specified index.
This is short hand for
get_by_index()
.- Parameters:
idx (int) – The index of the draw page. Idx can be a negative value to get from the end of the document.
- Returns:
The drawpage with the specified index.
- Return type:
See also
- __len__()[source]
Gets the number of draw pages in the document.
- Returns:
Number of draw pages in the document.
- Return type:
int
- delete_page(idx)[source]
Deletes a draw page
- Parameters:
idx (int) – Index. Can be a negative value to delete from the end of the document. For example, -1 will delete the last slide.
- Returns:
True
on success; Otherwise,False
- Return type:
bool
- get_by_index(idx)[source]
Gets the element with the specified index.
- Parameters:
idx (int) – The index of the element. Idx can be a negative value to get from the end of the document. For example, -1 will get the last slide.
- Raises:
IndexError – If unable to find slide with index.
- Returns:
The drawpage with the specified index.
- Return type:
- get_count()
Gets the number of elements contained in the container.
- Returns:
The number of elements.
- Return type:
int
- get_element_type()
Gets the type of the elements contained in the container.
- Returns:
The type of the elements.
None
means that it is a multi-type container and you cannot determine the exact types with this interface.- Return type:
Any
- has_elements()
Determines whether the container has elements.
- Return type:
bool
- insert_new_by_index(idx)[source]
Creates and inserts a new GenericDrawPage or MasterPage into this container.
- Parameters:
idx (int) – The index at which the new page will be inserted.
idx
can be a negative value to insert from the end of the document. For example,-1
will insert at the end of the document.- Returns:
The new page.
- Return type:
- insert_page(idx)[source]
Inserts a draw page at the given position in the document
- Parameters:
idx (int) – Index, can be a negative value to insert from the end of the document. For example, -1 will insert at the end of the document.
- Returns:
New slide that was inserted.
- Return type:
- qi(atype, raise_err=False)
Generic method that get an interface instance from an object.
- Parameters:
atype (T) – Interface type to query obj for. Any Uno class that starts with ‘X’ such as XInterface
raise_err (bool, optional) – If True then raises MissingInterfaceError if result is None. Default False
- Raises:
MissingInterfaceError – If ‘raise_err’ is ‘True’ and result is None
- Returns:
instance of interface if supported; Otherwise, None
- Return type:
T | None
Note
When
raise_err=True
return value will never beNone
.
- remove(page)
Removes a DrawPage or MasterPage from this container.
- Parameters:
page (Any) – The page to be removed.
- Return type:
None
- property component: com.sun.star.drawing.DrawPages
DrawPages Component
- Return type:
DrawPages
- property office_doc: OfficeDocumentT
Office Document.
- Return type: