How to execute a function after an event resolves (syncing cursors between two trees) #6099
Closed
aaronrudkin
started this conversation in
General
Replies: 1 comment
-
Well, I feel sheepish, because I had totally missed the |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
In my program, two trees are next to each other. The trees have the same nodes, but the right tree will display a transformed version of the node name. I want to be able to sync cursor highlighting (so if I move down through the left tree, the right tree is moved down the same way and vice versa).
The left tree and right tree are both child classes of a BaseTree class which in turn inherits Tree. At the BaseTree level, I capture an
on_key
event in the tree in the following manner:The sync function is fairly trivial and boils down to
self.cursor_node.data.get("unique_id")
(which is how I'm identifying the node) and passing that as an argument to a move_cursor call in the other tree. I don't think anything about my problem is specific to how I implement this portion of the code.The problem is that the sync fires off before the cursor is moved rather than after. I investigated the documentation and it seemed like the correct way to solve this would be to use the message queue, because any message inserted into the queue would resolve after the cursor event resolved.
So I updated the outer code to:
and made a custom message type etc. This is clunkier, but I figured it would work. But this also fires off before the cursor is moved rather than after. I want the sync to occur after the cursor has been moved.
What am I missing? My next proposed solutions are using
set_interval
or similar to delay the event a fixed time period (this seems yucky) or investigating whether the event should occur at the node level rather than the tree level. It feels like what I want is basically a callback that executes after the whole event stack has resolved.Any thoughts? Thanks.
Beta Was this translation helpful? Give feedback.
All reactions