dave-howard / vsdx

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

Find by text != Find by data label #32

Closed nicholas-hartley closed 2 years ago

nicholas-hartley commented 2 years ago

Hey,

I was playing around with this library (very nice) and I noticed that when I found an object with find_by_text and find_by_data_label they did not show as being equal. I have a million guesses as to why, but figured I would point it out in case if y'all thought it would be a good idea to overwrite the == assignment operator.

Code that showed the result shown below, I had a single object with 'Start2' as the text on it an a data property with label: 'One', Name: 'Two', Value: 'Three'

with VisioFile('Test2.vsdx') as vis:
    page = vis.get_page(0)
    shape = page.find_shape_by_text('Start2')
    props = shape.data_properties

    for property_label in props.keys():
            prop = props[property_label]
            print(f"prop: lbl:'{prop.label}' name:'{prop.name}': val:'{prop.value}'")

    # print(props)

    shape2 = page.find_shape_by_property_label('One')
    props2 = shape2.data_properties

    for property_label in props2.keys():
            prop = props2[property_label]
            print(f"prop: lbl:'{prop.label}' name:'{prop.name}': val:'{prop.value}'")

    print(shape2 == shape)
stevensultana commented 2 years ago

Thanks! Indeed the same issue can be seen just by:

from vsdx import VisioFile

with VisioFile('issue32.vsdx') as vis:
    page = vis.get_page(0)
    shape = page.find_shape_by_text('Start2')
    shape2 = page.find_shape_by_text('Start2')
    print(shape2 == shape)

The issue is simply that the find_* methods re-create the list of Shapes internally. As you said, overriding == resolves this anomaly.