Beispiel #1
0
    def __init__(self, logger=None, app=None):
        if app is not None and logger is None:
            logger = app.logger
        if logger is None:
            logger = log.NullLogger()
        self.logger = logger

        if app is None:
            app = Widgets.Application(logger=self.logger)
        self.app = app
        self.dc = get_canvas_types()

        self.count = 0
Beispiel #2
0
def main(options, args):

    hostname = args[0]

    logdir = os.path.join(paths.home, '.ana_logs')
    if not os.path.isdir(logdir):
        os.mkdir(logdir)
    if not options.logstderr:
        options.logfile = os.path.join(logdir,
                                       'anamenu_{}.log'.format(hostname))
    logger = ssdlog.make_logger(hostname, options)

    rohost = options.rohost

    def SigHandler(signum, frame):
        """Signal handler for all unexpected conditions."""
        logger.debug('signal handling.  %s' % str(signum))
        #update_menu_num(menu_file, num_menu-1, logger=logger)
        #ana.quit('quit')

    # Set signal handler for signals.  Add any other signals you want to
    # handle or terminate here.
    for sig in [signal.SIGINT, signal.SIGTERM, signal.SIGHUP]:
        signal.signal(sig, SigHandler)

    app = Widgets.Application(logger=logger)
    root = app.make_window(title='ANA Menu')

    try:
        ana = AnaMenu(root, logger, rohost, hostname)
        ana.setup_ui()
        root.show()
        ana.set_geometry(options.geometry)

        app.mainloop()

    except KeyboardInterrupt as e:
        print('interrupted by keyboard....')
        logger.debug('Keyboard Interrupt...')
        ana.quit('quit')
        app.quit()

    except Exception as e:
        logger.error('error: starting anamenu. %s' % e)
        #sys.exit(1)
        raise
Beispiel #3
0
    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())
Beispiel #4
0
    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)
Beispiel #5
0
    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)
Beispiel #6
0
    def __init__(self, logger, ev_quit, options):
        super(GingaVision, self).__init__()
        self.logger = logger
        self.ev_quit = ev_quit

        from ginga.gw import Widgets, Viewers, GwHelp, GwMain

        self.card = 'default'
        # playback rate; changed when we know the actual rate
        self.fps = 30
        self.playback_rate = 1.0 / self.fps

        # Use an AstroImage, not RGBImage for now because we get a
        # different default (faster) scaling algorithm
        self.pimage = AstroImage.AstroImage()
        self.pdata = None

        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', lambda *args: self.quit())

        thread_pool = Task.ThreadPool(2, logger, ev_quit=ev_quit)
        thread_pool.startall()
        self.main = GwMain.GwMain(logger=logger,
                                  ev_quit=ev_quit,
                                  app=self.app,
                                  thread_pool=thread_pool)

        vbox = Widgets.VBox()
        vbox.set_border_width(2)
        vbox.set_spacing(1)

        fi = Viewers.CanvasView(logger=logger)
        fi.enable_autocuts('off')
        fi.set_autocut_params('histogram')
        fi.enable_autozoom('off')
        fi.cut_levels(0, 255)
        fi.defer_redraw = False
        fi.set_bg(0.2, 0.2, 0.2)
        # flip y
        fi.transform(False, False, False)
        fi.ui_setActive(True)
        self.fitsimage = fi

        # Some optomizations to smooth playback at decent FPS
        fi.set_redraw_lag(self.playback_rate)
        #fi.set_redraw_lag(0.0)
        fi._invertY = False
        # PassThruRGBMapper doesn't color map data--data is already colored
        rgbmap = RGBMap.PassThruRGBMapper(self.logger)
        fi.set_rgbmap(rgbmap)
        # Clip cuts assumes data does not need to be scaled in cut levels--
        # only clipped
        fi.set_autocuts(AutoCuts.Clip(logger=self.logger))

        bd = fi.get_bindings()
        bd.enable_pan(True)
        bd.enable_zoom(True)
        bd.enable_cuts(True)
        bd.enable_flip(True)
        bd.enable_cmap(True)

        fi.set_desired_size(512, 512)
        iw = Viewers.GingaViewerWidget(viewer=fi)
        vbox.add_widget(iw, stretch=1)

        hbox = Widgets.HBox()
        hbox.set_margins(4, 2, 4, 2)

        wopen = Widgets.Button("Open File")
        #wopen.clicked.connect(self.open_file)
        wquit = Widgets.Button("Quit")
        wquit.add_callback('activated', lambda *args: self.quit())

        for w in (wopen, wquit):
            hbox.add_widget(w, stretch=0)
        hbox.add_widget(Widgets.Label(''), stretch=1)

        vbox.add_widget(hbox, stretch=0)

        self.top.set_widget(vbox)
        self.top.set_title("Video Example Viewer")
Beispiel #7
0
    return viewer.dc.CompoundObject(*objs)

def plot_sphere(viewer, r):
    # sphere
    u = np.linspace(0, np.pi, 30)
    v = np.linspace(0, 2 * np.pi, 30)
    x = np.outer(np.sin (u), np.sin (v)) * r
    y = np.outer(np.sin (u), np.cos (v)) * r
    z = np.outer(np.cos (u), np.ones_like (v)) * r

    wf = get_wireframe(viewer, x, y, z, color='cyan', alpha=0.3)
    viewer.canvas.add(wf)

logger = log.get_logger('example', level=20, log_stderr=True)

app = Widgets.Application(logger)

v = Viewer(app)
v.top.resize(512, 512)
v.top.show()

# put viewer in camera mode
bm = v.vw.get_bindmap()
bm.set_mode('camera', mode_type='locked')

# toggle 3D view
bd = v.vw.get_bindings()
bd.kp_camera_toggle3d(v.vw, None, 0, 0)

r = 100
plot_octahedron(v, r)
Beispiel #8
0
    def __init__(self, logger, ev_quit, options):
        super(GingaVision, self).__init__()
        self.logger = logger
        self.ev_quit = ev_quit

        from ginga.gw import Widgets, Viewers, GwMain

        self.card = 'default'
        # playback rate; changed when we know the actual rate
        self.fps = options.fps
        self.playback_rate = 1.0 / 30.0

        self.pimage = RGBImage.RGBImage()
        self.pdata = None

        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', lambda *args: self.quit())

        thread_pool = Task.ThreadPool(2, logger, ev_quit=ev_quit)
        thread_pool.startall()
        self.main = GwMain.GwMain(logger=logger, ev_quit=ev_quit,
                                  app=self.app, thread_pool=thread_pool)

        vbox = Widgets.VBox()
        vbox.set_border_width(2)
        vbox.set_spacing(1)

        fi = Viewers.CanvasView(logger=logger)
        fi.set_autocut_params('histogram')
        fi.enable_autozoom('off')
        fi.enable_autocenter('once')
        fi.enable_autocuts('off')
        fi.cut_levels(0, 255)
        fi.scale_to(1, 1)
        fi.set_bg(0.2, 0.2, 0.2)
        fi.ui_set_active(True)
        self.viewer = fi

        if options.optimize:
            # Some optimizations to smooth playback at decent FPS
            # PassThruRGBMapper is the most efficient mapper
            rgbmap = RGBMap.PassThruRGBMapper(self.logger)
            fi.set_rgbmap(rgbmap)

            # Clip cuts assumes data does not need to be scaled in cut levels--
            # only clipped
            fi.set_autocuts(AutoCuts.Clip(logger=self.logger))

        bd = fi.get_bindings()
        bd.enable_all(True)

        fi.set_desired_size(512, 512)
        iw = Viewers.GingaViewerWidget(viewer=fi)
        vbox.add_widget(iw, stretch=1)

        hbox = Widgets.HBox()
        hbox.set_margins(4, 2, 4, 2)

        wopen = Widgets.Button("Open File")
        #wopen.clicked.connect(self.open_file)
        wquit = Widgets.Button("Quit")
        wquit.add_callback('activated', lambda *args: self.quit())

        for w in (wopen, wquit):
            hbox.add_widget(w, stretch=0)
        hbox.add_widget(Widgets.Label(''), stretch=1)

        vbox.add_widget(hbox, stretch=0)

        self.top.set_widget(vbox)
        self.top.set_title("Video Example Viewer")
Beispiel #9
0
    import sys
    from qplan import entity, common
    from qplan.util.site import get_site

    from ginga import toolkit
    toolkit.use('qt')

    from ginga.gw import Widgets, Plot
    plot = AirMassPlot2(1200, 740)

    outfile = None
    if len(sys.argv) > 1:
        outfile = sys.argv[1]

    if outfile == None:
        app = Widgets.Application()
        topw = app.make_window()
        plotw = Plot.PlotWidget(plot)
        topw.set_widget(plotw)
        topw.add_callback('close', lambda w: w.delete())
    else:
        from ginga.aggw import Plot
        plotw = Plot.PlotWidget(plot)

    plot.setup()
    site = get_site('subaru')
    tz = site.tz_local

    start_time = datetime.strptime("2015-03-30 18:30:00", "%Y-%m-%d %H:%M:%S")
    start_time = tz.localize(start_time)
    t = start_time