Class DrawPages

Introduction

The DrawPages 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 = DrawDoc.open_doc("test.odg")
>>> 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 = DrawDoc.open_doc("test.odg")
>>> doc.slides[0]
<ooodev.draw.DrawPage object at 0x7f7f0c0b2b90>

Or by page name.

>>> doc = DrawDoc.open_doc("test.odg")
>>> doc.slides["page1"]
<ooodev.draw.DrawPage object at 0x7f7f0c0b2b90>

To get the last page in a draw document, use the built in [-1] method:

>>> doc = DrawDoc(Draw.create_draw_doc(loader))
>>> doc.slides[-1]
<ooodev.draw.DrawPage 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 = DrawDoc.open_doc("test.odg")
>>> del doc.slides[0]

Or by page name.

>>> doc = DrawDoc.open_doc("test.odg")
>>> del doc.slides["page1"]

Or by DrawPage object.

>>> doc = DrawDoc.open_doc("test.odg")
>>> slide = doc.slides[0]
>>> del doc.slides[slide]

or by XDrawPage object.

>>> doc = DrawDoc.open_doc("test.odg")
>>> 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 = DrawDoc.open_doc("test.odg")
>>> for slide in doc.slides:
...     print(slide)
<ooodev.draw.DrawPage object at 0x7f7f0c0b2b90>

Class Declaration

class ooodev.draw.DrawPages(owner, slides, lo_inst=None)[source]

Bases: Generic[_T], LoInstPropsPartial, OfficeDocumentPropPartial, DrawPagesComp, NameAccessPartial[XDrawPage], QiPartial, ServicePartial

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:

DrawPage[DrawDoc]

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:

DrawPage[DrawDoc]

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, otherwise False.

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:

DrawPage

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:
Returns:

New slide that was inserted.

Return type:

DrawPage

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 be None.

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 lo_inst: LoInst

Lo Instance

Return type:

LoInst

property office_doc: OfficeDocumentT

Office Document.

Return type:

OfficeDocumentT

property owner: _T

Returns: _T: Draw or Impress document.

Return type:

TypeVar(_T, bound= ComponentT)