def __init__(self, logger): self.logger = logger self.drawcolors = colors.get_colors() self.dc = get_canvas_types() from ginga.gw import Widgets, Viewers, GwHelp self.app = Widgets.Application(logger=logger) self.app.add_callback('shutdown', self.quit) self.top = self.app.make_window("Ginga example2") self.top.add_callback('close', self.closed) vbox = Widgets.VBox() vbox.set_border_width(2) vbox.set_spacing(1) fi = Viewers.CanvasView(logger=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) # add a color bar fi.private_canvas.add(self.dc.ColorBar(side='bottom', offset=10)) # add little mode indicator that shows modal states in # lower left hand corner fi.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)) # 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 fi.get_canvas().add(canvas) canvas.ui_setActive(True) canvas.register_for_cursor_drawing(fi) self.drawtypes = canvas.get_drawtypes() self.drawtypes.sort() fi.set_desired_size(512, 512) iw = Viewers.GingaViewerWidget(viewer=fi) vbox.add_widget(iw, 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 (wopen, wdrawtype, wdrawcolor, wfill, Widgets.Label('Alpha:'), walpha, wclear, wquit): 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) self.fs = None if hasattr(GwHelp, 'FileSelection'): self.fs = GwHelp.FileSelection(self.top.get_widget())
def build_gui(self, container, future=None): vbox1 = Widgets.VBox() msg_font = self.fv.get_font("sansFont", 14) tw = Widgets.TextArea() tw.set_font(msg_font) tw.set_wrap(True) self.tw = tw fr = Widgets.Expander("Instructions") fr.set_widget(tw) vbox1.add_widget(fr, stretch=0) nb = Widgets.TabWidget(tabpos='bottom') self.w.nb = nb vbox1.add_widget(nb, stretch=1) vbox0 = Widgets.VBox() hbox = Widgets.HBox() hbox.set_spacing(4) vbox0.add_widget(hbox, stretch=1) vbox = Widgets.VBox() fr = Widgets.Frame(" Image Server ") fr.set_widget(vbox) hbox.add_widget(fr, stretch=0) captions = (('Server:', 'llabel'), ('Server', 'combobox'), ('Use DSS channel', 'checkbutton'), ('Get Image', 'button')) w, b = Widgets.build_info(captions) self.w.update(b) self.w.get_image.add_callback('activated', lambda w: self.getimage_cb()) self.w.use_dss_channel.set_state(self.use_dss_channel) self.w.use_dss_channel.add_callback('activated', self.use_dss_channel_cb) vbox.add_widget(w, stretch=0) self.w.img_params = Widgets.StackWidget() vbox.add_widget(self.w.img_params, stretch=1) combobox = self.w.server index = 0 self.image_server_options = self.fv.imgsrv.getServerNames(kind='image') for name in self.image_server_options: combobox.append_text(name) index += 1 index = 0 combobox.set_index(index) combobox.add_callback('activated', lambda w, idx: self.setup_params_image(idx)) if len(self.image_server_options) > 0: self.setup_params_image(index, redo=False) vbox = Widgets.VBox() fr = Widgets.Frame(" Catalog Server ") fr.set_widget(vbox) hbox.add_widget(fr, stretch=0) captions = (('Server:', 'llabel'), ('Server', 'combobox'), ('Limit stars to area', 'checkbutton'), ('Search', 'button')) w, self.w2 = Widgets.build_info(captions) self.w2.search.add_callback('activated', lambda w: self.getcatalog_cb()) self.w2.limit_stars_to_area.set_state(self.limit_stars_to_area) self.w2.limit_stars_to_area.add_callback('activated', self.limit_area_cb) vbox.add_widget(w, stretch=0) self.w2.cat_params = Widgets.StackWidget() vbox.add_widget(self.w2.cat_params, stretch=1) combobox = self.w2.server index = 0 self.catalog_server_options = self.fv.imgsrv.getServerNames( kind='catalog') for name in self.catalog_server_options: combobox.append_text(name) index += 1 index = 0 combobox.set_index(index) combobox.add_callback('activated', lambda w, idx: self.setup_params_catalog(idx)) if len(self.catalog_server_options) > 0: self.setup_params_catalog(index, redo=False) # stretch vbox0.add_widget(Widgets.Label(''), stretch=1) btns = Widgets.HBox() btns.set_spacing(5) btn1 = Widgets.RadioButton("Rectangle") btn1.set_state(self.drawtype == 'rectangle') btn1.add_callback('activated', lambda w, tf: self.set_drawtype_cb(tf, 'rectangle')) btns.add_widget(btn1, stretch=0) btn2 = Widgets.RadioButton("Circle", group=btn1) btn2.set_state(self.drawtype == 'circle') btn2.add_callback('activated', lambda w, tf: self.set_drawtype_cb(tf, 'circle')) btns.add_widget(btn2, stretch=0) btn = Widgets.Button("Entire image") btn.add_callback('activated', lambda w: self.setfromimage()) btns.add_widget(btn, stretch=0) vbox0.add_widget(btns, stretch=0) self.w.params = vbox0 sw = Widgets.ScrollArea() sw.set_widget(vbox0) nb.add_widget(sw, title="Params") vbox = Widgets.VBox() self.table = CatalogListing(self.logger, vbox) hbox = Widgets.HBox() adj = Widgets.Slider(orientation='horizontal') adj.set_limits(0, 1000, incr_value=1) adj.set_value(0) #adj.resize(200, -1) adj.set_tracking(True) adj.set_tooltip("Choose subset of stars plotted") self.w.plotgrp = adj adj.add_callback('value-changed', self.plot_pct_cb) hbox.add_widget(adj, stretch=1) sb = Widgets.SpinBox(dtype=int) sb.set_limits(10, self.plot_max, incr_value=10) sb.set_value(self.plot_limit) #sb.set_wrapping(False) self.w.plotnum = sb sb.set_tooltip("Adjust size of subset of stars plotted") sb.add_callback('value-changed', self.plot_limit_cb) hbox.add_widget(sb, stretch=0) vbox.add_widget(hbox, stretch=0) self.w.listing = vbox nb.add_widget(vbox, title="Listing") btns = Widgets.HBox() btns.set_spacing(3) self.w.buttons = btns btn = Widgets.Button("Close") btn.add_callback('activated', lambda w: self.close()) btns.add_widget(btn, stretch=0) if future: btn = Widgets.Button('Ok') btn.add_callback('activated', lambda w: self.ok()) btns.add_widget(btn, stretch=0) btn = Widgets.Button('Cancel') btn.add_callback('activated', lambda w: self.cancel()) btns.add_widget(btn, stretch=0) vbox1.add_widget(btns, stretch=0) container.add_widget(vbox1, stretch=1) self.gui_up = True
def __init__(self, logger): self.logger = logger self.drawcolors = colors.get_colors() self.dc = get_canvas_types() from ginga.gw import Widgets, Viewers self.app = Widgets.Application(logger=logger) #self.app.add_callback('shutdown', self.quit) self.top = self.app.make_window("Ginga example2") self.top.add_callback('close', self.closed) vbox = Widgets.VBox() vbox.set_border_width(2) vbox.set_spacing(1) hbox = Widgets.HBox() hbox.set_border_width(2) hbox.set_spacing(4) v1 = Viewers.CanvasView(logger) v1.enable_autocuts('on') v1.set_autocut_params('zscale') v1.enable_autozoom('on') v1.set_zoom_algorithm('rate') v1.set_zoomrate(1.4) v1.show_pan_mark(True) v1.set_callback('drag-drop', self.drop_file) v1.set_callback('none-move', self.motion) v1.set_bg(0.2, 0.2, 0.2) v1.ui_setActive(True) v1.set_name('tweedledee') self.viewer1 = v1 self._mi1 = ModeIndicator(v1) bd = v1.get_bindings() bd.enable_all(True) # shared canvas between the two viewers canvas = self.dc.DrawingCanvas() canvas.enable_draw(True) canvas.enable_edit(True) canvas.set_drawtype('rectangle', color='lightblue') self.canvas = canvas # Tell viewer1 to use this canvas v1.set_canvas(canvas) self.drawtypes = canvas.get_drawtypes() self.drawtypes.sort() v1.set_desired_size(300, 300) iw = Viewers.GingaViewerWidget(viewer=v1) hbox.add_widget(iw, stretch=1) # Add a second viewer viewing the same canvas v2 = Viewers.CanvasView(logger) v2.enable_autocuts('on') v2.set_autocut_params('zscale') v2.enable_autozoom('on') v2.set_zoom_algorithm('rate') v2.set_zoomrate(1.4) v2.show_pan_mark(True) v2.set_callback('drag-drop', self.drop_file) v2.set_callback('none-move', self.motion) v2.set_bg(0.2, 0.2, 0.2) v2.ui_setActive(True) v1.set_name('tweedledum') self.viewer2 = v2 self._mi2 = ModeIndicator(v2) # Tell viewer2 to use this same canvas v2.set_canvas(canvas) bd = v2.get_bindings() bd.enable_all(True) v2.set_desired_size(300, 300) iw = Viewers.GingaViewerWidget(viewer=v2) hbox.add_widget(iw, stretch=1) vbox.add_widget(hbox, 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 (wopen, wdrawtype, wdrawcolor, wfill, Widgets.Label('Alpha:'), walpha, wclear, wquit): hbox.add_widget(w, stretch=0) vbox.add_widget(hbox, stretch=0) self.top.set_widget(vbox)
def __init__(self, logger, settings, options): self.logger = logger self.options = options self.settings = settings colors = [ 'lightgreen', 'orange', 'cyan', 'pink', 'slateblue', 'yellow', 'maroon', 'brown' ] self.color_index = 0 cols = 3 if options.num_cols is not None: cols = options.num_cols self.settings.add_defaults(columns=cols, zones=['UTC'], colors=colors) self.colors = self.settings.get('colors', colors) # now import our items from ginga.gw import Widgets, GwHelp self.app = Widgets.Application(logger=logger) self.app.add_callback('shutdown', self.quit) self.top = self.app.make_window("Clocks") self.top.add_callback('close', self.closed) menubar = Widgets.Menubar() clockmenu = menubar.add_name('Clock') item = clockmenu.add_name("Quit") item.add_callback('activated', lambda *args: self.quit()) self.top.set_widget(menubar) vbox = Widgets.VBox() self.grid = Widgets.GridBox() self.grid.set_border_width(1) self.grid.set_spacing(2) vbox.add_widget(self.grid, stretch=1) self.top.set_widget(vbox) hbox = Widgets.HBox() self.timezone_label = Widgets.Label('TimeZone') self.county_timezone = Widgets.ComboBox() self.county_timezone.widget.setEditable(True) # make a giant list of time zones zones = [ timezone for timezones in pytz.country_timezones.values() for timezone in timezones ] zones.sort() for timezone in zones: self.county_timezone.append_text(timezone) # also let user set timezone by UTC offset self.location_label = Widgets.Label('Location') self.location = Widgets.TextEntry() self.location.set_tooltip("Type a label to denote this UTC offset") #self.location.set_length(10) self.timeoffset_label = Widgets.Label('UTC Offset(hour)') self.time_offset = Widgets.SpinBox(dtype=float) self.time_offset.set_decimals(2) self.time_offset.set_limits(-12, 12) self.time_offset.set_tooltip("Time offset from UTC") self.timezone_button = Widgets.Button('Add by Timezone') self.offset_button = Widgets.Button('Add by Offset') self.timezone_button.widget.clicked.connect( self.more_clock_by_timezone) self.offset_button.widget.clicked.connect(self.more_clock_by_offset) hbox.add_widget(self.timezone_label, stretch=0) hbox.add_widget(self.county_timezone, stretch=0) hbox.add_widget(self.timezone_button, stretch=0) hbox.add_widget(Widgets.Label(''), stretch=1) hbox.add_widget(self.location_label, stretch=0) hbox.add_widget(self.location, stretch=0) hbox.add_widget(self.timeoffset_label, stretch=0) hbox.add_widget(self.time_offset, stretch=0) hbox.add_widget(self.offset_button, stretch=0) hbox.add_widget(Widgets.Label(''), stretch=1) self.top.set_widget(hbox) self.clocks = {} self.timer = GwHelp.Timer(1.0) self.timer.add_callback('expired', self.timer_cb) self.timer.start(1.0)
vbox.add_widget(w, stretch=1) elif wname == 'radiobutton': w = Widgets.RadioButton("Option 1") vbox.add_widget(w) vbox.add_widget(Widgets.RadioButton("Option 2", group=w)) vbox.add_widget(Widgets.RadioButton("Option 3", group=w)) elif wname == 'combobox': w = Widgets.ComboBox() for name in ["Larry", "Curly", "Moe"]: w.append_text(name) vbox.add_widget(w) elif wname == 'spinbox': w = Widgets.SpinBox(dtype=int) w.set_limits(-10, 10, incr_value=1) w.set_value(4) vbox.add_widget(w) elif wname == 'slider': w = Widgets.Slider(orientation='horizontal') w.set_limits(-10, 10, incr_value=1) w.set_value(4) vbox.add_widget(w) elif wname == 'scrollbar': w = Widgets.ScrollBar(orientation='horizontal') w.add_callback('activated', lambda w, val: logger.info("value is %d" % val)) vbox.add_widget(w)