1# Extensions and Callback via Terminal
2from firefly_client import FireflyClient
3import firefly_client
4
5local_host = 'http://127.0.0.1:8080/firefly'
6fd = 'https://fireflydev.ipac.caltech.edu/firefly'
7irsa_host = 'https://irsa.ipac.caltech.edu/irsaviewer'
8data_lsst_host = 'https://data.lsst.cloud/portal/app/'
9host = local_host
10
11v_str = firefly_client.__dict__['__version__'] if '__version__' in firefly_client.__dict__ else 'development'
12print('Version: %s' % v_str)
13# FireflyClient._debug = True # enable for debug logging
14token = None
15fc = FireflyClient.make_client(host, launch_browser=True, token=token)
16print(fc.get_firefly_url())
17fc.show_fits(url="http://web.ipac.caltech.edu.s3-us-west-2.amazonaws.com/staff/roby/demo/wise-00.fits")
18
19
20def example_listener(ev):
21 if False:
22 print(ev)
23 if 'data' not in ev:
24 print('no data found in ev')
25 return
26 data = ev['data']
27 if 'payload' in data:
28 print(data['payload'])
29 if 'type' in data:
30 print(data['type'])
31 if data['type'] == 'POINT':
32 print(' plotId: ' + data['plotId'])
33 print(' image point: %s' % data['ipt'])
34 print(' world point: %s' % data['wpt'])
35 if data['type'] == 'LINE_SELECT' or data['type'] == 'AREA_SELECT':
36 print(' plotId: ' + data['plotId'])
37 print(' image points: %s to %s' % (data['ipt0'], data['ipt1']))
38 print(' world points: %s to %s' % (data['wpt0'], data['wpt1']))
39
40
41fc.add_extension(ext_type='POINT', title='Output Selected Point', shortcut_key='ctrl-p')
42fc.add_extension(ext_type='LINE_SELECT', title='Output Selected line', shortcut_key='meta-b')
43fc.add_extension(ext_type='AREA_SELECT', title='Output Selected Area', shortcut_key='a')
44# ------------ add listener and wait
45fc.add_listener(example_listener)
46print('listener is added')
47# time.sleep(3)
48# fc.remove_listener(example_listener)
49# time.sleep(2)
50# fc.add_listener(example_listener)
51fc.wait_for_events() # needed to keep the process alive to show callback output in terminal