Class GenericDrawPages
Introduction
The GenericDrawPages class represents the collection of pages in a 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(loader))
>>> len(doc.draw_pages)
1
Getting a page
There are several ways to get a page from a draw document.
The simplest is to use the []
method:
Get by page index.
>>> doc = WriteDoc(Write.create_doc(loader))
>>> doc.draw_pages[0]
<ooodev.draw.GenericDrawPage object at 0x7f7f0c0b2b90>
To get the last page in a draw document, use the built in [-1]
method:
>>> doc = WriteDoc(Write.create_doc(loader))
>>> doc.draw_pages[-1]
<ooodev.draw.GenericDrawPage object at 0x7f7f0c0b2b90>
Deleting a page
There are several ways to delete a page from a draw document.
The simplest is to use the del
method:
Delete by page index.
>>> doc = WriteDoc(Write.create_doc(loader))
>>> del doc.draw_pages[0]
Or by DrawPage
object.
>>> doc = WriteDoc(Write.create_doc(loader))
>>> pg = doc.draw_pages[0]
>>> del doc.draw_pages[pg]
or by XDrawPage
object.
>>> doc = WriteDoc(Write.create_doc(loader))
>>> pg = doc.draw_pages[0]
>>> del doc.draw_pages[pg.component]
Iterating over pages
To iterate over the pages in a draw document, use the built in for
loop:
>>> doc = WriteDoc(Write.create_doc(loader))
>>> for pg in doc.slides:
... print(pg)
<ooodev.draw.GenericDrawPage object at 0x7f7f0c0b2b90>
See Also
Class Declaration
- class ooodev.draw.GenericDrawPages(owner, slides, lo_inst=None)[source]
Bases:
LoInstPropsPartial
,OfficeDocumentPropPartial
,DrawPagesComp
,QiPartial
,ServicePartial
,Generic
[_T
]Class for managing Generic Draw Pages.
- __init__(owner, slides, lo_inst=None)[source]
Constructor
- Parameters:
owner (_T) – Owner Document
slides (XDrawPages) – Document Pages.
lo_inst (LoInst, optional) – Lo instance. Defaults to None.
- Return type:
None
- 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
- get_services()
Gets service names for the instance.
- Returns:
service names
- Return type:
List[str]
- 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.
- Raises:
DrawPageMissingError – If unable to get pages.
DrawPageError – If any other error occurs.
- 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
- support_service(*service)
Gets if instance supports a service.
- Parameters:
*service (str) – Variable length argument list of UNO namespace strings such as
com.sun.star.configuration.GroupAccess
- Returns:
True
if instance supports any passed in service; Otherwise,False
- Return type:
bool
- property component: com.sun.star.drawing.DrawPages
DrawPages Component
- Return type:
DrawPages
- property office_doc: OfficeDocumentT
Office Document.
- Return type:
- property owner: _T
Returns: _T: Draw or Impress document.
- Return type:
TypeVar
(_T
, bound= ComponentT)