Class ShapeBase

class ooodev.draw.shapes.ShapeBase(owner, component, lo_inst=None)[source]

Bases: LoInstPropsPartial, OfficeDocumentPropPartial, EventsPartial, ExportJpgPartial, ExportPngPartial, ServicePartial, Generic[_T]

__init__(owner, component, lo_inst=None)[source]

Constructor.

Parameters:
  • lo_inst (LoInst, optional) – Lo instance.

  • owner (_T) –

  • component (XShape) –

Return type:

None

add_event_observers(*args)

Adds observers that gets their trigger method called when this class trigger method is called.

Parameters:

args (EventObserver) – One or more observers to add.

Return type:

None

Note

Observers are removed automatically when they are out of scope.

export_shape_jpg(fnm, resolution=96)

Exports shape as jpg image.

Parameters:
  • fnm (PathOrStr, optional) – Image file name.

  • resolution (int, optional) – Resolution in dpi. Defaults to 96.

Events:
Return type:

None

Note

On exporting event is Class CancelEventArgsExport. On exported event is Class EventArgsExport. Args event_data is a ExportJpgT dictionary.

If fnm is not specified, the image file name is created based on the document name and page number and written to the same folder as the document.

export_shape_png(fnm, resolution=96)

Exports shape as png image.

Parameters:
  • fnm (PathOrStr, optional) – Image file name.

  • resolution (int, optional) – Resolution in dpi. Defaults to 96.

Events:
Return type:

None

Note

On exporting event is Class CancelEventArgsExport. On exported event is Class EventArgsExport. Args event_data is a ExportPngT dictionary.

If fnm is not specified, the image file name is created based on the document name and page number and written to the same folder as the document.

When page is exported as png, such as an impress slide, any images on the will not be exported if filter translucent=True. For this reason, the default value for translucent is False.

get_glue_points()[source]

Gets Glue Points.

Raises:

DrawError – If error occurs.

Returns:

Glue Points.

Return type:

Tuple[GluePoint2, …]

Note

If a glue point can not be accessed then it is ignored.

get_lo_inst()[source]
Return type:

LoInst

get_owner()[source]
Return type:

TypeVar(_T, bound= ComponentT)

get_position_mm()[source]

Gets position in mm units

Raises:

PointError – If error occurs.

Returns:

Position as Point in mm units

Return type:

Point

get_rotation()[source]

Gets the rotation of a shape

Parameters:

shape (XShape) – Shape

Raises:

ShapeError – If error occurs.

Returns:

Rotation angle.

Return type:

Angle

get_services()

Gets service names for the instance.

Returns:

service names

Return type:

List[str]

get_shape_text()[source]

Gets the text from inside a shape.

Raises:

DrawError – If error occurs getting shape text.

Returns:

Shape text

Return type:

str

get_shape_text_cursor()[source]

Gets a cursor object for this text.

Returns:

Cursor.

Return type:

ShapeTextCursor

get_shape_type()[source]

Get the shape type. This is usually a service name and is manually set by the class.

Return type:

str

get_size_mm()[source]

Gets Size in mm units.

Raises:

SizeError – If error occurs.

Returns:

Size in mm units

Return type:

Size

get_text_properties()[source]

Gets the properties associated with the text area inside the shape.

Raises:

PropertySetError – If error occurs.

Returns:

Property Set

Return type:

XPropertySet

get_transformation()[source]

Gets a transformation matrix which seems to represent a clockwise rotation.

Homogeneous matrix has three homogeneous lines

Raises:

ShapeError – If error occurs.

Returns:

Matrix

Return type:

HomogenMatrix3

get_zorder()[source]

Gets the z-order of a shape

Raises:

DrawError – If unable to get z-order.

Returns:

Z-Order

Return type:

int

is_group()[source]

Gets if a shape is a Group Shape

Returns:

True if shape is a group; Otherwise; False.

Return type:

bool

is_image()[source]

Gets if a shape is an image (GraphicObjectShape).

Returns:

True if shape is image; Otherwise, False.

Return type:

bool

move_to_bottom()[source]

Moves the shape to the bottom of the z-order

Raises:
Return type:

None

move_to_top()[source]

Moves the shape to the top of the z-order

Raises:
Return type:

None

remove_event_observer(observer)

Removes an observer

Parameters:

observer (EventObserver) – One or more observers to add.

Returns:

True if observer has been removed; Otherwise, False.

Return type:

bool

set_angle(angle)[source]

Set the line style for a shape

Parameters:

angle (Angle | int) – Angle to set.

Raises:

ShapeError – If error occurs.

Return type:

None

set_bitmap_color(name)[source]

Set bitmap color of a shape.

Parameters:

name (DrawingBitmapKind, str) – Bitmap Name

Raises:
  • NameError – If name is not recognized.

  • ShapeError – If any other error occurs.

Return type:

None

Note

Getting the bitmap color name can be a bit challenging. DrawingBitmapKind contains name displayed in the Bitmap color menu of Draw.

The Easiest way to get the colors is to open Draw and see what bitmap color names are available on your system.

set_bitmap_file_color(fnm)[source]

Set bitmap color from file.

Parameters:

fnm (PathOrStr) – path to file.

Raises:

ShapeError – If error occurs.

Return type:

None

set_dashed_line(is_dashed)[source]

Set a dashed line

Parameters:

is_dashed (bool) – Determines if line is to be dashed or solid.

Raises:

ShapeError – If error occurs.

Return type:

None

set_gradient_color(name: DrawingGradientKind | str)[source]
set_gradient_color(start_color: Color, end_color: Color)
set_gradient_color(start_color: Color, end_color: Color, angle: Angle | int)
set_gradient_color(*args, **kwargs)

Set the gradient color of the shape.

Parameters:
Raises:
  • NameError – If name is not recognized.

  • ShapeError – If any other error occurs.

Returns:

Gradient instance that just had properties set.

Return type:

Gradient

Note

When using Gradient Name.

Getting the gradient color name can be a bit challenging. DrawingGradientKind contains name displayed in the Gradient color menu of Draw.

The Easiest way to get the colors is to open Draw and see what gradient color names are available on your system.

set_gradient_properties(grad)[source]

Sets shapes gradient properties.

Parameters:

grad (Gradient) – Gradient properties to set.

Return type:

None

set_hatch_color(name)[source]

Set hatching color of a shape.

Parameters:

name (DrawingHatchingKind, str) – Hatching Name.

Raises:
  • NameError – If name is not recognized.

  • ShapeError – If any other error occurs.

Return type:

None

Note

Getting the hatching color name can be a bit challenging. DrawingHatchingKind contains name displayed in the Hatching color menu of Draw.

The Easiest way to get the colors is to open Draw and see what gradient color names are available on your system.

set_image(fnm)[source]

Sets the image of a shape.

Parameters:

fnm (PathOrStr) – Path to image.

Raises:

ShapeError – If error occurs.

Return type:

None

set_image_graphic(graphic)[source]

Sets the image of a shape.

Parameters:

graphic (XGraphic) – Graphic.

Raises:

ShapeError – If error occurs.

Return type:

None

set_line_style(style)[source]

Set the line style for a shape.

Parameters:

style (LineStyle) – Line Style.

Raises:

ShapeError – If error occurs.

Return type:

None

set_position(pt: com.sun.star.awt.Point)[source]
set_position(x: int | UnitT, y: int | UnitT)
set_position(*args, **kwargs)

Sets Position of shape.

Parameters:
  • pt (point) – Point that contains x and y positions in mm units.

  • x (int, UnitT) – X position in mm units or UnitT.

  • y (int, UnitT) – Y Position in mm units or UnitT.

Raises:

ShapeError – If error occurs.

Return type:

None

set_props(**props)[source]

Sets properties on a shape.

Parameters:

props (Any) – Key value pairs of property name and property value

Raises:
Return type:

None

Example

set_props(Loop=True, MediaURL=FileIO.fnm_to_url(fnm))
set_rotation(angle)[source]

Set the rotation of a shape.

Parameters:

angle (Angle | int) – Angle or int. An angle value from 0 to 359.

Raises:

ShapeError – If error occurs.

Return type:

None

set_size(sz: object)[source]
set_size(width: int | UnitT, height: int | UnitT)
set_size(*args, **kwargs)

Sets set_size of shape.

Parameters:
  • sz (Size) – Size that contains width and height positions in mm units.

  • width (int, UnitT) – Width position in mm units or UnitT.

  • height (int, UnitT) – Height position in mm units or UnitT.

Raises:

ShapeError – If error occurs.

Return type:

None

set_style(graphic_styles, style_name)[source]

Set the graphic style for a shape.

Parameters:
  • graphic_styles (XNameContainer) – Graphic styles.

  • style_name (GraphicStyleKind | str) – Graphic Style Name.

Raises:

DrawError – If error occurs.

Return type:

None

set_transparency(level)[source]

Sets the transparency level for the shape. Higher level means more transparent.

Parameters:

level (Intensity, int) – Transparency value. Represents a intensity value from 0 to 100.

Raises:

ShapeError – If error occurs.

Return type:

None

set_visible(is_visible)[source]

Set the line style for a shape.

Parameters:

is_visible (bool) – Set is shape is visible or not.

Raises:

ShapeError – If error occurs.

Return type:

None

set_zorder(order)[source]

Sets the z-order of a shape.

Parameters:

order (int) – Z-Order.

Raises:

DrawError – If unable to set z-order.

Return type:

None

subscribe_event(event_name, callback)

Add an event listener to current instance.

Parameters:
  • event_name (str) – Event Name.

  • callback (EventCallback) – Callback of the event listener.

Return type:

None

subscribe_event_shape_jpg_exported(callback)

Add an event listener to current instance that is triggered on export complete.

Parameters:

callback (Callable[[Any, EventArgsExport[ExportJpgT]], None]) – Callback of the event listener.

Return type:

None

subscribe_event_shape_jpg_exporting(callback)

Add an event listener to current instance that is triggered on exporting.

Parameters:

callback (Callable[[Any, CancelEventArgsExport[ExportJpgT]], None]) – Callback of the event listener.

Return type:

None

subscribe_event_shape_png_exported(callback)

Add an event listener to current instance that is triggered on export complete.

Parameters:

callback (Callable[[Any, EventArgsExport[ExportPngT]], None]) – Callback of the event listener.

Return type:

None

subscribe_event_shape_png_exporting(callback)

Add an event listener to current instance that is triggered on exporting.

Parameters:

callback (Callable[[Any, CancelEventArgsExport[ExportPngT]], None]) – Callback of the event listener.

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

trigger_event(event_name, event_args)

Trigger an event on current instance.

Parameters:
  • event_name (str) – Event Name.

  • event_args (EventArgsT) – Event Args.

Return type:

None

unsubscribe_event(event_name, callback)

Remove an event listener from current instance.

Parameters:
  • event_name (str) – Event Name.

  • callback (EventCallback) – Callback of the event listener.

Return type:

None

unsubscribe_event_shape_jpg_exported(callback)

Remove an event listener from current instance.

Parameters:

callback (Callable[[Any, EventArgsExport[ExportJpgT]], None]) – Callback of the event listener.

Return type:

None

unsubscribe_event_shape_jpg_exporting(callback)

Remove an event listener from current instance.

Parameters:

callback (Callable[[Any, CancelEventArgsExport[ExportJpgT]], None]) – Callback of the event listener.

Return type:

None

unsubscribe_event_shape_png_exported(callback)

Remove an event listener from current instance.

Parameters:

callback (Callable[[Any, EventArgsExport[ExportPngT]], None]) – Callback of the event listener.

Return type:

None

unsubscribe_event_shape_png_exporting(callback)

Remove an event listener from current instance.

Parameters:

callback (Callable[[Any, CancelEventArgsExport[ExportPngT]], None]) – Callback of the event listener.

Return type:

None

property component: XShape

Gets the component.

Return type:

XShape

property event_observer: EventObserver

Gets/Sets The Event Observer for this instance.

Return type:

EventObserver

property lo_inst: LoInst

Lo Instance

Return type:

LoInst

property office_doc: OfficeDocumentT

Office Document.

Return type:

OfficeDocumentT

property owner: _T

Component Owner

Return type:

TypeVar(_T, bound= ComponentT)

property position: PointStructGenericComp[UnitMM]

Gets/Sets the position of the shape in UnitMM Values.

When setting this value, it can be set with a com.sun.star.awt.Position instance or a PointStructGenericComp instance.

The Position can be set by just setting a Position property.

Returns:

Position in UnitMM Values.

Return type:

PointStructGenericComp[UnitMM]

Note

This is the position as reported by the shape. This is not the same as the position of the shape on the page. The position of the shape on the page includes is from the page margins.

For instance if the page has a margin of 10mm and the shape is at position (15, 15) then the position of the shape in the Draw Dialog box is (5, 5) where as this position property will report (15, 15).

Example

Can be set by just setting a Position property using int or UnitMM.

shape.position.x = 1000 # 10 mm
shape.position.y = UnitMM(20) # 20 mm

Can also be set using any UnitT object.

shape.position.x = UnitCM(1.2)
shape.position.y = UnitMM(40)

Can also be set using a com.sun.star.awt.Position struct.

shape.position = Position(1000, 2000) # in 1/100mm
property shape_type: str

Gets the shape type.

Return type:

str

property size: SizeStructGenericComp[UnitMM]

Gets/Sets the size of the shape in UnitMM Values.

When setting this value, it can be set with a com.sun.star.awt.Size instance or a SizeStructGenericComp instance.

The Size can be set by just setting a Size property.

Returns:

Size in UnitMM Values.

Return type:

SizeStructGenericComp[UnitMM]

Example

Can be set by just setting a Size property using int or UnitMM.

shape.size.width = 1000 # 10 mm
shape.size.height = UnitMM(20) # 20 mm

Can also be set using any UnitT object.

shape.size.width = UnitCM(1.2)
shape.size.height = UnitMM(40)

Can also be set using a com.sun.star.awt.Size struct.

shape.size = Size(1000, 2000) # in 1/100mm