Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I adjust an elbow connector? #1017

Open
Ozymansour opened this issue Oct 5, 2024 · 3 comments
Open

How do I adjust an elbow connector? #1017

Ozymansour opened this issue Oct 5, 2024 · 3 comments

Comments

@Ozymansour
Copy link

Ozymansour commented Oct 5, 2024

The following code creates a connector starting at the top right of a table and ending at a country on a map:

def add_connector(slide, end_shape, start_table, is_left_side: bool, header_textbox):
    _, (end_left, end_top, end_width, end_height) = end_shape
    end_center = Emu(round(end_left + (end_width / 2))), Emu(
        round(end_top + (end_height / 2))
    )
    start_x = Emu(
        start_table.left + start_table.width if is_left_side else start_table.left
    )
    start_y = Emu(start_table.top + (start_table.height / 2) - Cm(1.25))

    connector = slide.shapes.add_connector(
        MSO_CONNECTOR.ELBOW, start_x, start_y, *end_center
    )
    if is_left_side:
        connector.begin_connect(header_textbox, 3)
    else:
        connector.begin_connect(header_textbox, 1)
    print(connector.adjustments)
    connector.line._get_or_add_ln().append(
        parse_xml(
            '<a:tailEnd type="oval" xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"/>'
        )
    )
    connector.line.width = Pt(0.5)
    connector.line.color.rgb = RGBColor(32, 64, 140)

    return connector

This is the current output:
CleanShot 2024-10-05 at 13 06 24@2x

My issue is that the elbow connector always goes down first and then right, instead of just simply going down like so:
CleanShot 2024-10-05 at 13 07 03@2x

This means i'm forced to manually drag that yellow adjustment box in the middle (to the right in this case) to get the desired look. Unfortunately this is quite tiresome when I have many connectors on a deck of slides.

Is there any way to get the connector to display like above instead of it taking many twists and turns?

@scanny
Copy link
Owner

scanny commented Oct 5, 2024

The "little-yellow-box" things are adjustments. The documentation talks about those here: https://python-pptx.readthedocs.io/en/latest/user/autoshapes.html#adjusting-an-autoshape

@Ozymansour
Copy link
Author

The "little-yellow-box" things are adjustments. The documentation talks about those here: https://python-pptx.readthedocs.io/en/latest/user/autoshapes.html#adjusting-an-autoshape

Is a connector an auto-shape? After adding adjs = connector.adjustments to the function above, I keep getting this error:
AttributeError: 'Connector' object has no attribute 'adjustments'

@scanny
Copy link
Owner

scanny commented Oct 7, 2024

Ah, yes, apologies, you're quite right. A connector is a cxnSp element, not an sp element and so doesn't have that attribute.

I believe that attribute could be implemented on Connector but hasn't been yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants