spreadsheet_intelligence.converters package#

Subpackages#

Module contents#

class spreadsheet_intelligence.converters.BentConnector3Converter(connector_anchor_raw: ConnectorAnchorRaw, theme: Theme, id_counter: int)[source]#

Bases: ConnectorConverter

Converter for BentConnector3 drawings.

_abc_impl = <_abc._abc_data object>#
_validate_drawing(drawing: ConnectorRaw)[source]#

Validates that the drawing is of type BentConnector3 and has a valid rotation.

Parameters:

drawing – The raw drawing data.

Raises:

ValueError – If the drawing type is not BentConnector3 or the rotation is invalid.

convert() BentConnector3[source]#

Converts the raw drawing to a BentConnector3 object.

Returns:

A BentConnector3 object.

convert_angle_unit(raw_unit: int) int[source]#

Converts angle from raw units to degrees.

Parameters:

raw_unit – The angle in raw units.

Returns:

The angle in degrees.

extract_endpoints_direction(rotation, flip_h, flip_v, interm_ln_pos)[source]#

Extracts the directions of the arrowheads at both ends.

Parameters:
  • rotation – The rotation of the drawing.

  • flip_h – Whether the drawing is flipped horizontally.

  • flip_v – Whether the drawing is flipped vertically.

  • interm_ln_pos – The position of the intermediate line.

Returns:

A tuple containing the directions of the head and tail.

class spreadsheet_intelligence.converters.StraightConnector1Converter(connector_anchor_raw: ConnectorAnchorRaw, theme: Theme, id_counter: int)[source]#

Bases: ConnectorConverter

Converter for StraightConnector1 drawings.

_abc_impl = <_abc._abc_data object>#
_validate_drawing(drawing: ConnectorRaw)[source]#

Validates that the drawing is of type StraightConnector1.

Parameters:

drawing – The raw drawing data.

Raises:

ValueError – If the drawing type is not StraightConnector1.

convert() StraightConnector1[source]#

Converts the raw drawing to a StraightConnector1 object.

Returns:

A StraightConnector1 object.

class spreadsheet_intelligence.converters.ShapeConverter(shape_anchor_raw: ShapeAnchorRaw, theme: Theme, id_counter: int)[source]#

Bases: BaseDrawingConverter

Converter for shape drawings.

anchor#

The anchor point of the shape.

Type:

Anchor

drawing#

The raw shape data.

Type:

ShapeRaw

theme#

The theme applied to the shape.

Type:

Theme

id_counter#

A counter for generating unique IDs.

Type:

int

TODO: - Text parsing is not implemented when the text contains multiple formats.

_abc_impl = <_abc._abc_data object>#
calc_shape_bbox() tuple[source]#

Calculates the bounding box of the shape after unit conversion.

Returns:

A tuple containing the x, y coordinates and width, height of the shape.

Return type:

tuple

convert() Shape[source]#

Converts the raw shape data into a Shape object.

Returns:

The converted shape object.

Return type:

Shape

convert_unit(raw_unit: int) float[source]#

Converts a raw unit to centimeters.

Parameters:

raw_unit (int) – The raw unit to be converted.

Returns:

The converted unit in centimeters.

Return type:

float

TODO: Allow unit conversion method to be specified globally in settings.

extract_shape_type() ShapeType[source]#

Extracts the shape type from the raw drawing data.

Returns:

The type of the shape.

Return type:

ShapeType

Raises:

ValueError – If the shape type is invalid.

class spreadsheet_intelligence.converters.BaseDrawingConverter(raw: ShapeAnchorRaw | ConnectorAnchorRaw)[source]#

Bases: ABC

Base abstract class for drawing converters.

anchor#

The anchor point of the drawing.

Type:

Anchor

drawing#

The raw drawing data.

Type:

BaseDrawingRaw

refined#

The refined drawing data after conversion.

Type:

Optional[BaseDrawingRaw]

_abc_impl = <_abc._abc_data object>#
static _convert_one_color(scheme_clr: SchemeClr | None, srgb_clr: SrgbClr | None, style_base_ref: StyleBaseRef, theme: Theme) Color[source]#

Converts color information to a Color object.

Parameters:
  • scheme_clr (Optional[SchemeClr]) – The scheme color.

  • srgb_clr (Optional[SrgbClr]) – The sRGB color.

  • style_base_ref (StyleBaseRef) – The style base reference.

  • theme (Theme) – The theme used for color conversion.

Returns:

The converted color object.

Return type:

Color

Raises:

ValueError – If the color type is invalid.

_validate_drawing(drawing: BaseDrawingRaw)[source]#

Validates if the drawing is the expected input for the converter.

Parameters:

drawing (BaseDrawingRaw) – The drawing to validate.

Returns:

True if the drawing is valid, False otherwise.

Return type:

bool

abstractmethod convert()[source]#

Abstract method to convert the drawing.

This method should be implemented by subclasses.