Example #1
0
    def build_gui(self, container):

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

        vbox1 = Widgets.VBox()

        # Uncomment to debug; passing parent logger generates too
        # much noise in the main logger
        #zi = Viewers.CanvasView(logger=self.logger)
        zi = Viewers.CanvasView(logger=None)
        zi.set_desired_size(self._wd, self._ht)
        zi.enable_autozoom('once')
        zi.enable_autocuts('once')
        zi.enable_autocenter('override')
        zi.set_zoom_algorithm('step')
        zi.cut_levels(0, 255)
        zi.transform(False, True, False)
        #zi.set_scale_limits(0.001, 1000.0)
        zi.set_bg(0.4, 0.4, 0.4)
        zi.set_color_map('gray')
        zi.set_intensity_map('ramp')
        # for debugging
        zi.set_name('scrnimage')
        self.scrnimage = zi

        bd = zi.get_bindings()
        bd.enable_zoom(True)
        bd.enable_pan(True)
        bd.enable_cmap(False)
        zi.show_mode_indicator(True)

        iw = Viewers.ScrolledView(zi)
        iw.resize(self._wd, self._ht)
        vbox1.add_widget(iw, stretch=1)

        captions = (('Screen size', 'checkbutton', 'Width:', 'label', 'width',
                     'entry', 'Height:', 'label', 'height', 'entry'),
                    ('Lock aspect', 'checkbutton', 'Aspect:', 'label',
                     'aspect', 'entry'))
        w, b = Widgets.build_info(captions, orientation='vertical')
        self.w = b

        if self._sg_wd is None:
            wd, ht = self.fitsimage.get_window_size()
            self.shot_generator.configure_surface(wd, ht)
        else:
            wd, ht = self._sg_wd, self._sg_ht

        b.screen_size.set_state(self._screen_size)
        b.screen_size.set_tooltip("From screen viewer actual size")
        b.screen_size.add_callback('activated', self._screen_size_cb)
        b.lock_aspect.set_state(self._lock_aspect)
        b.lock_aspect.set_tooltip("Lock aspect ratio of screen shot")
        b.lock_aspect.add_callback('activated', self._lock_aspect_cb)
        b.width.set_text(str(wd))
        b.height.set_text(str(ht))
        b.width.set_enabled(not self._screen_size)
        b.height.set_enabled(not self._screen_size)
        if self._sg_aspect is None:
            _as = self.calc_aspect_str(wd, ht)
            b.aspect.set_text(_as)
        else:
            b.aspect.set_text(str(self._sg_aspect))
        b.aspect.set_enabled(self._lock_aspect)
        b.lock_aspect.set_enabled(not self._screen_size)

        b.width.add_callback('activated', lambda *args: self._set_width_cb())
        b.height.add_callback('activated', lambda *args: self._set_height_cb())
        b.aspect.add_callback('activated', lambda *args: self._set_aspect_cb())

        vbox1.add_widget(w, stretch=0)

        captions = (('Type:', 'label', 'grtype', 'combobox', 'Snap', 'button'),
                    ('Clear', 'button', 'Center', 'button', 'Fit', 'button',
                     'Full', 'button'))
        w, b = Widgets.build_info(captions, orientation='vertical')
        self.w.update(b)

        combobox = b.grtype
        for name in self.savetypes:
            combobox.append_text(name)
        index = self.savetypes.index(self.tosave_type)
        combobox.set_index(index)
        combobox.add_callback('activated', lambda w, idx: self.set_type(idx))
        combobox.set_tooltip("Set the format of the snap image")

        b.snap.set_tooltip(
            "Click to grab a snapshot of this channel viewer image")
        b.snap.add_callback('activated', self._snap_cb)
        b.clear.set_tooltip("Clear the snap image")
        b.clear.add_callback('activated', self._clear_cb)
        b.center.set_tooltip("Center the snap image")
        b.center.add_callback('activated', self._center_cb)
        b.fit.set_tooltip("Fit snap image to window")
        b.fit.add_callback('activated', self._fit_cb)
        b.full.set_tooltip("View at 100% (1:1)")
        b.full.add_callback('activated', self._full_cb)

        vbox1.add_widget(w, stretch=0)

        fr = Widgets.Frame("Screenshot")
        fr.set_widget(vbox1)

        vpaned = Widgets.Splitter(orientation='vertical')
        self.w.splitter = vpaned
        vpaned.add_widget(fr)
        vpaned.add_widget(Widgets.Label(''))
        vpaned.set_sizes(self._split_sizes)

        vbox2 = Widgets.VBox()

        fr = Widgets.Frame("Save File")

        captions = (
            ('Folder:', 'label', 'folder', 'entry'),
            ('Name:', 'label', 'name', 'entry'),
            ('Save', 'button'),
        )
        w, b = Widgets.build_info(captions, orientation='vertical')
        self.w.update(b)

        b.folder.set_text(self.save_path)
        b.folder.set_tooltip("Set the folder path for the snap image")
        b.name.set_text(self.save_name)
        b.name.set_tooltip("Set the name for the snap image")
        b.save.set_tooltip("Click to save the last snap")
        b.save.add_callback('activated', self._save_cb)

        fr.set_widget(w)
        vbox2.add_widget(fr, stretch=0)

        # stretch
        spacer = Widgets.Label('')
        vbox2.add_widget(spacer, stretch=1)

        btns = Widgets.HBox()
        btns.set_spacing(3)

        btn = Widgets.Button("Close")
        btn.add_callback('activated', lambda w: self.close())
        btns.add_widget(btn, stretch=0)
        btn = Widgets.Button("Help")
        btn.add_callback('activated', lambda w: self.help())
        btns.add_widget(btn, stretch=0)
        btns.add_widget(Widgets.Label(''), stretch=1)

        vbox2.add_widget(btns, stretch=0)

        #vpaned.add_widget(vbox2)

        vbox.add_widget(vpaned, stretch=1)

        container.add_widget(vbox, stretch=1)
        container.add_widget(vbox2, stretch=0)
        self.gui_up = True
Example #2
0
    def build_gui(self, container):
        top = Widgets.VBox()
        top.set_border_width(4)

        vbox, sw, orientation = Widgets.get_oriented_box(container, fill=True)
        vbox.set_border_width(4)
        vbox.set_spacing(2)

        self.msg_font = self.fv.get_font("sansFont", 12)
        tw = Widgets.TextArea(wrap=True, editable=False)
        tw.set_font(self.msg_font)
        self.tw = tw

        fr = Widgets.Expander("Instructions")
        fr.set_widget(tw)
        vbox.add_widget(fr, stretch=0)

        fr = Widgets.Frame("Pixel Values")

        # We just use a ginga widget to implement the pixtable
        pixview = Viewers.CanvasView(logger=self.logger)
        width, height = 300, 300
        pixview.set_desired_size(width, height)
        bg = colors.lookup_color('#202030')
        pixview.set_bg(*bg)

        bd = pixview.get_bindings()

        self.pixview = pixview
        self.pix_w = Viewers.ScrolledView(pixview)
        self.pix_w.resize(width, height)
        fr.set_widget(self.pix_w)
        vbox.add_widget(fr, stretch=1)

        self._rebuild_table()

        btns = Widgets.HBox()
        btns.set_border_width(4)
        btns.set_spacing(4)

        cbox1 = Widgets.ComboBox()
        index = 0
        for i in self.sizes:
            j = 1 + i * 2
            name = "%dx%d" % (j, j)
            cbox1.append_text(name)
            index += 1
        index = self.sizes.index(self.pixtbl_radius)
        cbox1.set_index(index)
        cbox1.add_callback('activated', self.set_cutout_size_cb)
        cbox1.set_tooltip("Select size of pixel table")
        btns.add_widget(cbox1, stretch=0)

        # control for selecting a mark
        cbox2 = Widgets.ComboBox()
        for tag in self.marks:
            cbox2.append_text(tag)
        if self.mark_selected is None:
            cbox2.set_index(0)
        else:
            cbox2.show_text(self.mark_selected)
        cbox2.add_callback('activated', self.mark_select_cb)
        self.w.marks = cbox2
        cbox2.set_tooltip("Select a mark")
        #cbox2.setMinimumContentsLength(8)
        btns.add_widget(cbox2, stretch=0)

        btn1 = Widgets.Button("Delete")
        btn1.add_callback('activated', lambda w: self.clear_mark_cb())
        btn1.set_tooltip("Delete selected mark")
        btns.add_widget(btn1, stretch=0)

        btn2 = Widgets.Button("Delete All")
        btn2.add_callback('activated', lambda w: self.clear_all())
        btn2.set_tooltip("Clear all marks")
        btns.add_widget(btn2, stretch=0)
        btns.add_widget(Widgets.Label(''), stretch=1)

        vbox2 = Widgets.VBox()
        vbox2.add_widget(btns, stretch=0)

        btns = Widgets.HBox()
        btns.set_border_width(4)
        btns.set_spacing(4)

        btn3 = Widgets.CheckBox("Pan to mark")
        btn3.set_state(self.pan2mark)
        btn3.add_callback('activated', self.pan2mark_cb)
        btn3.set_tooltip("Pan follows selected mark")
        btns.add_widget(btn3)
        btns.add_widget(Widgets.Label(''), stretch=1)

        vbox2.add_widget(btns, stretch=0)

        captions = [
            ('Font size:', 'label', 'Font size', 'combobox'),
        ]
        w, b = Widgets.build_info(captions)
        self.w.update(b)
        vbox2.add_widget(w, stretch=0)

        b.font_size.set_tooltip("Set font size for pixel display")
        for size in (8, 9, 10, 11, 12, 14, 16):
            b.font_size.append_text(str(size))
        b.font_size.show_text(str(self.fontsize))
        b.font_size.add_callback('activated', self.set_font_size_cb)

        vbox2.add_widget(Widgets.Label(''), stretch=1)
        vbox.add_widget(vbox2, stretch=1)

        ## spacer = Widgets.Label('')
        ## vbox.add_widget(spacer, stretch=1)

        top.add_widget(sw, stretch=1)

        btns = Widgets.HBox()
        btns.set_border_width(4)
        btns.set_spacing(4)

        btn = Widgets.Button("Close")
        btn.add_callback('activated', lambda w: self.close())
        btns.add_widget(btn)
        btns.add_widget(Widgets.Label(''), stretch=1)

        top.add_widget(btns, stretch=0)
        container.add_widget(top, stretch=1)