Skip to content

Commit

Permalink
Add listener for click event
Browse files Browse the repository at this point in the history
  • Loading branch information
tboch committed Oct 6, 2017
1 parent 52727a6 commit c87d009
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions ipyaladin/aladin_widget.py
Expand Up @@ -62,8 +62,10 @@ class Aladin(widgets.DOMWidget):
# values used in the add_listener function
listener_type = Unicode('').tag(sync=True)
listener_flag = Bool(True).tag(sync=True)
listener_callback_source_click = None
listener_callback_source_hover = None
listener_callback_click = None
listener_callback_hover = None

last_prompt_length = 0

# values used in the get_JPEG_thumbnail function
Expand Down Expand Up @@ -164,9 +166,12 @@ def add_listener(self, listener_type, callback):
callback: python function"""
self.listener_type= listener_type
if listener_type == 'objectHovered':
self.listener_callback_hover= callback
if listener_type == 'objectClicked':
self.listener_callback_source_hover= callback
elif listener_type == 'objectClicked':
self.listener_callback_source_click= callback
elif listener_type == 'click':
self.listener_callback_click= callback

self.listener_flag= not self.listener_flag

# Note: the print() options end='\r'allow us to override the previous prints,
Expand All @@ -175,8 +180,10 @@ def handle_aladin_event(self, _, content, buffers):
""" used to collect json objects that are sent by the js-side of the application by using the send() method """
if content.get('event', '').startswith('callback'):
if content.get('type') == 'objectHovered':
result= self.listener_callback_hover(content.get('data'))
if content.get('type') == 'objectClicked':
result= self.listener_callback_source_hover(content.get('data'))
elif content.get('type') == 'objectClicked':
result= self.listener_callback_source_click(content.get('data'))
elif content.get('type') == 'click':
result= self.listener_callback_click(content.get('data'))
result= str(result)
for i in range(len(result),self.last_prompt_length):
Expand Down

0 comments on commit c87d009

Please sign in to comment.