/
example2.py
81 lines (56 loc) · 2.18 KB
/
example2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import sys
import os
from bokeh.plotting import figure, curdoc, vplot
from bokeh.models.widgets import TextInput
#from bokeh.io import vform
from ginga.web.bokehw import ImageViewBokeh as ib
from ginga.misc import log
from ginga.util.loader import load_data
def main(options, args):
logger = log.get_logger("ginga", options=options)
# create a new plot with default tools, using figure
fig = figure(x_range=[0, 600], y_range=[0, 600],
plot_width=600, plot_height=600, toolbar_location=None)
viewer = ib.CanvasView(logger)
viewer.set_figure(fig)
def load_file(path):
image = load_data(path, logger=logger)
viewer.set_image(image)
def load_file_cb(attr_name, old_val, new_val):
#print(attr_name, old_val, new_val)
load_file(new_val)
# add a entry widget and configure with the call back
dstdir = options.indir
path_w = TextInput(value=dstdir, title="File:")
path_w.on_change('value', load_file_cb)
if len(args) > 0:
load_file(args[0])
# put the path widget and viewer in a layout and add to the document
curdoc().add_root(vplot(fig, path_w))
if __name__ == "__main__":
# Parse command line options
from argparse import ArgumentParser
argprs = ArgumentParser()
argprs.add_argument("--debug", dest="debug", default=False,
action="store_true",
help="Enter the pdb debugger on main()")
argprs.add_argument("-d", "--indir", dest="indir", metavar="DIR",
default=os.environ['HOME'],
help="Look in DIR for files")
argprs.add_argument("--profile", dest="profile", action="store_true",
default=False,
help="Run the profiler on main()")
log.addlogopts(argprs)
(options, args) = argprs.parse_known_args(sys.argv[1:])
# Are we debugging this?
if options.debug:
import pdb
pdb.run('main(options, args)')
# Are we profiling this?
elif options.profile:
import profile
print(("%s profile:" % sys.argv[0]))
profile.run('main(options, args)')
else:
main(options, args)
# END