Esempio n. 1
0
File: ipg.py Progetto: Cadair/ginga
    def new_viewer(self, name=None, settings=None):
        if not name:
            self.count += 1
            name = 'v%d' % self.count

        if settings is None:
            settings = self.preferences.createCategory('ipg_viewer')
            settings.load(onError='silent')
            settings.addDefaults(autocut_method='zscale')

        # instantiate bindings loaded with users preferences
        bclass = IPyNbImageView.bindingsClass
        bindprefs = self.preferences.createCategory('bindings')
        bd = bclass(self.logger, settings=bindprefs)

        # create a ginga basic object for user interaction
        fi = IPyNbImageView(self.logger, settings=settings,
                            render='widget', bindings=bd)
        fi.enable_draw(False)
        fi.set_callback('drag-drop', self.drop_file, name)
        fi.set_bg(0.2, 0.2, 0.2)
        fi.ui_setActive(True)

        # expose the fits viewer to the shared namespace
        self.kapp.namespace[name] = fi

        # enable various interactive operations
        bd = fi.get_bindings()
        bd.enable_all(True)

        # get the ginga Qt widget
        w = fi.get_widget()
        w.resize(512, 512)

        # pack it into a qt window with a couple other buttons
        vw = QtGui.QWidget()
        vbox = QtGui.QVBoxLayout()
        vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2))
        vbox.setSpacing(1)
        vbox.addWidget(w, stretch=1)

        # for simple WCS readout
        self.readout = Readout(-1, 16)
        readout = self.readout.get_widget()
        fi.set_callback('none-move', self.motion, self.readout)
        vbox.addWidget(readout, stretch=0,
                       alignment=QtCore.Qt.AlignCenter)

        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))

        wopen = QtGui.QPushButton("Open File")
        def _open_file(name):
            return lambda: self.open_file(name)
        wopen.clicked.connect(_open_file(name))
        wquit = QtGui.QPushButton("Close")
        def _close(name):
            return lambda: self.close_viewer(name)
        wquit.clicked.connect(_close(name))

        hbox.addStretch(1)
        for w in (wopen, wquit):
            hbox.addWidget(w, stretch=0)

        hw = QtGui.QWidget()
        hw.setLayout(hbox)
        vbox.addWidget(hw, stretch=0)

        vw.setLayout(vbox)
        vw.resize(524, 540)
        vw.setWindowTitle("Ginga: %s" % name)
        self.viewers[name] = vw
        vw.showNormal()
        vw.raise_()
        vw.activateWindow()
Esempio n. 2
0
    def new_viewer(self, name=None, settings=None):
        if not name:
            self.count += 1
            name = 'v%d' % self.count

        if settings is None:
            settings = self.preferences.createCategory('ipg_viewer')
            settings.load(onError='silent')
            settings.addDefaults(autocut_method='zscale')

        # instantiate bindings loaded with users preferences
        bclass = IPyNbImageView.bindingsClass
        bindprefs = self.preferences.createCategory('bindings')
        bd = bclass(self.logger, settings=bindprefs)

        # create a ginga basic object for user interaction
        fi = IPyNbImageView(self.logger,
                            settings=settings,
                            render='widget',
                            bindings=bd)
        fi.enable_draw(False)
        fi.set_callback('drag-drop', self.drop_file, name)
        fi.set_bg(0.2, 0.2, 0.2)
        fi.ui_setActive(True)

        # expose the fits viewer to the shared namespace
        self.kapp.namespace[name] = fi

        # enable various interactive operations
        bd = fi.get_bindings()
        bd.enable_all(True)

        # get the ginga Qt widget
        w = fi.get_widget()
        w.resize(512, 512)

        # pack it into a qt window with a couple other buttons
        vw = QtGui.QWidget()
        vbox = QtGui.QVBoxLayout()
        vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2))
        vbox.setSpacing(1)
        vbox.addWidget(w, stretch=1)

        # for simple WCS readout
        self.readout = Readout(-1, 16)
        readout = self.readout.get_widget()
        fi.set_callback('none-move', self.motion, self.readout)
        vbox.addWidget(readout, stretch=0, alignment=QtCore.Qt.AlignCenter)

        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))

        wopen = QtGui.QPushButton("Open File")

        def _open_file(name):
            return lambda: self.open_file(name)

        wopen.clicked.connect(_open_file(name))
        wquit = QtGui.QPushButton("Close")

        def _close(name):
            return lambda: self.close_viewer(name)

        wquit.clicked.connect(_close(name))

        hbox.addStretch(1)
        for w in (wopen, wquit):
            hbox.addWidget(w, stretch=0)

        hw = QtGui.QWidget()
        hw.setLayout(hbox)
        vbox.addWidget(hw, stretch=0)

        vw.setLayout(vbox)
        vw.resize(524, 540)
        vw.setWindowTitle("Ginga: %s" % name)
        self.viewers[name] = vw
        vw.showNormal()
        vw.raise_()
        vw.activateWindow()
Esempio n. 3
0
File: ipg.py Progetto: Cadair/ginga
class StartMenu(QtGui.QMainWindow):

    def __init__(self, logger, app, kapp, prefs):
        super(StartMenu, self).__init__()
        self.logger = logger
        self.preferences = prefs
        self.count = 0
        self.viewers = {}
        self.app = app
        self.kapp = kapp
        self.app.aboutToQuit.connect(self.quit)

        vbox = QtGui.QVBoxLayout()
        vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2))
        vbox.setSpacing(1)

        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))

        console = QtGui.QPushButton('Qt Console')
        if self.kapp.ipkernel is None:
            console.setEnabled(False)
        console.clicked.connect(self.kapp.new_qt_console)

        newfits = QtGui.QPushButton('New Viewer')
        newfits.clicked.connect(self.new_viewer)

        wquit = QtGui.QPushButton("Quit")
        wquit.clicked.connect(self.quit)

        hbox.addStretch(1)
        for w in (console, newfits, wquit):
            hbox.addWidget(w, stretch=0)

        hw = QtGui.QWidget()
        hw.setLayout(hbox)
        vbox.addWidget(hw, stretch=0)

        vw = QtGui.QWidget()
        self.setCentralWidget(vw)
        vw.setLayout(vbox)
        self.setWindowTitle("Ginga IPython Console")
        self.showNormal()
        self.raise_()
        self.activateWindow()

    def new_viewer(self, name=None, settings=None):
        if not name:
            self.count += 1
            name = 'v%d' % self.count

        if settings is None:
            settings = self.preferences.createCategory('ipg_viewer')
            settings.load(onError='silent')
            settings.addDefaults(autocut_method='zscale')

        # instantiate bindings loaded with users preferences
        bclass = IPyNbImageView.bindingsClass
        bindprefs = self.preferences.createCategory('bindings')
        bd = bclass(self.logger, settings=bindprefs)

        # create a ginga basic object for user interaction
        fi = IPyNbImageView(self.logger, settings=settings,
                            render='widget', bindings=bd)
        fi.enable_draw(False)
        fi.set_callback('drag-drop', self.drop_file, name)
        fi.set_bg(0.2, 0.2, 0.2)
        fi.ui_setActive(True)

        # expose the fits viewer to the shared namespace
        self.kapp.namespace[name] = fi

        # enable various interactive operations
        bd = fi.get_bindings()
        bd.enable_all(True)

        # get the ginga Qt widget
        w = fi.get_widget()
        w.resize(512, 512)

        # pack it into a qt window with a couple other buttons
        vw = QtGui.QWidget()
        vbox = QtGui.QVBoxLayout()
        vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2))
        vbox.setSpacing(1)
        vbox.addWidget(w, stretch=1)

        # for simple WCS readout
        self.readout = Readout(-1, 16)
        readout = self.readout.get_widget()
        fi.set_callback('none-move', self.motion, self.readout)
        vbox.addWidget(readout, stretch=0,
                       alignment=QtCore.Qt.AlignCenter)

        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))

        wopen = QtGui.QPushButton("Open File")
        def _open_file(name):
            return lambda: self.open_file(name)
        wopen.clicked.connect(_open_file(name))
        wquit = QtGui.QPushButton("Close")
        def _close(name):
            return lambda: self.close_viewer(name)
        wquit.clicked.connect(_close(name))

        hbox.addStretch(1)
        for w in (wopen, wquit):
            hbox.addWidget(w, stretch=0)

        hw = QtGui.QWidget()
        hw.setLayout(hbox)
        vbox.addWidget(hw, stretch=0)

        vw.setLayout(vbox)
        vw.resize(524, 540)
        vw.setWindowTitle("Ginga: %s" % name)
        self.viewers[name] = vw
        vw.showNormal()
        vw.raise_()
        vw.activateWindow()

    def close_viewer(self, name):
        w = self.viewers[name]
        del self.viewers[name]
        # remove variable from namespace
        del self.kapp.namespace[name]
        w.setParent(None)
        w.deleteLater()

    def load_file(self, filepath, name):
        image = AstroImage.AstroImage(logger=self.logger)
        image.load_file(filepath)

        fi = self.kapp.namespace[name]
        fi.set_image(image)

    def open_file(self, name):
        res = QtGui.QFileDialog.getOpenFileName(self, "Open FITS file",
                                                ".", "FITS files (*.fits)")
        if isinstance(res, tuple):
            fileName = res[0]
        else:
            fileName = str(res)
        self.load_file(fileName, name)

    def drop_file(self, viewer, paths, name):
        fileName = paths[0]
        self.load_file(fileName, name)

    def motion(self, viewer, button, data_x, data_y, readout):

        # Get the value under the data coordinates
        try:
            #value = viewer.get_data(data_x, data_y)
            # We report the value across the pixel, even though the coords
            # change halfway across the pixel
            value = viewer.get_data(int(data_x+0.5), int(data_y+0.5))

        except Exception:
            value = None

        fits_x, fits_y = data_x + 1, data_y + 1

        # Calculate WCS RA
        try:
            # NOTE: image function operates on DATA space coords
            image = viewer.get_image()
            if image is None:
                # No image loaded
                return
            ra_txt, dec_txt = image.pixtoradec(fits_x, fits_y,
                                               format='str', coords='fits')
        except Exception as e:
            self.logger.warn("Bad coordinate conversion: %s" % (
                str(e)))
            ra_txt  = 'BAD WCS'
            dec_txt = 'BAD WCS'

        text = "RA: %s  DEC: %s  X: %.2f  Y: %.2f  Value: %s" % (
            ra_txt, dec_txt, fits_x, fits_y, value)
        readout.set_text(text)

    def quit(self):
        names = list(self.viewers.keys())
        for name in names:
            self.close_viewer(name)
        self.kapp.cleanup_consoles()
        self.setParent(None)
        self.deleteLater()
Esempio n. 4
0
class StartMenu(QtGui.QMainWindow):
    def __init__(self, logger, app, kapp, prefs):
        super(StartMenu, self).__init__()
        self.logger = logger
        self.preferences = prefs
        self.count = 0
        self.viewers = {}
        self.app = app
        self.kapp = kapp
        self.app.aboutToQuit.connect(self.quit)

        vbox = QtGui.QVBoxLayout()
        vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2))
        vbox.setSpacing(1)

        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))

        console = QtGui.QPushButton('Qt Console')
        if self.kapp.ipkernel is None:
            console.setEnabled(False)
        console.clicked.connect(self.kapp.new_qt_console)

        newfits = QtGui.QPushButton('New Viewer')
        newfits.clicked.connect(self.new_viewer)

        wquit = QtGui.QPushButton("Quit")
        wquit.clicked.connect(self.quit)

        hbox.addStretch(1)
        for w in (console, newfits, wquit):
            hbox.addWidget(w, stretch=0)

        hw = QtGui.QWidget()
        hw.setLayout(hbox)
        vbox.addWidget(hw, stretch=0)

        vw = QtGui.QWidget()
        self.setCentralWidget(vw)
        vw.setLayout(vbox)
        self.setWindowTitle("Ginga IPython Console")
        self.showNormal()
        self.raise_()
        self.activateWindow()

    def new_viewer(self, name=None, settings=None):
        if not name:
            self.count += 1
            name = 'v%d' % self.count

        if settings is None:
            settings = self.preferences.createCategory('ipg_viewer')
            settings.load(onError='silent')
            settings.addDefaults(autocut_method='zscale')

        # instantiate bindings loaded with users preferences
        bclass = IPyNbImageView.bindingsClass
        bindprefs = self.preferences.createCategory('bindings')
        bd = bclass(self.logger, settings=bindprefs)

        # create a ginga basic object for user interaction
        fi = IPyNbImageView(self.logger,
                            settings=settings,
                            render='widget',
                            bindings=bd)
        fi.enable_draw(False)
        fi.set_callback('drag-drop', self.drop_file, name)
        fi.set_bg(0.2, 0.2, 0.2)
        fi.ui_setActive(True)

        # expose the fits viewer to the shared namespace
        self.kapp.namespace[name] = fi

        # enable various interactive operations
        bd = fi.get_bindings()
        bd.enable_all(True)

        # get the ginga Qt widget
        w = fi.get_widget()
        w.resize(512, 512)

        # pack it into a qt window with a couple other buttons
        vw = QtGui.QWidget()
        vbox = QtGui.QVBoxLayout()
        vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2))
        vbox.setSpacing(1)
        vbox.addWidget(w, stretch=1)

        # for simple WCS readout
        self.readout = Readout(-1, 16)
        readout = self.readout.get_widget()
        fi.set_callback('none-move', self.motion, self.readout)
        vbox.addWidget(readout, stretch=0, alignment=QtCore.Qt.AlignCenter)

        hbox = QtGui.QHBoxLayout()
        hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2))

        wopen = QtGui.QPushButton("Open File")

        def _open_file(name):
            return lambda: self.open_file(name)

        wopen.clicked.connect(_open_file(name))
        wquit = QtGui.QPushButton("Close")

        def _close(name):
            return lambda: self.close_viewer(name)

        wquit.clicked.connect(_close(name))

        hbox.addStretch(1)
        for w in (wopen, wquit):
            hbox.addWidget(w, stretch=0)

        hw = QtGui.QWidget()
        hw.setLayout(hbox)
        vbox.addWidget(hw, stretch=0)

        vw.setLayout(vbox)
        vw.resize(524, 540)
        vw.setWindowTitle("Ginga: %s" % name)
        self.viewers[name] = vw
        vw.showNormal()
        vw.raise_()
        vw.activateWindow()

    def close_viewer(self, name):
        w = self.viewers[name]
        del self.viewers[name]
        # remove variable from namespace
        del self.kapp.namespace[name]
        w.setParent(None)
        w.deleteLater()

    def load_file(self, filepath, name):
        image = AstroImage.AstroImage(logger=self.logger)
        image.load_file(filepath)

        fi = self.kapp.namespace[name]
        fi.set_image(image)

    def open_file(self, name):
        res = QtGui.QFileDialog.getOpenFileName(self, "Open FITS file", ".",
                                                "FITS files (*.fits)")
        if isinstance(res, tuple):
            fileName = res[0]
        else:
            fileName = str(res)
        self.load_file(fileName, name)

    def drop_file(self, viewer, paths, name):
        fileName = paths[0]
        self.load_file(fileName, name)

    def motion(self, viewer, button, data_x, data_y, readout):

        # Get the value under the data coordinates
        try:
            #value = viewer.get_data(data_x, data_y)
            # We report the value across the pixel, even though the coords
            # change halfway across the pixel
            value = viewer.get_data(int(data_x + 0.5), int(data_y + 0.5))

        except Exception:
            value = None

        fits_x, fits_y = data_x + 1, data_y + 1

        # Calculate WCS RA
        try:
            # NOTE: image function operates on DATA space coords
            image = viewer.get_image()
            if image is None:
                # No image loaded
                return
            ra_txt, dec_txt = image.pixtoradec(fits_x,
                                               fits_y,
                                               format='str',
                                               coords='fits')
        except Exception as e:
            self.logger.warning("Bad coordinate conversion: %s" % (str(e)))
            ra_txt = 'BAD WCS'
            dec_txt = 'BAD WCS'

        text = "RA: %s  DEC: %s  X: %.2f  Y: %.2f  Value: %s" % (
            ra_txt, dec_txt, fits_x, fits_y, value)
        readout.set_text(text)

    def quit(self):
        names = list(self.viewers.keys())
        for name in names:
            self.close_viewer(name)
        self.kapp.cleanup_consoles()
        self.setParent(None)
        self.deleteLater()