New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dragging LinearRegion limits with mouse #2528
Comments
Am I correct that you would like the camera to still work if the linear region is not selected? You mentioned that so far you've been able to connect the mouse events to the callback functions, but I don't see any callback functions in your example code? Could you give a minimal example that shows what you have so far including any callbacks and mouse event handling you have? You may need to do some fancy "picking" to determine if you're clicking on a Visual (the linear region) versus clicking on the viewbox (controlled by the camera). But I can't tell you exactly where code would have to change without the code you have so far. |
What i d like is that when i have a mouse event close to the limits of the linear region, instead of moving the camera around, the mouse d just move the limits of the linear region. Here i have the code with the callback functions. So when i detect the event in the "picking regions" i d like to avoid camera moving and just drag the vertical lines. hope i am being more clear this time :S
|
I'm playing around with the code. I'll get back to you on some ideas. In the mean time, be careful of your use of tabs in your python code. Always use spaces (preferably 4). You have tabs in your mouse press handler. |
Let me know if any part of this is not what you were hoping for, but here are some things I got to work. Even as the maintainer of vispy, I have to relearn a lot of this stuff every time it comes up (an obvious sign I need to put it in the documentation more). Also note there may be smarter ways of doing this, but this introduces some important concepts. The top portion of your script is unchanged as well as the very bottom with the vert_region2 = scene.LinearRegion([549.2, 700], [0.0, 1.0, 0.0, 0.3],
vertical=True,
parent=viewbox.scene)
# let the SceneCanvas "picking" logic know that this Visual can be "clicked on"
vert_region2.interactive = True
def on_mouse_press(event):
mouse_event = event.mouse_event
modifiers = [key.name for key in mouse_event.modifiers]
print('Mouse: - pos: %r, button: %s, modifiers: %s, delta: %r' % (event.pos, mouse_event.button, modifiers, mouse_event.delta))
vis = event.visual
print("Visual at mouse: ", vis)
#vis = canvas.visual_at(event.pos) # not used but could be useful
if vis is vert_region2:
# the SceneCanvas mouse handler will see this and not pass the event on
# to the camera for handling
event.handled = True
def on_mouse_move(event):
if event.visual is vert_region2:
event.handled = True
print("Moving region", event.visual)
# TODO: Do something to the visual based on mouse movement
def on_mouse_release(event):
if event.mouse_event.is_dragging:
print("Dragging release")
vert_region2.events.mouse_press.connect(on_mouse_press)
vert_region2.events.mouse_move.connect(on_mouse_move)
vert_region2.events.mouse_release.connect(on_mouse_release) The key takeaways:
Hopefully this gives you enough information to be dangerous. Let me know if you have more questions. |
I have been playing around a bit considering your comments and i can actually update the linear region boundaries. But for some reason the data is not set on real time, i just see the result in the display after the mouse release. It also takes a long time to set the new boundaries. Is there a way to optimize this behaviour?
Thanks for all the effort!! |
Two things:
This fixes the basic behavior, but it only seems to work on the first click and drag of a specific side. If you then click and drag the other side it works, but the original side is "snapped" back to its original position. This makes me think either the |
I made some debugging and i see that after the set_data and update the .bounds give the same initial values, so for some reason its not taking the values set with set_data. |
This is...a huge bug. I don't understand. The BaseVisual class implements the The summary of this is that https://github.com/search?q=repo%3Avispy%2Fvispy%20_bounds_change&type=code @brisvag has napari seen this before? @almarklein @larsoner any historical context you can supply to this? @lfreites adding a Edit: Unless I'm missing something, I can't imagine the number of updating-Visual cases that this breaks. |
No idea :( |
Interesting! I don't have any historical context, it looks like @campagnola wrote the |
Actually as @djhoese commented adding vert_region2._bounds_changed() after set_data() fixed my problem. I ll just be carefull whenever i am updating data to consider if it ll be necesary to manually update the bounds too. Thanks to all for your help! |
I actually encountered this Right now there's just one place in napari where we explicitly use |
From my skimming of code yesterday it seems there are a couple Visuals (maybe it was Markers and/or Meshes) where they manually reset the bounds in their own cache, but this doesn't change the vispy/vispy/visuals/line/line.py Lines 172 to 175 in 2f3da29
This makes |
I am quite new with the library and i am struggling to get some LinearRegion to be updated in real time with mouse drag events. Based on the LinearRegion example:
I d like to be able to select one of the limit lines and drag it around the graph and have the limit of the LinearRegion updated on real time. Is it possible?
So far i connected the mouse events to the callback functions but the problem i have is that when i start a drag event with the mouse the display moves to adjust the camera, but in this case i d like the display to stay still and just get the left or right limit of the linear region geting updated. Thanks a lot in advance!
The text was updated successfully, but these errors were encountered: