def build_gui(self, container): """ This is responsible for building the viewer's UI. It should place the UI in `container`. """ vbox = Widgets.VBox() vbox.set_border_width(2) vbox.set_spacing(1) w = Viewers.GingaViewerWidget(viewer=self) vbox.add_widget(w, stretch=1) # set up to capture cursor movement for reading out coordinates # coordinates reported in base 1 or 0? self.pixel_base = 1.0 self.readout = Widgets.Label("") vbox.add_widget(self.readout, stretch=0) #self.set_callback('none-move', self.motion_cb) self.set_callback('cursor-changed', self.motion_cb) # need to put this in an hbox with an expanding label or the # browser wants to resize the canvas, distorting it hbox = Widgets.HBox() hbox.add_widget(vbox, stretch=0) hbox.add_widget(Widgets.Label(''), stretch=1) container.set_widget(hbox)
def build_gui(self, container): """ This is responsible for building the viewer's UI. It should place the UI in `container`. Override this to make a custom UI. """ vbox = Widgets.VBox() vbox.set_border_width(0) w = Viewers.GingaViewerWidget(viewer=self) vbox.add_widget(w, stretch=1) # need to put this in an hbox with an expanding label or the # browser wants to resize the canvas, distorting it hbox = Widgets.HBox() hbox.add_widget(vbox, stretch=0) hbox.add_widget(Widgets.Label(''), stretch=1) container.set_widget(hbox)
def __init__(self, logger, window, viewer_class=None): if viewer_class is None: viewer_class = EnhancedCanvasView self.logger = logger self.url = window.url self.drawcolors = colors.get_colors() self.dc = get_canvas_types() self.top = window self.top.add_callback('close', self.closed) vbox = Widgets.VBox() vbox.set_border_width(2) vbox.set_spacing(1) fi = viewer_class(logger) fi.url = self.url fi.enable_autocuts('on') fi.set_autocut_params('zscale') fi.enable_autozoom('on') fi.set_zoom_algorithm('rate') fi.set_zoomrate(1.4) fi.show_pan_mark(True) fi.set_callback('drag-drop', self.drop_file) fi.set_callback('none-move', self.motion) fi.set_bg(0.2, 0.2, 0.2) fi.ui_setActive(True) self.fitsimage = fi bd = fi.get_bindings() bd.enable_all(True) # so trackpad scrolling can be adjusted settings = bd.get_settings() settings.set(scroll_zoom_direct_scale=True) # so trackpad scrolling can be adjusted settings = bd.get_settings() settings.set(scroll_zoom_direct_scale=True, scroll_zoom_acceleration=0.07) # canvas that we will draw on canvas = self.dc.DrawingCanvas() #canvas.enable_draw(True) #canvas.enable_edit(True) #canvas.set_drawtype('rectangle', color='lightblue') canvas.setSurface(fi) self.canvas = canvas # add canvas to view private_canvas = fi.get_canvas() private_canvas.add(canvas) canvas.ui_setActive(True) #canvas.register_for_cursor_drawing(fi) fi.set_canvas(canvas) ## self.drawtypes = canvas.get_drawtypes() ## self.drawtypes.sort() # add a color bar private_canvas.add(self.dc.ColorBar(side='bottom', offset=10)) # add little mode indicator that shows modal states in # the corner private_canvas.add(self.dc.ModeIndicator(corner='ur', fontsize=14)) # little hack necessary to get correct operation of the mode indicator # in all circumstances bm = fi.get_bindmap() bm.add_callback('mode-set', lambda *args: fi.redraw(whence=3)) fi.set_desired_size(512, 512) w = Viewers.GingaViewerWidget(viewer=fi) vbox.add_widget(w, stretch=1) self.readout = Widgets.Label("") vbox.add_widget(self.readout, stretch=0) hbox = Widgets.HBox() hbox.add_widget(Widgets.Label('Zoom sensitivity: ')) slider = Widgets.Slider(orientation='horizontal', dtype=float) slider.add_callback('value-changed', lambda w, val: self.adjust_scrolling_accel_cb(val)) slider.set_limits(0.0, 12.0, 0.005) slider.set_value(8.0) hbox.add_widget(slider, stretch=1) hbox.add_widget(Widgets.Label(''), stretch=1) vbox.add_widget(hbox, stretch=0) # need to put this in an hbox with an expanding label or the # browser wants to resize the canvas, distorting it hbox = Widgets.HBox() hbox.add_widget(vbox, stretch=0) hbox.add_widget(Widgets.Label(''), stretch=1) self.top.set_widget(hbox)
def __init__(self, logger, window): self.logger = logger self.drawcolors = colors.get_colors() self.dc = get_canvas_types() self.top = window self.top.add_callback('close', self.closed) vbox = Widgets.VBox() vbox.set_border_width(2) vbox.set_spacing(1) fi = EnhancedCanvasView(logger) fi.enable_autocuts('on') fi.set_autocut_params('zscale') fi.enable_autozoom('on') fi.set_zoom_algorithm('rate') fi.set_zoomrate(1.4) fi.show_pan_mark(True) fi.set_callback('drag-drop', self.drop_file) fi.set_callback('none-move', self.motion) fi.set_bg(0.2, 0.2, 0.2) fi.ui_setActive(True) self.fitsimage = fi bd = fi.get_bindings() bd.enable_all(True) # canvas that we will draw on canvas = self.dc.DrawingCanvas() canvas.enable_draw(True) canvas.enable_edit(True) canvas.set_drawtype('rectangle', color='lightblue') canvas.setSurface(fi) self.canvas = canvas # add canvas to view private_canvas = fi.get_canvas() private_canvas.add(canvas) canvas.ui_setActive(True) canvas.register_for_cursor_drawing(fi) fi.set_canvas(canvas) ## self.drawtypes = canvas.get_drawtypes() ## self.drawtypes.sort() # add a color bar private_canvas.add(self.dc.ColorBar(side='bottom', offset=10)) # add little mode indicator that shows modal states in # the corner private_canvas.add(self.dc.ModeIndicator(corner='ur', fontsize=14)) # little hack necessary to get correct operation of the mode indicator # in all circumstances bm = fi.get_bindmap() bm.add_callback('mode-set', lambda *args: fi.redraw(whence=3)) fi.set_desired_size(512, 512) w = Viewers.GingaViewerWidget(viewer=fi) vbox.add_widget(w, stretch=1) self.readout = Widgets.Label("") vbox.add_widget(self.readout, stretch=0) hbox = Widgets.HBox() btn3 = Widgets.CheckBox("I'm using a trackpad") btn3.add_callback('activated', lambda w, tf: self.use_trackpad_cb(tf)) hbox.add_widget(btn3) hbox.add_widget(Widgets.Label(''), stretch=1) vbox.add_widget(hbox, stretch=0) self.top.set_widget(vbox)
def __init__(self, logger, window): self.logger = logger self.drawcolors = colors.get_colors() self.dc = get_canvas_types() self.top = window self.top.add_callback('close', self.closed) vbox = Widgets.VBox() vbox.set_border_width(2) vbox.set_spacing(1) fi = Viewers.CanvasView(logger) fi.enable_autocuts('on') fi.set_autocut_params('zscale') fi.enable_autozoom('on') fi.set_zoom_algorithm('rate') fi.set_zoomrate(1.4) fi.show_pan_mark(True) fi.set_callback('drag-drop', self.drop_file) fi.set_callback('none-move', self.motion) fi.set_bg(0.2, 0.2, 0.2) fi.ui_setActive(True) self.fitsimage = fi bd = fi.get_bindings() bd.enable_all(True) # so trackpad scrolling can be adjusted settings = bd.get_settings() settings.set(scroll_zoom_direct_scale=True, scroll_zoom_acceleration=0.07) # canvas that we will draw on canvas = self.dc.DrawingCanvas() canvas.enable_draw(True) canvas.enable_edit(True) canvas.set_drawtype('rectangle', color='lightblue') canvas.setSurface(fi) self.canvas = canvas # add canvas to view private_canvas = fi.get_canvas() private_canvas.add(canvas) canvas.ui_setActive(True) canvas.register_for_cursor_drawing(fi) self.drawtypes = canvas.get_drawtypes() self.drawtypes.sort() # add a color bar fi.show_color_bar(True) # add little mode indicator that shows keyboard modal states fi.show_mode_indicator(True, corner='ur') fi.set_desired_size(512, 512) w = Viewers.GingaViewerWidget(viewer=fi) vbox.add_widget(w, stretch=1) self.readout = Widgets.Label("") vbox.add_widget(self.readout, stretch=0) hbox = Widgets.HBox() hbox.set_border_width(2) wdrawtype = Widgets.ComboBox() for name in self.drawtypes: wdrawtype.append_text(name) index = self.drawtypes.index('rectangle') wdrawtype.set_index(index) wdrawtype.add_callback('activated', lambda w, idx: self.set_drawparams()) self.wdrawtype = wdrawtype wdrawcolor = Widgets.ComboBox() for name in self.drawcolors: wdrawcolor.append_text(name) index = self.drawcolors.index('lightblue') wdrawcolor.set_index(index) wdrawcolor.add_callback('activated', lambda w, idx: self.set_drawparams()) self.wdrawcolor = wdrawcolor wfill = Widgets.CheckBox("Fill") wfill.add_callback('activated', lambda w, tf: self.set_drawparams()) self.wfill = wfill walpha = Widgets.SpinBox(dtype=float) walpha.set_limits(0.0, 1.0, incr_value=0.1) walpha.set_value(1.0) walpha.set_decimals(2) walpha.add_callback('value-changed', lambda w, val: self.set_drawparams()) self.walpha = walpha wclear = Widgets.Button("Clear Canvas") wclear.add_callback('activated', lambda w: self.clear_canvas()) ## wopen = Widgets.Button("Open File") ## wopen.add_callback('activated', lambda w: self.open_file()) ## wquit = Widgets.Button("Quit") ## wquit.add_callback('activated', lambda w: self.quit()) hbox.add_widget(Widgets.Label(''), stretch=1) for w in (wdrawtype, wdrawcolor, wfill, Widgets.Label('Alpha:'), walpha, wclear): hbox.add_widget(w, stretch=0) vbox.add_widget(hbox, stretch=0) mode = self.canvas.get_draw_mode() hbox = Widgets.HBox() btn1 = Widgets.RadioButton("Draw") btn1.set_state(mode == 'draw') btn1.add_callback('activated', lambda w, val: self.set_mode_cb('draw', val)) btn1.set_tooltip("Choose this to draw on the canvas") hbox.add_widget(btn1) btn2 = Widgets.RadioButton("Edit", group=btn1) btn2.set_state(mode == 'edit') btn2.add_callback('activated', lambda w, val: self.set_mode_cb('edit', val)) btn2.set_tooltip("Choose this to edit things on the canvas") hbox.add_widget(btn2) hbox.add_widget(Widgets.Label('Zoom sensitivity: ')) slider = Widgets.Slider(orientation='horizontal', dtype=float) slider.add_callback('value-changed', lambda w, val: self.adjust_scrolling_accel_cb(val)) slider.set_limits(0.0, 12.0, 0.005) slider.set_value(8.0) hbox.add_widget(slider, stretch=1) # hbox.add_widget(Widgets.Label(''), stretch=1) vbox.add_widget(hbox, stretch=0) # need to put this in an hbox with an expanding label or the # browser wants to resize the canvas hbox = Widgets.HBox() hbox.add_widget(vbox, stretch=0) hbox.add_widget(Widgets.Label(''), stretch=1) self.top.set_widget(hbox)
def __init__(self, logger, window): self.logger = logger self.drawcolors = colors.get_colors() self.dc = get_canvas_types() self.top = window self.top.add_callback('close', self.closed) vbox = Widgets.VBox() vbox.set_border_width(2) vbox.set_spacing(1) fi = Viewers.CanvasView(logger) fi.enable_autocuts('on') fi.set_autocut_params('zscale') fi.enable_autozoom('on') fi.set_zoom_algorithm('rate') fi.set_zoomrate(1.4) fi.show_pan_mark(True) fi.set_callback('drag-drop', self.drop_file) fi.set_callback('none-move', self.motion) fi.set_bg(0.2, 0.2, 0.2) fi.ui_setActive(True) self.fitsimage = fi bd = fi.get_bindings() bd.enable_all(True) # canvas that we will draw on canvas = self.dc.DrawingCanvas() canvas.enable_draw(True) canvas.enable_edit(True) canvas.set_drawtype('rectangle', color='lightblue') canvas.setSurface(fi) self.canvas = canvas # add canvas to view private_canvas = fi.get_canvas() private_canvas.add(canvas) canvas.ui_setActive(True) canvas.register_for_cursor_drawing(fi) self.drawtypes = canvas.get_drawtypes() self.drawtypes.sort() # add a color bar private_canvas.add(self.dc.ColorBar(side='bottom', offset=10)) # add little mode indicator that shows modal states in # the corner private_canvas.add(self.dc.ModeIndicator(corner='ur', fontsize=14)) # little hack necessary to get correct operation of the mode indicator # in all circumstances bm = fi.get_bindmap() bm.add_callback('mode-set', lambda *args: fi.redraw(whence=3)) fi.set_desired_size(512, 512) w = Viewers.GingaViewerWidget(viewer=fi) vbox.add_widget(w, stretch=1) self.readout = Widgets.Label("") vbox.add_widget(self.readout, stretch=0) hbox = Widgets.HBox() hbox.set_border_width(2) wdrawtype = Widgets.ComboBox() for name in self.drawtypes: wdrawtype.append_text(name) index = self.drawtypes.index('rectangle') wdrawtype.set_index(index) wdrawtype.add_callback('activated', lambda w, idx: self.set_drawparams()) self.wdrawtype = wdrawtype wdrawcolor = Widgets.ComboBox() for name in self.drawcolors: wdrawcolor.append_text(name) index = self.drawcolors.index('lightblue') wdrawcolor.set_index(index) wdrawcolor.add_callback('activated', lambda w, idx: self.set_drawparams()) self.wdrawcolor = wdrawcolor wfill = Widgets.CheckBox("Fill") wfill.add_callback('activated', lambda w, tf: self.set_drawparams()) self.wfill = wfill walpha = Widgets.SpinBox(dtype=float) walpha.set_limits(0.0, 1.0, incr_value=0.1) walpha.set_value(1.0) walpha.set_decimals(2) walpha.add_callback('value-changed', lambda w, val: self.set_drawparams()) self.walpha = walpha wclear = Widgets.Button("Clear Canvas") wclear.add_callback('activated', lambda w: self.clear_canvas()) ## wopen = Widgets.Button("Open File") ## wopen.add_callback('activated', lambda w: self.open_file()) ## wquit = Widgets.Button("Quit") ## wquit.add_callback('activated', lambda w: self.quit()) hbox.add_widget(Widgets.Label(''), stretch=1) for w in (wdrawtype, wdrawcolor, wfill, Widgets.Label('Alpha:'), walpha, wclear): hbox.add_widget(w, stretch=0) vbox.add_widget(hbox, stretch=0) mode = self.canvas.get_draw_mode() hbox = Widgets.HBox() btn1 = Widgets.RadioButton("Draw") btn1.set_state(mode == 'draw') btn1.add_callback('activated', lambda w, val: self.set_mode_cb('draw', val)) btn1.set_tooltip("Choose this to draw on the canvas") hbox.add_widget(btn1) btn2 = Widgets.RadioButton("Edit", group=btn1) btn2.set_state(mode == 'edit') btn2.add_callback('activated', lambda w, val: self.set_mode_cb('edit', val)) btn2.set_tooltip("Choose this to edit things on the canvas") hbox.add_widget(btn2) btn3 = Widgets.CheckBox("I'm using a trackpad") btn3.add_callback('activated', lambda w, tf: self.use_trackpad_cb(tf)) hbox.add_widget(btn3) hbox.add_widget(Widgets.Label(''), stretch=1) vbox.add_widget(hbox, stretch=0) self.top.set_widget(vbox)
def build_gui(self, container): """ Building the GUI to be displayed in an HTML5 canvas. Tested and working in Mozilla Firefox and Google Chrome web browsers. :param container: ginga.web.pgw.Widgets.TopLevel object """ bindings = self.get_bindings() bindings.enable_all(True) # keyboard mode indicator, upper right corner self.show_mode_indicator(True, corner='ur') viewer_vbox = Widgets.VBox() # box containing the viewer viewer_vbox.set_border_width(2) viewer_vbox.set_spacing(1) viewer_widget = Viewers.GingaViewerWidget(viewer=self) viewer_vbox.add_widget(viewer_widget, stretch=1) viewer_vbox.add_widget( self.readout, stretch=0) # text directly below the viewer for coordinate display self.set_callback('cursor-changed', self.motion_cb) healpix_set = Widgets.TextEntrySet() healpix_set.add_callback('activated', lambda x: self.set_healpix(event=x)) healpix_set.set_length(6) candidate_override = Widgets.TextEntrySet() candidate_override.add_callback('activated', lambda x: self.override_set(event=x)) candidate_override.set_length(10) astfile = Widgets.TextEntry(editable=True) astfile.add_callback('activated', lambda x: self.load_astfile(event=x)) catalog = Widgets.TextEntrySet(text='17AQ03') catalog.add_callback('activated', lambda x: self.set_qrun_id(x)) catalog.set_length(5) self.accept.add_callback('activated', lambda x: self.accept_reject()) self.reject.add_callback('activated', lambda x: self.accept_reject(rejected=True)) self.load_json.add_callback('activated', lambda x: self.load_candidates()) self.next_set.add_callback('activated', lambda x: self.next()) self.previous_set.add_callback('activated', lambda x: self.previous()) self.clear_button.add_callback('activated', lambda x: self.clear_viewer()) self.reload_button.add_callback('activated', lambda x: self.reload_candidates()) # accept/reject/next buttons buttons_hbox = Widgets.HBox() buttons_hbox.add_widget(self.previous_set) buttons_hbox.add_widget(self.accept) buttons_hbox.add_widget(self.reject) buttons_hbox.add_widget(self.next_set) buttons_hbox.add_widget(self.load_json) buttons_hbox.add_widget(self.reload_button) buttons_hbox.add_widget(self.clear_button) self.load_json.set_enabled(False) buttons_hbox.set_spacing(3) # catalog directory text box catalog_box = Widgets.HBox() catalog_label = Widgets.Label(text="Set QRUNID:", style='color:red') catalog_box.add_widget(catalog_label) catalog_box.add_widget(catalog) catalog_box.set_margins(15, 0, 10, 0) # top, right, bottom, left candidates_hbox = Widgets.HBox() candidate_label = Widgets.Label( text="(Optional) Enter candidate set (HEALPIX): ") candidates_hbox.add_widget(candidate_label) candidates_hbox.add_widget(healpix_set) candidates_hbox.set_margins(15, 0, 15, 0) # top, right, bottom, left override_hbox = Widgets.HBox() override_label = Widgets.Label( text="(Optional) Override provisional name: ") override_hbox.add_widget(override_label) override_hbox.add_widget(candidate_override) override_hbox.set_margins(0, 0, 15, 0) # top, right, bottom, left astfile_hbox = Widgets.HBox() astfile_hbox_label = Widgets.Label(text="Paste AST file here:") astfile_hbox.add_widget(astfile_hbox_label) astfile_hbox.add_widget(astfile) # button and text entry vbox buttons_vbox = Widgets.VBox() buttons_vbox.add_widget(buttons_hbox) buttons_vbox.add_widget(catalog_box) buttons_vbox.add_widget(candidates_hbox) buttons_vbox.add_widget(override_hbox) buttons_vbox.add_widget(astfile_hbox) viewer_vbox.add_widget(buttons_vbox) # add buttons below the viewer viewer_header_hbox = Widgets.HBox( ) # box containing the viewer/buttons and rightmost text area viewer_header_hbox.add_widget(viewer_vbox) viewer_header_hbox.add_widget(Widgets.Label('')) hbox = Widgets.HBox() hbox.add_widget(self.header_box) hbox.add_widget(self.legend) viewer_header_hbox.add_widget(hbox) full_vbox = Widgets.VBox() # vbox container for all elements full_vbox.add_widget(viewer_header_hbox) full_vbox.add_widget(self.console_box) self.console_box.set_text('Logging output:\n') self.header_box.set_text("Header:") container.set_widget(full_vbox) container.set_widget(self.warning) container.set_widget(self.yes_button) container.set_widget(self.no_button) self.yes_button.set_enabled(False) self.no_button.set_enabled(False) self.buttons_off()
def __init__(self, logger, window, viewer_class=None, width=512, height=512): if viewer_class is None: viewer_class = EnhancedCanvasView self.logger = logger self.url = window.url self.dc = get_canvas_types() self.pixel_base = 1.0 self.top = window self.top.add_callback('close', self.closed) vbox = Widgets.VBox() vbox.set_border_width(2) vbox.set_spacing(1) # load binding preferences if available cfgfile = os.path.join(ginga_home, "ipg_bindings.cfg") bindprefs = SettingGroup(name='bindings', logger=logger, preffile=cfgfile) bindprefs.load(onError='silent') bd = ImageViewBindings(logger, settings=bindprefs) fi = viewer_class(logger, bindings=bd) fi.url = self.url fi.enable_autocuts('on') fi.set_autocut_params('zscale') fi.set_zoom_algorithm('rate') fi.set_zoomrate(1.1) fi.enable_autozoom('on') #fi.set_callback('drag-drop', self.drop_file) fi.set_callback('none-move', self.motion) fi.set_bg(0.2, 0.2, 0.2) fi.ui_setActive(True) self.fitsimage = fi fi.ipg_parent = self bd = fi.get_bindings() bd.enable_all(True) # canvas that we will draw on canvas = self.dc.DrawingCanvas() canvas.set_surface(fi) self.canvas = canvas # add canvas to view private_canvas = fi.get_canvas() private_canvas.add(canvas) canvas.ui_setActive(True) fi.set_canvas(canvas) fi.set_desired_size(width, height) # force allocation of a surface--may be resized later fi.configure_surface(width, height) # add little mode indicator that shows modal states in # the corner fi.show_mode_indicator(True) w = Viewers.GingaViewerWidget(viewer=fi) vbox.add_widget(w, stretch=1) self.readout = Widgets.Label("") vbox.add_widget(self.readout, stretch=0) hbox = Widgets.HBox() hbox.add_widget(Widgets.Label('Zoom sensitivity: ')) slider = Widgets.Slider(orientation='horizontal', dtype=float) slider.add_callback('value-changed', lambda w, val: self.adjust_scrolling_accel_cb(val)) slider.set_limits(1.0, 9.5, 0.1) val = 4.0 slider.set_value(val) self.adjust_scrolling_accel_cb(val) hbox.add_widget(slider, stretch=1) hbox.add_widget(Widgets.Label(''), stretch=1) vbox.add_widget(hbox, stretch=0) # need to put this in an hbox with an expanding label or the # browser wants to resize the canvas, distorting it hbox = Widgets.HBox() hbox.add_widget(vbox, stretch=0) hbox.add_widget(Widgets.Label(''), stretch=1) self.top.set_widget(hbox)