dave-howard / vsdx

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

Retrieve master page info in Shape object and master shape name in shape text when it does not exist #48

Closed jmgarcia-iriusrisk closed 2 years ago

jmgarcia-iriusrisk commented 2 years ago

Hi @dave-howard , I have created this pr in order to fix the task Retrieve master page info in Shape object

Thanks for your effort and feel free to reach me in order to do any change.

Cordially, Juan.

dave-howard commented 2 years ago

Hi - I made a few changes. I was a bit confused by the change to Shape.text, so have removed that and updated the test to check the master shape that has the expected text (which happens to be same as the master page name).

I didn't think that Shape.text should return master name when that master shape really had no text

If I have misunderstood please let me know :)

KInd regards Dave

jmgarcia-iriusrisk commented 2 years ago

Hi @dave-howard , thanks for your comment. The change of Shape.text it is due the following behaviour. We are doing something like:

` shapes = vis.pages[0].shapes[0]

for shape in self.page.sub_shapes():

shape.text ` But for the file test_master_multiple_child_shapes.vsdx, the shape.text is empty: image

as the master shape child has more than one child and the text is not in the first one: image

The library is not retrieving that name correctly, I think that the issue, please, correct me if I'm missing something.

Cordially, Juan.

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