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
Adding Double Click Callback #231
Conversation
Codecov Report
@@ Coverage Diff @@
## master #231 +/- ##
==========================================
+ Coverage 88.46% 88.49% +0.02%
==========================================
Files 17 17
Lines 4386 4423 +37
Branches 556 569 +13
==========================================
+ Hits 3880 3914 +34
Misses 366 366
- Partials 140 143 +3
|
@skoudoro I need some suggestions here... According to this example they have overridden the OnLeftButtonDown by inheriting from vtkInteractorStyleTrackballCamera class. But the rest of the callbacks are implemented in a different way. So should I inherit both vtkInteractorStyleUser and vtkInteractorStyleTrackballCamera and implement the double click? or should I create a separate class for it? I am also unable to implement my double click callback on an actor hence not being able to test my implementation. I need some help here with that. Thanks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Nibba2018,
So should I inherit both vtkInteractorStyleUser and vtkInteractorStyleTrackballCamera and implement the double click? or should I create a separate class for it?
inherit from vtkInteractorStyleUser so inherit from the current class
I am also unable to implement my double click callback on an actor hence not being able to test my implementation. I need some help here with that.
There are many ways to do it and it is not trivial. In your first test, you should do every in on_left_button_down
. Then, when it works you can create a new custom event and use the invokeevent function. I will try to give you more details later this weekend but you can update this first. Look at all existing vtk event and How to create a custom event.
Hello @Nibba2018! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2020-06-09 22:07:04 UTC |
Here's a test that I am running to test double click implementation where I change the color of the cube when double clicked on it. from fury import actor, window, interactor
import numpy as np
cube = actor.cube(np.random.rand(1, 3), np.random.rand(1,3), (1,1,1), heights=np.random.rand(5))
def change_color(iren, obj):
obj.SetColor(np.random.rand(3))
iren.force_render()
interactor_style = interactor.CustomInteractorStyle()
interactor_style.add_active_prop(cube)
interactor_style.add_callback(cube, "LeftButtonPressEvent", change_color)
current_size = (800, 800)
showm = window.ShowManager(size=current_size, title="Double Click Test")
showm.scene.add(cube)
showm.start() Apparantly I am having an error message being printed which I am not able to understand why. The output: Initial state: (390, 379)
Final state: (390, 379)
Initial state: (390, 379)
Final state: (390, 379)
Double Clicked...
interactor is none
event name is LeftButtonPressEvent
|
nice progress! |
Hello @skoudoro , I tried Traceback (most recent call last):
File "double_click.py", line 13, in <module>
showm.iren.add_callback(cube, "LeftButtonPressEvent", change_color)
AttributeError: 'vtkRenderingOpenGL2Python.vtkXRenderWindowInteract' object has no attribute 'add_callback' |
ok, need to check, maybe it is |
Hello @skoudoro , I am successfully able to detect and differentiate between single clicks & double clicks. But I am unable to understand how to abort or stop the propagation of the previously initiated single click event. Can you give me some idea where I should look for a solution... Thank you. |
Also, is the line |
Hi @Nibba2018, That's good news! To stop the propagation,you need to use
No, it is not because this custom event is never invoked. We need to create a custom event named |
Hello @skoudoro , I did some research and have come up with the following conclusions:
I will try implementing vtkCommand subclasses and see if it works. |
Hi @Nibba2018, Thank you for your research and all this information. You should look at this nice example too.
Does it make sense? |
Thank you @skoudoro , It makes it very clear. I will implement this right away. |
@skoudoro I am using this following for testing: from fury import actor, window, interactor
import numpy as np
cube = actor.cube(np.random.rand(1, 3), np.random.rand(1,3), (1,1,1), heights=np.random.rand(5))
def single_click(iren, obj):
print("Single Click")
iren.force_render()
def double_click(iren, obj):
print("Double Click")
iren.force_render()
current_size = (800, 800)
showm = window.ShowManager(size=current_size, title="Double Click Test")
showm.scene.add(cube)
showm.style.add_callback(cube, "LeftButtonPressEvent", single_click)
showm.style.add_callback(cube, "DoubleClickEvent", double_click)
showm.start() The changes are able to detect and differentiate clicks but is not able to propagate the Double Click Event Callback. |
@skoudoro , I ran the debugger and found that during single clicks, the control moves from |
Interesting, I have no idea at this point, I need to go deeper. Maybe @MarcCote have an idea about the DoubleClik |
I suppose you are missing a
So you need both @Nibba2018 |
@skoudoro , Initially I tried with This time I will try using both. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @Nibba2018, thank you so much for taking a stab at this. Sorry for being late to the party. See my comments in the code to fix your double click issue.
On a side note, the expected behavior of a double click event is:
- Two consecutive clicks on the same object/prop within some time interval.
At the moment, I see that the second click has to be in some radius of the first one. What's the expected behavior when the two clicks are not on the same prop/object but still within the predefined radius?
Regarding the "within a time interval", I guess we can do it in another PR.
Hello @MarcCote , thank you for the review I will apply the changes and will let you know if I have any questions. |
@MarcCote Thank you for the suggestions. The double click callback now triggers normally. Regarding the double click behavior, Yes it only detects double clicks if the second click is within a certain radius of the first click irrespective of the prop. I will add some changes to in order to detect whether the clicks are on the same prop or not. |
Hello @MarcCote , looks like single clicks arent working the way they are supposed to and hence causing tests to fail. Failed tests start from |
Thank you for the rebase @Nibba2018. Any additional comments? I will merge this by the end of the day. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thank you @MarcCote and @Nibba2018 for this nice work. merging |
Referencing #226 , Adding Double Left Click Callback.
I will be adding examples & unittests soon.
Let me know if I am doing it wrong.
Thank You.