def __init__(self, session, parent=None): self.logger = log.get_logger( name='ginga', level=20, null=True, # uncomment for debugging # log_stderr=True ) self.canvas = ImageViewCanvas(self.logger, render='widget') # prevent widget from grabbing focus try: self.canvas.set_enter_focus(False) except AttributeError: self.canvas.set_follow_focus(False) # enable interactive features bindings = self.canvas.get_bindings() bindings.enable_all(True) self.canvas.add_callback('none-move', self.motion_readout) self.canvas.add_callback('draw-event', self._apply_roi_cb) self.canvas.add_callback('draw-down', self._clear_roi_cb) self.canvas.enable_draw(False) self.canvas.enable_autozoom('off') self.canvas.set_zoom_algorithm('rate') self.canvas.set_zoomrate(1.4) bm = self.canvas.get_bindmap() bm.add_callback('mode-set', self.mode_set_cb) self.mode_w = None self.mode_actns = {} # Create settings and set defaults settings = self.canvas.get_settings() self.settings = settings settings.getSetting('cuts').add_callback('set', self.cut_levels_cb) settings.set(autozoom='off', autocuts='override', autocenter='override') # make color bar, with color maps shared from ginga canvas self.colorbar = ColorBar.ColorBar(self.logger) rgbmap = self.canvas.get_rgbmap() rgbmap.add_callback('changed', self.rgbmap_cb, self.canvas) self.colorbar.set_rgbmap(rgbmap) # make coordinates/value readout self.readout = Readout.Readout(-1, -1) self.roi_tag = None super(GingaWidget, self).__init__(session, parent)
def build_colorbar(self): cbar = ColorBar.ColorBar(self.logger) cbar.set_cmap(self.cm) cbar.set_imap(self.im) cbar.resize(700, 15) #cbar.show() self.colorbar = cbar self.add_callback('active-image', self.change_cbar, cbar) cbar.add_callback('motion', self.cbar_value_cb) fr = QtGui.QFrame() fr.setContentsMargins(0, 0, 0, 0) layout = QtGui.QHBoxLayout() fr.setLayout(layout) layout.setContentsMargins(0, 0, 0, 0) fr.setFrameStyle(QtGui.QFrame.Box | QtGui.QFrame.Raised) layout.addWidget(cbar, stretch=1) return fr
import sys from ginga.qtw.QtHelp import QtGui, QtCore from ginga.qtw import ColorBar from ginga import cmap, imap import logging app = QtGui.QApplication([]) logger = logging.getLogger('cbar') w = ColorBar.ColorBar(logger) w.set_cmap(cmap.get_cmap('rainbow')) w.set_imap(imap.get_imap('ramp')) w.show() app.exec_()
def _build_gui(self, container): self.mframe = container vbox = QtHelp.VBox() # create the table table = QtGui.QTableView() self.table = table table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows) table.setSelectionMode(QtGui.QAbstractItemView.SingleSelection) table.setShowGrid(False) vh = table.verticalHeader() # Hack to make the rows in a TableView all have a # reasonable height for the data if QtHelp.have_pyqt5: vh.setSectionResizeMode(QtGui.QHeaderView.ResizeToContents) else: vh.setResizeMode(QtGui.QHeaderView.ResizeToContents) # Hide vertical header vh.setVisible(False) vbox.addWidget(table, stretch=1) self.cbar = ColorBar.ColorBar(self.logger) self.cbar.set_cmap(self.cmap) self.cbar.set_imap(self.imap) #self.cbar.set_size_request(-1, 20) rgbmap = self.cbar.get_rgbmap() rgbmap.add_callback('changed', lambda *args: self.replot_stars()) vbox.addWidget(self.cbar, stretch=0) btns = QtHelp.HBox() btns.setSpacing(5) combobox = QtHelp.ComboBox() options = [] index = 0 for name in self.cmap_names: options.append(name) combobox.addItem(name) index += 1 cmap_name = self.magcmap try: index = self.cmap_names.index(cmap_name) except Exception: index = self.cmap_names.index('ramp') combobox.setCurrentIndex(index) combobox.activated.connect(self.set_cmap_cb) self.btn['cmap'] = combobox btns.addWidget(combobox, stretch=0, alignment=QtCore.Qt.AlignRight) combobox = QtHelp.ComboBox() options = [] index = 0 for name in self.imap_names: options.append(name) combobox.addItem(name) index += 1 imap_name = self.magimap try: index = self.imap_names.index(imap_name) except Exception: index = self.imap_names.index('ramp') combobox.setCurrentIndex(index) combobox.activated.connect(self.set_imap_cb) self.btn['imap'] = combobox btns.addWidget(combobox, stretch=0, alignment=QtCore.Qt.AlignRight) vbox.addWidget(btns, stretch=0, alignment=QtCore.Qt.AlignTop) btns = QtHelp.HBox() btns.setSpacing(5) for name in ('Plot', 'Clear', #'Close' ): btn = QtGui.QPushButton(name) btns.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignLeft) self.btn[name.lower()] = btn self.btn.plot.clicked.connect(self.replot_stars) self.btn.clear.clicked.connect(self.clear) #self.btn.close.clicked.connect(self.close) combobox = QtHelp.ComboBox() options = [] index = 0 for name in ['Mag']: options.append(name) combobox.addItem(name) index += 1 combobox.setCurrentIndex(0) combobox.activated.connect(self.set_field_cb) self.btn['field'] = combobox btns.addWidget(combobox, stretch=0, alignment=QtCore.Qt.AlignLeft) vbox.addWidget(btns, stretch=0, alignment=QtCore.Qt.AlignTop) # create the table info = Bunch.Bunch(columns=self.columns, color='Mag') self.build_table(info) self.mframe.addWidget(vbox, stretch=1)
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 = ImageViewCanvas(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_all(True) self.cp_tag = 'compass' # 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('gray') 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('gray') 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, container): self.logger = logger self.tag = None self.mycolor = 'skyblue' self.magmap = 'stairs8' self.mag_max = 25.0 self.mag_min = 0.0 # keys: are name, ra, dec, mag, flag, b_r, preference, priority, dst # TODO: automate this generation self.columns = [('Name', 'name'), ('RA', 'ra'), ('DEC', 'dec'), ('Mag', 'mag'), ('Preference', 'preference'), ('Priority', 'priority'), ('Flag', 'flag'), ('b-r', 'b_r'), ('Dst', 'dst'), ('Description', 'description'), ] self.catalog = None self.cursor = 0 self.color_cursor = 'red' self.color_selected = 'skyblue' self.selection_mode = 'single' self.selected = [] self.moving_cursor = False self.btn = Bunch.Bunch() self.mframe = container vbox = QtHelp.VBox() # create the table table = QtGui.QTableWidget() table.setColumnCount(len(self.columns)) table.cellClicked.connect(self.select_star) self.table = table col = 0 for hdr, kwd in self.columns: item = QtGui.QTableWidgetItem(hdr) table.setHorizontalHeaderItem(col, item) col += 1 vbox.addWidget(table, stretch=1) self.cbar = ColorBar.ColorBar(self.logger) self.cmap = cmap.get_cmap(self.magmap) self.imap = imap.get_imap('ramp') self.cbar.set_cmap(self.cmap) self.cbar.set_imap(self.imap) #self.cbar.set_size_request(-1, 20) vbox.addWidget(self.cbar, stretch=0) btns = QtHelp.HBox() btns.setSpacing(5) for name in ('Plot', 'Clear', #'Close' ): btn = QtGui.QPushButton(name) btns.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignCenter) self.btn[name.lower()] = btn self.btn.plot.clicked.connect(self.replot_stars) self.btn.clear.clicked.connect(self.clear) #self.btn.close.clicked.connect(self.close) vbox.addWidget(btns, stretch=0, alignment=QtCore.Qt.AlignTop) self.mframe.addWidget(vbox, stretch=1)