Class ImpressPages
Introduction
The ImpressPages 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 = ImpressDoc.open_doc("test.odp")
>>> len(doc.slides)
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 = ImpressDoc.open_doc("test.odp")
>>> doc.slides[0]
<ooodev.draw.ImpressPage object at 0x7f7f0c0b2b90>
Or by page name.
>>> doc = ImpressDoc.open_doc("test.odp")
>>> doc.slides["page1"]
<ooodev.draw.ImpressPage object at 0x7f7f0c0b2b90>
To get the last page in a draw document, use the built in [-1]
method:
>>> doc = ImpressDoc.open_doc("test.odp")
>>> doc.slides[-1]
<ooodev.draw.ImpressPage object at 0x7f7f0c0b2b90>
Deleting a page
There are several ways to delete a page from an Impress document.
The simplest is to use the del
method:
Delete by page index.
>>> doc = ImpressDoc.open_doc("test.odp")
>>> del doc.slides[0]
Or by page name.
>>> doc = ImpressDoc.open_doc("test.odp")
>>> del doc.slides["page1"]
Or by ImpressPage
object.
>>> doc = ImpressDoc.open_doc("test.odp")
>>> slide = doc.slides[0]
>>> del doc.slides[slide]
or by XDrawPage
object.
>>> doc = ImpressDoc.open_doc("test.odp")
>>> slide = doc.slides[0]
>>> del doc.slides[slide.component]
Iterating over pages
To iterate over the pages in a draw document, use the built in for
loop:
>>> doc = ImpressDoc.open_doc("test.odp")
>>> for slide in doc.slides:
... print(slide)
<ooodev.draw.ImpressPage object at 0x7f7f0c0b2b90>
Class Declaration
- class ooodev.draw.ImpressPages(owner, slides, lo_inst=None)[source]
Bases:
LoInstPropsPartial
,OfficeDocumentPropPartial
,DrawPagesComp
,NameAccessPartial
[XDrawPage
],QiPartial
,ServicePartial
,TheDictionaryPartial
,Generic
[_T
]Class for managing 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_slide(idx)[source]
Deletes a slide
- 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:
ImpressPage[_T]
- get_by_name(name)[source]
Gets the element with the specified name.
- Parameters:
name (str) – The name of the element.
- Raises:
MissingNameError – If unable to find slide with name.
- Returns:
The drawpage with the specified name.
- Return type:
ImpressPage[_T]
- get_count()
Gets the number of elements contained in the container.
- Returns:
The number of elements.
- Return type:
int
- get_element_names()
Gets the names of all elements contained in the container.
- Returns:
The names of all elements.
- Return type:
tuple[str, …]
- 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_by_name(name)
Checks if the container has an element with the specified name.
- Parameters:
name (str) – The name of the element.
- Returns:
True
if the container has an element with the specified name, otherwiseFalse
.- Return type:
bool
- has_elements()
Determines whether the container has elements.
- Return type:
bool
- insert_new_by_index(idx)[source]
Creates and inserts a new DrawPage 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:
ImpressPage[_T]
- insert_slide(idx)[source]
Inserts a slide 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 extra_data: TheDict
Extra Data Key Value Pair Dictionary.
Properties can be assigned properties and access like a dictionary and with dot notation.
Note
This is a dictionary object that can be used to store key value pairs. Generally speaking this data is not part of the object’s main data structure and is not saved with the object (document).
This property is used to store data that is not part of the object’s main data structure and can be used however the developer sees fit.
- Return type:
- property office_doc: OfficeDocumentT
Office Document.
- Return type:
- property owner: _T
Returns: _T: Usually Impress document.
- Return type:
TypeVar
(_T
, bound= ComponentT)