dave-howard / vsdx

vsdx - A python library for processing .vsdx files
BSD 3-Clause "New" or "Revised" License
67 stars 25 forks source link

Retrieve master page info in Shape object #47

Closed jmgarcia-iriusrisk closed 1 year ago

jmgarcia-iriusrisk commented 2 years ago

Hi @dave-howard, I need to access the master page info of a Shape in order to access to their attributes (name, master_base_id, etc..) (AWS-complex-stencils-shapes.zip), as I can see on the code, this master shape is retrieve from here:

image

But then it access the child_shape[0] for retrieve it as master_shape (I don't understand why), in this part I lost track of the page master attributes that I need (name, master_base_id, etc...) As you can see, the child_shape[0].text attribute is not informed, then when trying to access shape.text, the attribute self.master_shape.text will be empty.

I need to access to the value (AWS Step Functions workflow) in the only shape of the vsdx file, should it be updated how to retrieve the master page info in order to do that?

Thank for your help. Cordially, Juan.

jmgarcia-iriusrisk commented 2 years ago

Hi @dave-howard , I just added this comment to the PR: https://github.com/dave-howard/vsdx/pull/48#issuecomment-1195136994

dave-howard commented 2 years ago

Hi @jmgarcia-iriusrisk, I think Shape.text returning an empty string in this case is correct - if we change the behaviour of Shape.text to return value of first child Shape with non-empty text, then that will break some other use cases (i.e. Page.find_shapes_by_text() method) That said - if it would be useful to have a method of a Shape that returns all text, or first text value.

In the example above - if you get shape by id 7 and check it's text property - you'll get the expected text - but the other peer and patrent shapes have an empty text so that's what gets returned

I've added a new test in da2c7e1a that includes your sample file

Dave

jmgarcia-iriusrisk commented 2 years ago

Hi @dave-howard, Thanks for your answer and your time, our problem is that we need to go throug all shape's of a page and retrieving their text. But with the file test_master_multiple_child_shapes.vsdx , in this case, how could we get the text inside the shape (it could have a custom one modified by the user): image

standalone-with-custom-name-AWS-complex-stencils-shapes.zip

jmgarcia-iriusrisk commented 2 years ago

Hi @dave-howard , sorry for insists, but this is a lacking feature we need to implement in our code, What would be the best approach for retrieving this custom text inside the component? Cordially, Juan.

dave-howard commented 1 year ago

Hello - just a thought on an approach you might take to this. You can add a label to the sub-shape in the master that contain the text, and then use an approach similar to that in the test: test_find_shape_by_data_property_label() - this is based on shape with a label in Page object, but same applies to a container shape also.

jmgarcia-iriusrisk commented 1 year ago

Hi @dave-howard! thx for answering. We implemented the following logic for retrieve the text for the master shape:

def get_master_shape_text(shape: Shape) -> str:
    if not shape.master_shape:
        return ""

    result = shape.master_shape.text.replace('\n', '')
    if not result:
        result = get_child_shapes_text(shape.master_shape.child_shapes)

    return (result or "").strip()

def get_child_shapes_text(shapes: [Shape]) -> str:
    if not shapes:
        return ""
    return "".join(shape.text for shape in shapes).replace('\n', '')
dave-howard commented 1 year ago

Thanks for the update also - I can see how that would work fine for what you are doing. I'll close this issue.