MOUSEDOWN and selection

Hi! I’d like to detect selected nodes on MOUSEDOWN, but it seems like the selecting happens after the callback, doesn’t it?
Here’s what happens:

  1. Nothing is selected;
  2. I click on a node selecting it and expect the callback to recognize it, but it doesn’t;
  3. I click away, nothing is selected, but the callback now prints the previously selected node.

What’s the correct way to achieve it? Tried def mouseDown_ in the select plugin, but it then doesn’t select individual nodes at all.

What are you trying to do?

Trying to do some actions to selected nodes when they are moved. Ideally, just click-and-drag a node should run the code, but MOUSEDOWN doesn’t recognize the node as selected. So it requires the first click to get selection, and then second click and drag to run the code, which doesn’t seem right.

I don’t know if there’s a better way to do it, but now I’m getting selection with MOUSEDOWN (for a single node) and MOUSEUP (for marquee box selection) and run actions with DRAWFOREGROUND.
(also it needs to calculate some stuff at the moment of selection, that’s why its separated from drawforeground)

So you need a notification if selection changes and if nodes are moved? Can you give me a hint what exactly you are trying to do?

Not quite. Here’s a little screengrab: if you first select the node and then drag it, the other nodes adjust accordingly (it gets selection and calculates the relation to other nodes on mousedown). But if you just click+drag in one click, it the MOUSEDOWN doesn’t recognize the node as selected and doesn’t run the code:


Maybe you can register for MOUSEDRAGGED?
How do you switch this mode on or off? Maybe make your own tool. Then you also can respond to the keyboard.

Ooh, just got what you meant before! Yes, is it possible to subscribe to changes in selection and if nodes are moved? I guess it would be better than mousedown/dragged!

I’ll prepare a better example. Ping me if I haven’t posted something in the next few days.

1 Like

Hi Georg, any chance you have time for an example for this?