def __init__(self, logger): super(FitsViewer, self).__init__() self.logger = logger menubar = self.menuBar() # create a File pulldown menu, and add it to the menu bar filemenu = menubar.addMenu("File") item = QtGui.QAction("Open File", menubar) item.triggered.connect(self.open_file) filemenu.addAction(item) sep = QtGui.QAction(menubar) sep.setSeparator(True) filemenu.addAction(sep) item = QtGui.QAction("Quit", menubar) item.triggered.connect(self.close) filemenu.addAction(item) # Add matplotlib color maps to our built in ones cmap.add_matplotlib_cmaps() self.cmaps = cmap.get_names() self.imaps = imap.get_names() wd, ht = 500, 500 # Create a Ginga widget fi = FitsImageCanvas(logger, render='widget') fi.enable_autocuts('on') fi.set_autocut_params('zscale') fi.enable_autozoom('on') fi.enable_draw(False) 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 # enable various key and mouse controlled actions bd = fi.get_bindings() bd.enable_pan(True) bd.enable_zoom(True) bd.enable_cuts(True) bd.enable_flip(True) bd.enable_rotate(True) bd.enable_cmap(True) # pack widget into layout gingaw = fi.get_widget() gingaw.resize(wd, ht) vbox1 = QtGui.QWidget() layout = QtGui.QVBoxLayout() layout.addWidget(gingaw, stretch=1) self.cm = cmap.get_cmap('ramp') self.im = imap.get_imap('ramp') # add color bar rgbmap = fi.get_rgbmap() rgbmap.set_hash_size(256) cbar = ColorBar.ColorBar(self.logger, rgbmap=rgbmap, link=True) cbar.resize(-1, 15) #cbar.show() self.colorbar = cbar layout.addWidget(cbar, stretch=0) settings = fi.get_settings() settings.getSetting('cuts').add_callback('set', self.change_range_cb, fi, self.colorbar) # color map selection widget wcmap = QtGui.QComboBox() for name in self.cmaps: wcmap.addItem(name) index = self.cmaps.index('ramp') wcmap.setCurrentIndex(index) wcmap.activated.connect(self.set_cmap_cb) self.wcmap = wcmap # intensity map selection widget wimap = QtGui.QComboBox() for name in self.imaps: wimap.addItem(name) index = self.imaps.index('ramp') wimap.setCurrentIndex(index) wimap.activated.connect(self.set_cmap_cb) self.wimap = wimap #wopen = QtGui.QPushButton("Open File") #wopen.clicked.connect(self.open_file) # add buttons to layout hbox = QtGui.QHBoxLayout() hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2)) hbox.addStretch(1) for w in (wcmap, wimap): hbox.addWidget(w, stretch=0) hw = QtGui.QWidget() hw.setLayout(hbox) layout.addWidget(hw, stretch=0) vbox1.setLayout(layout) # Create a matplotlib Figure #self.fig = matplotlib.figure.Figure(figsize=(wd, ht)) self.fig = matplotlib.figure.Figure() self.canvas = FigureCanvas(self.fig) vbox2 = QtGui.QWidget() layout = QtGui.QVBoxLayout() # scrw = QtGui.QScrollArea() # scrw.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) # scrw.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded) # scrw.setWidgetResizable(True) # layout.addWidget(scrw, stretch=1) # scrw.setWidget(self.canvas) layout.addWidget(self.canvas, stretch=1) # Add matplotlib buttons hbox = QtGui.QHBoxLayout() hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2)) wgetimg = QtGui.QPushButton("Get Data") wgetimg.clicked.connect(self.get_image) wgetrgb = QtGui.QPushButton("Get RGB") wgetrgb.clicked.connect(self.get_rgb_image) #wquit = QtGui.QPushButton("Quit") #wquit.clicked.connect(self.close) hbox.addStretch(1) for w in (wgetimg, wgetrgb): hbox.addWidget(w, stretch=0) hw = QtGui.QWidget() hw.setLayout(hbox) layout.addWidget(hw, stretch=0) vbox2.setLayout(layout) vbox = QtGui.QVBoxLayout() vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2)) vbox.setSpacing(1) w = QtGui.QWidget() layout = QtGui.QHBoxLayout() layout.addWidget(vbox1, stretch=1.0) layout.addWidget(vbox2, stretch=1.0) w.setLayout(layout) vbox.addWidget(w, stretch=1) self.readout = QtGui.QLabel("") vbox.addWidget(self.readout, stretch=0, alignment=QtCore.Qt.AlignCenter) vw = QtGui.QWidget() vw.setLayout(vbox) self.setCentralWidget(vw)
def __init__(self, logger): super(FitsViewer, self).__init__() self.logger = logger self.drawcolors = ['white', 'black', 'red', 'yellow', 'blue', 'green'] fi = FitsImageCanvas(logger, render='widget') fi.enable_autocuts('on') fi.set_autocut_params('zscale') fi.enable_autozoom('on') fi.enable_draw(True) fi.set_drawtype('ruler') fi.set_drawcolor('blue') 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_pan(True) bd.enable_zoom(True) bd.enable_cuts(True) bd.enable_flip(True) bd.enable_rotate(True) bd.enable_cmap(True) w = fi.get_widget() w.resize(512, 512) vbox = QtGui.QVBoxLayout() vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2)) vbox.setSpacing(1) vbox.addWidget(w, stretch=1) self.readout = QtGui.QLabel("") vbox.addWidget(self.readout, stretch=0, alignment=QtCore.Qt.AlignCenter) hbox = QtGui.QHBoxLayout() hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2)) wdrawtype = QtGui.QComboBox() self.drawtypes = fi.get_drawtypes() for name in self.drawtypes: wdrawtype.addItem(name) index = self.drawtypes.index('ruler') wdrawtype.setCurrentIndex(index) self.connect(wdrawtype, QtCore.SIGNAL("activated(QString)"), self.set_drawparams) self.wdrawtype = wdrawtype wdrawcolor = QtGui.QComboBox() for name in self.drawcolors: wdrawcolor.addItem(name) index = self.drawcolors.index('blue') wdrawcolor.setCurrentIndex(index) self.connect(wdrawcolor, QtCore.SIGNAL("activated(QString)"), self.set_drawparams) self.wdrawcolor = wdrawcolor wclear = QtGui.QPushButton("Clear Canvas") self.connect(wclear, QtCore.SIGNAL("clicked()"), self.clear_canvas) wopen = QtGui.QPushButton("Open File") self.connect(wopen, QtCore.SIGNAL("clicked()"), self.open_file) wquit = QtGui.QPushButton("Quit") self.connect(wquit, QtCore.SIGNAL("clicked()"), self, QtCore.SLOT("close()")) hbox.addStretch(1) for w in (wopen, wdrawtype, wdrawcolor, wclear, 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)