In an effort to minimize bloat, I'm going to try to just describe the problem and the suspected culprits:
From a Message Handler on a Tree component, I am receiving a TypeError
due to a function in my script returning None
. I am feeding the Tree's items
property to the function as x
:
x = self.props.items
def find_first(obj_to_inspect, val_to_find, listpath=()):
if isinstance(obj_to_inspect, dict):
# Omitted for brevity...
if isinstance(obj_to_inspect, list):
# Omitted for brevity...
if isinstance(obj_to_inspect, str):
# Omitted for brevity...
y = find_first(x, payload)
When I copy and paste the Tree's items
into the script console as x and check the type with type(x)
, I get the expected result that x
is a <type 'list'>
. My function find_first()
therefore works as expected in the script console, and returns a proper data type - a tuple, for what it's worth.
However, when I check the type of x
in the message handler by sending type(x)
to a sibling Label, I get:
class com.inductiveautomation.perspective.gateway.script.PropertyTreeScriptWrapper$ArrayWrapper
This explains why my function is returning None
; it's looking for a list
, dict
, or str
, but getting something different.
I've tried coercing x
into a usable list
via x = list(self.props.items)
, but the type is just changed to class org.python.core.PyList
, and the find_first()
function still returns None
.
So my problem really has two potential solutions:
- How do I convert the Tree's
items
into alist
so I can use it in the message handler'sfind_first()
function? - If Option 1 can't be acheived, how do I alter the
if isinstance()
statements within thefind_first()
function so that they work with the Tree'sself.props.items
data type?