I'm working with wxpython, wxtreectrl and some Arduino sensors.
Is it possible to set a child within the tree dynamically - with a
variable?
Each sensor has an address and reads Temp's and other stats. Addresses
look like 408B2e00.
Python reads the sensor packet and gives:
self.datagen.AL = address of the sensor
self.datagen.Temp = Temperature reading
Currently I can append the address to the tree using:
self.tree.AppendItem(self.xb, self.datagen.AL)
Is there a good way of taking the value of self.datagen.AL to assign the
temperature reading?
Almost like: self.tree.AppendItem(self.datagen.AL, self.datagen.Temp)
I realise I can't do it that way as I'm not specifically giving a name -
unless I misunderstood?
I have attached the full code I have so far as that might help further.
The packets are coming in every 2 seconds or so...oh and I realise
currently it's going to append the address of the sensor each time the
packet comes in but that's still work in progress
Hope that's clear - anything would be helpful to get me past this small
block.
So in other words you are wanting to update the label of some of the items in the tree when you receive new values? If so then one way would be to simply keep a reference to the tree item (returned from AppendItem) and use it to set the new label when it needs to be updated, using something like tree.SetItemText(self.savedItem, newLabel)
Not quite - unless I have misunderstood the role of the label.
For example the address 408b2e00 comes in which I add to the root (XB) with Append Item:
XB
—> 408b2e00
My issues is how do I append the temperature reading to the child 408b2e00? I.e
XB
—> 408b2e00
—> 23c
I would use append item - but I have no idea what the child might be called - 408b2e00 could change every time the program runs.
So I don’t think it’s changing a label - it’s appending a value to a child when the child’s name is contained within a variable. Unless of course I have misunderstood your original answer and can try and put in place what you have suggested?
The only other way I could think - which might be long winded is searching for a child equal to the variable and assigning the temperature to that…again unless I misunderstood.
···
On Sunday, 3 March 2013 21:57:54 UTC, Robin Dunn wrote:
Oliver Taylor wrote:
Hi,
I’m working with wxpython, wxtreectrl and some Arduino sensors.
Is it possible to set a child within the tree dynamically - with a
variable?
Each sensor has an address and reads Temp’s and other stats. Addresses
Is there a good way of taking the value of self.datagen.AL to assign the
temperature reading?
Almost like: self.tree.AppendItem(self.datagen.AL, self.datagen.Temp)
I realise I can’t do it that way as I’m not specifically giving a name -
unless I misunderstood?
I have attached the full code I have so far as that might help further.
The packets are coming in every 2 seconds or so…oh and I realise
currently it’s going to append the address of the sensor each time the
packet comes in but that’s still work in progress
Hope that’s clear - anything would be helpful to get me past this small
block.
So in other words you are wanting to update the label of some of the
items in the tree when you receive new values? If so then one way would
be to simply keep a reference to the tree item (returned from
AppendItem) and use it to set the new label when it needs to be updated,
using something like tree.SetItemText(self.savedItem, newLabel)
Is there a good way of taking the value of self.datagen.AL to assign the
temperature reading?
Almost like: self.tree.AppendItem(self.datagen.AL, self.datagen.Temp)
I realise I can’t do it that way as I’m not specifically giving a name -
unless I misunderstood?
I have attached the full code I have so far as that might help further.
The packets are coming in every 2 seconds or so…oh and I realise
currently it’s going to append the address of the sensor each time the
packet comes in but that’s still work in progress
Hope that’s clear - anything would be helpful to get me past this small
block.
So in other words you are wanting to update the label of some of the
items in the tree when you receive new values? If so then one way would
be to simply keep a reference to the tree item (returned from
AppendItem) and use it to set the new label when it needs to be updated,
using something like tree.SetItemText(self.savedItem, newLabel)
Robin I just tried what you said and you were spot on...it really was
that simple.
Yep, the same principle applies to adding new items in the correct position of the tree too. For example, if you save a reference to the 408b2e00 tree item, probably associated with the name somehow so you can find it later. Then when you want to add a subelement to it later you use that tree item as the parent of the new item.