def build_gui(self, container): # Splitter is just to provide a way to size the graph # to a reasonable size vpaned = QtGui.QSplitter() vpaned.setOrientation(QtCore.Qt.Vertical) # Make the cuts plot twidget = QtHelp.VBox() vbox1 = twidget.layout() vbox1.setContentsMargins(4, 4, 4, 4) vbox1.setSpacing(2) msgFont = QtGui.QFont("Sans", 14) tw = QtGui.QLabel() tw.setFont(msgFont) tw.setWordWrap(True) self.tw = tw fr = QtHelp.Frame("Instructions") fr.layout().addWidget(tw, stretch=1, alignment=QtCore.Qt.AlignTop) vbox1.addWidget(fr, stretch=0, alignment=QtCore.Qt.AlignTop) self.plot = Plot.Plot(self.logger) w = self.plot.get_widget() vbox1.addWidget(w, stretch=1, alignment=QtCore.Qt.AlignTop) captions = (('Cut Low', 'xlabel', '@Cut Low', 'entry'), ('Cut High', 'xlabel', '@Cut High', 'entry', 'Cut Levels', 'button'), ('Auto Levels', 'button'), ) w, b = QtHelp.build_info(captions) self.w.update(b) b.cut_levels.setToolTip("Set cut levels manually") b.auto_levels.setToolTip("Set cut levels by algorithm") b.cut_low.setToolTip("Set low cut level (press Enter)") b.cut_high.setToolTip("Set high cut level (press Enter)") b.cut_low.returnPressed.connect(self.cut_levels) b.cut_high.returnPressed.connect(self.cut_levels) b.cut_levels.clicked.connect(self.cut_levels) b.auto_levels.clicked.connect(self.auto_levels) vbox1.addWidget(w, stretch=0, alignment=QtCore.Qt.AlignLeft) btns = QtHelp.HBox() layout= btns.layout() layout.setSpacing(3) #btns.set_child_size(15, -1) btn = QtGui.QPushButton("Close") btn.clicked.connect(self.close) layout.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignLeft) btn = QtGui.QPushButton("Full Image") btn.clicked.connect(self.full_image) layout.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignLeft) vbox1.addWidget(btns, stretch=0, alignment=QtCore.Qt.AlignLeft) vpaned.addWidget(twidget) vpaned.addWidget(QtGui.QLabel('')) container.addWidget(vpaned, stretch=1) self.gui_up = True
def build_gui(self, container): # Splitter is just to provide a way to size the graph # to a reasonable size vpaned = QtGui.QSplitter() vpaned.setOrientation(QtCore.Qt.Vertical) # Make the cuts plot twidget = QtHelp.VBox() vbox1 = twidget.layout() vbox1.setContentsMargins(4, 4, 4, 4) vbox1.setSpacing(2) msgFont = QtGui.QFont("Sans", 14) tw = QtGui.QLabel() tw.setFont(msgFont) tw.setWordWrap(True) self.tw = tw fr = QtHelp.Frame("Instructions") fr.layout().addWidget(tw, stretch=1, alignment=QtCore.Qt.AlignTop) vbox1.addWidget(fr, stretch=0, alignment=QtCore.Qt.AlignTop) self.plot = Plot.Cuts(self.logger) w = self.plot.get_widget() vbox1.addWidget(w, stretch=1, alignment=QtCore.Qt.AlignTop) hbox = QtHelp.HBox() hbox.setSpacing(4) # control for selecting a cut combobox = QtHelp.ComboBox() for tag in self.tags: combobox.append_text(tag) if self.cutstag == None: combobox.setCurrentIndex(0) else: combobox.show_text(self.cutstag) combobox.activated.connect(self.cut_select_cb) self.w.cuts = combobox combobox.setToolTip("Select a cut") hbox.addWidget(combobox) btn = QtGui.QPushButton("Delete") btn.clicked.connect(self.delete_cut_cb) btn.setToolTip("Delete selected cut") hbox.addWidget(btn) btn = QtGui.QPushButton("Delete All") btn.clicked.connect(self.delete_all) btn.setToolTip("Clear all cuts") hbox.addWidget(btn) ## btn = QtGui.CheckBox("Move together") ## #btn.stateChanged.connect(self.movetogether_cb) ## btn.setChecked(self.move_together) ## btn.setToolTip("Move cuts as a group") ## hbox.addWidget(btn) vbox1.addWidget(hbox, stretch=0, alignment=QtCore.Qt.AlignLeft) btns = QtHelp.HBox() layout = btns.layout() layout.setSpacing(3) #btns.set_child_size(15, -1) btn = QtGui.QPushButton("Close") btn.clicked.connect(self.close) layout.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignLeft) vbox1.addWidget(btns, stretch=0, alignment=QtCore.Qt.AlignLeft) vpaned.addWidget(twidget) vpaned.addWidget(QtGui.QLabel('')) container.addWidget(vpaned, stretch=1)
def __init__(self, logger): super(FitsViewer, self).__init__() self.logger = logger self.drawcolors = colors.get_colors() fig = Figure() w = FigureCanvas(fig) fi = ImageViewCanvas(logger) 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 fi.set_figure(fig) fi.get_bindings().enable_all(True) 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) wdrawtype.activated.connect(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) wdrawcolor.activated.connect(self.set_drawparams) self.wdrawcolor = wdrawcolor wclear = QtGui.QPushButton("Clear Canvas") wclear.clicked.connect(self.clear_canvas) wopen = QtGui.QPushButton("Open File") wopen.clicked.connect(self.open_file) wquit = QtGui.QPushButton("Quit") wquit.clicked.connect(self.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)
def _create_info_window(self): sw = QtGui.QScrollArea() widget = QtGui.QWidget() vbox = QtGui.QVBoxLayout() vbox.setContentsMargins(2, 2, 2, 2) widget.setLayout(vbox) captions = ( ('Name', 'label'), ('Object', 'label'), ('X', 'label'), ('Y', 'label'), ('Value', 'label'), ('RA', 'label'), ('DEC', 'label'), ('Equinox', 'label'), ('Dimensions', 'label'), #('Slices', 'label', 'MultiDim', 'button'), ('Min', 'label'), ('Max', 'label'), ('Zoom', 'label'), ('Cut Low', 'xlabel', '@Cut Low', 'entry'), ('Cut High', 'xlabel', '@Cut High', 'entry'), ('Auto Levels', 'button', 'Cut Levels', 'button'), ('Cut New', 'label'), ('Zoom New', 'label'), ('Preferences', 'button'), ) w, b = QtHelp.build_info(captions) b.cut_levels.setToolTip("Set cut levels manually") b.auto_levels.setToolTip("Set cut levels by algorithm") b.cut_low.setToolTip("Set low cut level (press Enter)") b.cut_high.setToolTip("Set high cut level (press Enter)") b.preferences.setToolTip("Set preferences for this channel") #b.multidim.setToolTip("View other HDUs or slices") vbox.addWidget(w, stretch=0) # Convenience navigation buttons btns = QtGui.QWidget() layout = QtGui.QHBoxLayout() layout.setSpacing(3) btns.setLayout(layout) #btns.set_layout(gtk.BUTTONBOX_CENTER) #btns.set_child_size(15, -1) bw = Bunch.Bunch() for tup in ( #("Load", 'button', 'fits_open_48', "Open an image file"), ("Prev", 'button', 'prev_48', "Go to previous image"), ("Next", 'button', 'next_48', "Go to next image"), ("Zoom In", 'button', 'zoom_in_48', "Zoom in"), ("Zoom Out", 'button', 'zoom_out_48', "Zoom out"), ("Zoom Fit", 'button', 'zoom_fit_48', "Zoom to fit window size"), ("Zoom 1:1", 'button', 'zoom_100_48', "Zoom to 100% (1:1)"), #("Quit", 'button', 'exit', "Quit the program"), ): btn = self.fv.make_button(*tup) name = tup[0] if tup[3]: btn.setToolTip(tup[3]) bw[QtHelp._name_mangle(name, pfx='btn_')] = btn layout.addWidget(btn, stretch=0) #self.w.btn_load.connect("clicked", lambda w: self.gui_load_file()) bw.btn_prev.clicked.connect(self.fv.prev_img) bw.btn_next.clicked.connect(self.fv.next_img) bw.btn_zoom_in.clicked.connect(self.fv.zoom_in) bw.btn_zoom_out.clicked.connect(self.fv.zoom_out) bw.btn_zoom_fit.clicked.connect(self.fv.zoom_fit) bw.btn_zoom_1_1.clicked.connect(self.fv.zoom_1_to_1) vbox.addWidget(btns, stretch=0) #widget.show() sw.setWidget(widget) return sw, b
def _draw(self, cr): width, height = self.get_size() #print "window size is %d,%d" % (width, height) x1 = 0 x2 = width clr_wd = width // 256 rem_px = x2 - (clr_wd * 256) if rem_px > 0: ival = 256 // rem_px else: ival = 0 clr_ht = height #print "clr is %dx%d width=%d rem=%d ival=%d" % ( # width, height, clr_wd, rem_px, ival) j = ival off = 0 range_pts = [] for i in xrange(256): wd = clr_wd if rem_px > 0: j -= 1 if j == 0: rem_px -= 1 j = ival wd += 1 x = off (r, g, b) = self.rgbmap.get_rgbval(i) color = QtGui.QColor(r, g, b) cr.fillRect(QtCore.QRect(x, 0, wd, clr_ht), color) # Draw range scale if we are supposed to if self.t_showrange and self._interval.has_key(i): pct = float(i) / 256.0 val = int(self.loval + pct * (self.hival - self.loval)) text = "%d" % (val) rect = cr.boundingRect(0, 0, 1000, 1000, 0, text) x1, y1, x2, y2 = rect.getCoords() _wd = x2 - x1 _ht = y2 - y1 _ht = 14 rx = x ry = _ht - 2 range_pts.append((rx, ry, text)) off += wd # draw range pen = cr.pen() cr.setFont(QtGui.QFont(self.t_font, pointSize=self.t_fontsize)) color = QtGui.QColor() color.setRgbF(0.0, 0.0, 0.0) pen.setColor(color) cr.setPen(pen) for (x, y, text) in range_pts: # tick cr.drawLine(x, 0, x, 2) # number cr.drawText(x, y, text)
def redo(self): """This updates DQ flags from canvas selection.""" self.w.x.set_text(str(self.xcen)) self.w.y.set_text(str(self.ycen)) # Clear previous single-pixel results self.pxdqlist.clear() self.w.dq.set_text(self._no_keyword) image = self.fitsimage.get_image() depth = image.get_depth() if depth == 3: self.logger.error('DQ inspection for RGB image is not supported') return True header = image.get_header() extname = header.get(self._ext_key, self._no_keyword).upper() instrument = header.get(self._ins_key, None) # If displayed extension is not DQ, extract DQ array with same EXTVER if extname != self._dq_extname: imfile = image.metadata['path'] imname = image.metadata['name'].split('[')[0] extver = header.get(self._extver_key, self._dummy_value) dq_extnum = (self._dq_extname, extver) with fits.open(imfile) as pf: dqsrc = dq_extnum in pf # Do not continue if no DQ extension if not dqsrc: self.logger.error('{0} extension not found for {1}'.format( dq_extnum, imfile)) return True chname = self.fv.get_channelName(self.fitsimage) chinfo = self.fv.get_channelInfo(chname) dqname = '{0}[{1},{2}]'.format(imname, self._dq_extname, extver) if dqname in chinfo.datasrc: # DQ already loaded self.logger.debug('Loading {0} from cache'.format(dqname)) dqsrc = chinfo.datasrc[dqname] else: # Force load DQ data self.logger.debug('Loading {0} from {1}'.format( dqname, imfile)) dqsrc = self.fv.load_image(imfile, idx=dq_extnum) future = Future.Future() future.freeze(self.fv.load_image, imfile, idx=dq_extnum) dqsrc.set(path=imfile, idx=dq_extnum, name=dqname, image_future=future) chinfo.datasrc[dqname] = dqsrc self.fv.make_callback('add-image', chname, dqsrc) # Use displayed image else: dqname = image.metadata['name'] dqsrc = image data = dqsrc.get_data() if data.ndim != self._ndim: self.logger.error('Expected ndim={0} but data has ' 'ndim={1}'.format(self._ndim, data.ndim)) return True # Get cached DQ parser first, if available if instrument in self._dqparser: self.logger.debug( 'Using cached DQ parser for {0}'.format(instrument)) dqparser = self._dqparser[instrument] # Create new parser and cache it. # Look in package data first. If not found, assume external data. # If no data file provided, use default. else: self.logger.debug( 'Creating new DQ parser for {0}'.format(instrument)) if instrument in self.dqdict: dqfile = get_pkg_data_filename(self.dqdict[instrument]) if dqfile: self.logger.info('Using package data {0}'.format(dqfile)) elif os.path.isfile(self.dqdict[instrument]): dqfile = self.dqdict[instrument] self.logger.info('Using external data {0}'.format(dqfile)) else: dqfile = _def_tab self.logger.warn( '{0} not found for {1}, using default'.format( self.dqdict[instrument], instrument)) else: dqfile = _def_tab self.logger.warn( '{0} is not supported, using default'.format(instrument)) dqparser = DQParser(dqfile) self._dqparser[instrument] = dqparser # Get cached results first, if available if self._cache_key in dqsrc.metadata: self.logger.debug('Using cached DQ results for {0}'.format(dqname)) pixmask_by_flag = dqsrc.get(self._cache_key) # Interpret DQ flags for all pixels. # Cache {flag: np_index} else: self.logger.debug('Interpreting all DQs for {0}...'.format(dqname)) pixmask_by_flag = dqparser.interpret_array(data) dqsrc.metadata[self._cache_key] = pixmask_by_flag # Parse DQ into individual flag definitions pixval = data[int(self.ycen), int(self.xcen)] dqs = dqparser.interpret_dqval(pixval) self.w.dq.set_text(str(pixval)) for row in dqs: item = QtGui.QListWidgetItem('{0:<5d}\t{1}'.format( row[dqparser._dqcol], row[self.dqstr])) self.pxdqlist.addItem(item) # No need to do the rest if image has not changed if pixmask_by_flag is self._curpxmask: return True # Populate a list of all valid DQ flags for that image. # Only list DQ flags present anywhere in the image. self.imdqlist.clear() self.w.npix.set_text(self._no_keyword) self._curpxmask = pixmask_by_flag self._curshape = data.shape for key in sorted(self._curpxmask): if len(self._curpxmask[key][0]) == 0: continue row = dqparser.tab[dqparser.tab[dqparser._dqcol] == key] item = QtGui.QListWidgetItem('{0:<5d}\t{1}'.format( row[dqparser._dqcol][0], row[self.dqstr][0])) self.imdqlist.addItem(item) return True
def __init__(self, logger): super(FitsViewer, self).__init__() self.logger = logger self.drawcolors = colors.get_colors() self.dc = get_canvas_types() fi = CanvasView(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.enable_draw(False) fi.set_callback('drag-drop', self.drop_file_cb) fi.set_callback('none-move', self.cursor_cb) fi.ui_set_active(True) self.fitsimage = fi # quick hack to get 'u' to invoke hidden camera mode bm = fi.get_bindmap() bm.mode_map['u'] = bm.mode_map['mode_camera'] bd = fi.get_bindings() bd.enable_all(True) # canvas that we will draw on canvas = self.dc.DrawingCanvas() canvas.enable_draw(True) canvas.set_drawtype('rectangle', color='lightblue') canvas.set_surface(fi) self.canvas = canvas # add canvas to view #fi.add(canvas) private_canvas = fi.get_canvas() private_canvas.register_for_cursor_drawing(fi) private_canvas.add(canvas) canvas.ui_set_active(True) self.drawtypes = canvas.get_drawtypes() self.drawtypes.sort() # add a color bar #fi.show_color_bar(True) #fi.show_focus_indicator(True) # add little mode indicator that shows keyboard modal states #fi.show_mode_indicator(True, corner='ur') 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() for name in self.drawtypes: wdrawtype.addItem(name) index = self.drawtypes.index('rectangle') wdrawtype.setCurrentIndex(index) wdrawtype.activated.connect(self.set_drawparams) self.wdrawtype = wdrawtype wdrawcolor = QtGui.QComboBox() for name in self.drawcolors: wdrawcolor.addItem(name) index = self.drawcolors.index('lightblue') wdrawcolor.setCurrentIndex(index) wdrawcolor.activated.connect(self.set_drawparams) self.wdrawcolor = wdrawcolor wfill = QtGui.QCheckBox("Fill") wfill.stateChanged.connect(self.set_drawparams) self.wfill = wfill walpha = QtGui.QDoubleSpinBox() walpha.setRange(0.0, 1.0) walpha.setSingleStep(0.1) walpha.setValue(1.0) walpha.valueChanged.connect(self.set_drawparams) self.walpha = walpha wclear = QtGui.QPushButton("Clear Canvas") wclear.clicked.connect(self.clear_canvas) wopen = QtGui.QPushButton("Open File") wopen.clicked.connect(self.open_file) wquit = QtGui.QPushButton("Quit") wquit.clicked.connect(self.quit) hbox.addStretch(1) for w in (wopen, wdrawtype, wdrawcolor, wfill, QtGui.QLabel('Alpha:'), walpha, 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)
def add_operation(self, title): opmenu = self.w.operation item = QtGui.QAction(title, opmenu) item.triggered.connect(lambda: self.start_operation_cb(title)) opmenu.addAction(item) self.operations.append(title)
def build_toplevel(self): self.font = self.getFont('fixedFont', 12) self.font11 = self.getFont('fixedFont', 11) self.font14 = self.getFont('fixedFont', 14) self.font18 = self.getFont('fixedFont', 18) self.w.tooltips = None QtGui.QToolTip.setFont(self.font11) self.ds = QtHelp.Desktop() self.ds.make_desktop(self.layout, widgetDict=self.w) # TEMP: FIX ME! self.gpmon.ds = self.ds for root in self.ds.toplevels: # add delete/destroy callbacks ## root.connect(root, QtCore.SIGNAL('closeEvent()'), ## self.quit) #root.setApp(self) root.setWindowTitle("Ginga") self.ds.add_callback('all-closed', self.quit) self.w.root = root self.w.fscreen = None menuholder = self.w['menu'] self.w.menubar = self.add_menus(menuholder) # Create main (center) FITS image pane self.w.vbox = self.w['main'].layout() self.w.vbox.setSpacing(0) #self.w.mnb = self.ds.make_ws(name='main', group=1, wstype='grid').nb ## self.w.mnb.subWindowActivated.connect(self.page_switch_mdi_cb) #self.w.mnb = self.ds.make_ws(name='main', group=1).nb self.w.mnb = self.w['channels'] self.w.mnb.currentChanged.connect(self.page_switch_cb) # readout if self.settings.get('shareReadout', True): self.readout = self.build_readout() self.add_callback('field-info', self.readout_cb, self.readout, None) rw = self.readout.get_widget() self.w.vbox.addWidget(rw, stretch=0) # bottom buttons plw = QtGui.QWidget() hbox = QtGui.QHBoxLayout() hbox.setContentsMargins(0, 0, 0, 0) hbox.setSpacing(2) plw.setLayout(hbox) cbox1 = QtHelp.ComboBox() self.w.channel = cbox1 cbox1.setToolTip("Select a channel") cbox1.activated.connect(self.channel_select_cb) hbox.addWidget(cbox1, stretch=0) opmenu = QtGui.QMenu() self.w.operation = opmenu btn = QtGui.QPushButton("Operation") btn.clicked.connect(self.invoke_op_cb) btn.setToolTip("Invoke operation") self.w.opbtn = btn hbox.addWidget(btn, stretch=0) w = QtGui.QWidget() self.w.optray = QtGui.QHBoxLayout() self.w.optray.setContentsMargins(0, 0, 0, 0) self.w.optray.setSpacing(2) w.setLayout(self.w.optray) hbox.addWidget(w, stretch=1, alignment=QtCore.Qt.AlignLeft) self.w.vbox.addWidget(plw, stretch=0) # Add colormap bar cbar = self.build_colorbar() self.w.vbox.addWidget(cbar, stretch=0) self.add_dialogs() statusholder = self.w['status'] self.add_statusbar(statusholder) self.w.root.show()
def add_plugin_menu(self, name): item = QtGui.QAction("Start %s" % (name), self.w.menubar) item.triggered.connect(lambda: self.start_global_plugin(name)) self.w.menu_plug.addAction(item)
def add_statusbar(self, holder): self.w.status = QtGui.QStatusBar() holder.layout().addWidget(self.w.status, stretch=1)
def add_dialogs(self): filesel = QtGui.QFileDialog(self.w.root) filesel.setFileMode(QtGui.QFileDialog.ExistingFile) filesel.setViewMode(QtGui.QFileDialog.Detail) self.filesel = filesel
def add_menus(self, holder): menubar = QtGui.QMenuBar() # NOTE: Special hack for Mac OS X, otherwise the menus # do not get added to the global OS X menu macos_ver = platform.mac_ver()[0] if len(macos_ver) > 0: self.w['top'].layout().addWidget(menubar, stretch=0) else: holder.layout().addWidget(menubar, stretch=1) # create a File pulldown menu, and add it to the menu bar filemenu = menubar.addMenu("File") item = QtGui.QAction("Load Image", menubar) item.triggered.connect(self.gui_load_file) filemenu.addAction(item) sep = QtGui.QAction(menubar) sep.setSeparator(True) filemenu.addAction(sep) item = QtGui.QAction("Quit", menubar) item.triggered.connect(self.windowClose) filemenu.addAction(item) # create a Channel pulldown menu, and add it to the menu bar chmenu = menubar.addMenu("Channel") item = QtGui.QAction("Add Channel", menubar) item.triggered.connect(self.gui_add_channel) chmenu.addAction(item) item = QtGui.QAction("Add Channels", menubar) item.triggered.connect(self.gui_add_channels) chmenu.addAction(item) item = QtGui.QAction("Delete Channel", menubar) item.triggered.connect(self.gui_delete_channel) chmenu.addAction(item) # create a Window pulldown menu, and add it to the menu bar winmenu = menubar.addMenu("Workspace") item = QtGui.QAction("Add Workspace", menubar) item.triggered.connect(self.gui_add_ws) winmenu.addAction(item) # # create a Option pulldown menu, and add it to the menu bar # optionmenu = menubar.addMenu("Option") ## # create a Workspace pulldown menu, and add it to the menu bar ## wsmenu = menubar.addMenu("Workspace") ## item = QtGui.QAction("Panes as Tabs", menubar) ## item.triggered.connect(self.tabstoggle_cb) ## item.setCheckable(True) ## # TODO: check the state of the workspace first ## item.setChecked(True) ## wsmenu.addAction(item) ## item = QtGui.QAction("Tile Panes", menubar) ## item.triggered.connect(self.tile_panes_cb) ## wsmenu.addAction(item) ## item = QtGui.QAction("Cascade Panes", menubar) ## item.triggered.connect(self.cascade_panes_cb) ## wsmenu.addAction(item) # create a Plugins pulldown menu, and add it to the menu bar plugmenu = menubar.addMenu("Plugins") self.w.menu_plug = plugmenu # create a Help pulldown menu, and add it to the menu bar helpmenu = menubar.addMenu("Help") item = QtGui.QAction("About", menubar) item.triggered.connect(lambda: self.banner(raiseTab=True)) helpmenu.addAction(item) item = QtGui.QAction("Documentation", menubar) item.triggered.connect(lambda: self.help()) helpmenu.addAction(item) return menubar
def build_gui(self, container): sw = QtGui.QScrollArea() twidget = QtHelp.VBox() sp = QtGui.QSizePolicy(QtGui.QSizePolicy.MinimumExpanding, QtGui.QSizePolicy.Fixed) twidget.setSizePolicy(sp) vbox1 = twidget.layout() vbox1.setContentsMargins(4, 4, 4, 4) vbox1.setSpacing(2) sw.setWidgetResizable(True) sw.setWidget(twidget) msgFont = QtGui.QFont("Sans", 14) tw = QtGui.QLabel() tw.setFont(msgFont) tw.setWordWrap(True) self.tw = tw fr = QtHelp.Frame("Instructions") fr.layout().addWidget(tw, stretch=1, alignment=QtCore.Qt.AlignTop) vbox1.addWidget(fr, stretch=0, alignment=QtCore.Qt.AlignTop) fr = QtHelp.Frame("Drawing") captions = (('Draw type', 'combobox'), ('Draw color', 'combobox'), ('Clear canvas', 'button')) w, b = QtHelp.build_info(captions) self.w = b combobox = b.draw_type options = [] index = 0 for name in self.drawtypes: options.append(name) combobox.addItem(name) index += 1 index = self.drawtypes.index(default_drawtype) combobox.setCurrentIndex(index) combobox.activated.connect(self.set_drawparams) self.w.draw_color = b.draw_color combobox = b.draw_color options = [] index = 0 self.drawcolors = draw_colors for name in self.drawcolors: options.append(name) combobox.addItem(name) index += 1 index = self.drawcolors.index(default_drawcolor) combobox.setCurrentIndex(index) combobox.activated.connect(self.set_drawparams) b.clear_canvas.clicked.connect(self.clear_canvas) fr.layout().addWidget(w, stretch=1, alignment=QtCore.Qt.AlignLeft) vbox1.addWidget(fr, stretch=0, alignment=QtCore.Qt.AlignTop) btns = QtHelp.HBox() layout = btns.layout() layout.setSpacing(3) btn = QtGui.QPushButton("Close") btn.clicked.connect(self.close) layout.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignLeft) vbox1.addWidget(btns, stretch=0, alignment=QtCore.Qt.AlignLeft) container.addWidget(sw, stretch=1)
def __init__(self): super(ScrollArea, self).__init__() self.widget = QtGui.QScrollArea() self.widget.setWidgetResizable(True)
def build_gui(self, container, future=None): vbox1 = QtHelp.VBox() msgFont = self.fv.getFont("sansFont", 14) tw = QtGui.QLabel() tw.setFont(msgFont) tw.setWordWrap(True) self.tw = tw fr = QtHelp.Frame("Instructions") fr.addWidget(tw, stretch=1, alignment=QtCore.Qt.AlignTop) vbox1.addWidget(fr, stretch=0, alignment=QtCore.Qt.AlignTop) nb = QtHelp.TabWidget() nb.setTabPosition(QtGui.QTabWidget.South) nb.setUsesScrollButtons(True) self.w.nb = nb #vbox1.addWidget(nb, stretch=1, alignment=QtCore.Qt.AlignTop) vbox1.addWidget(nb, stretch=1) vbox0 = QtHelp.VBox() hbox = QtHelp.HBox() hbox.setSpacing(4) vbox0.addWidget(hbox, stretch=1, alignment=QtCore.Qt.AlignTop) vbox = QtHelp.VBox() fr = QtHelp.Frame(" Image Server ") fr.addWidget(vbox, stretch=1, alignment=QtCore.Qt.AlignTop) hbox.addWidget(fr, stretch=0, alignment=QtCore.Qt.AlignLeft) captions = (('Server', 'xlabel'), ('@Server', 'combobox'), ('Use DSS channel', 'checkbutton'), ('Get Image', 'button')) w, b = QtHelp.build_info(captions) self.w.update(b) self.w.get_image.clicked.connect(self.getimage_cb) self.w.use_dss_channel.setChecked(self.use_dss_channel) self.w.use_dss_channel.stateChanged.connect(self.use_dss_channel_cb) vbox.addWidget(w, stretch=0, alignment=QtCore.Qt.AlignTop) self.w.img_params = QtHelp.StackedWidget() vbox.addWidget(self.w.img_params, stretch=1, alignment=QtCore.Qt.AlignTop) combobox = self.w.server index = 0 self.image_server_options = self.fv.imgsrv.getServerNames(kind='image') for name in self.image_server_options: combobox.addItem(name) index += 1 index = 0 combobox.setCurrentIndex(index) combobox.activated.connect(self.setup_params_image) if len(self.image_server_options) > 0: self.setup_params_image(index, redo=False) vbox = QtHelp.VBox() fr = QtHelp.Frame(" Catalog Server ") fr.addWidget(vbox, stretch=1, alignment=QtCore.Qt.AlignTop) hbox.addWidget(fr, stretch=0, alignment=QtCore.Qt.AlignLeft) captions = (('Server', 'xlabel'), ('@Server', 'combobox'), ('Limit stars to area', 'checkbutton'), ('Search', 'button')) w, self.w2 = QtHelp.build_info(captions) self.w2.search.clicked.connect(self.getcatalog_cb) self.w2.limit_stars_to_area.setChecked(self.limit_stars_to_area) self.w2.limit_stars_to_area.stateChanged.connect(self.limit_area_cb) vbox.addWidget(w, stretch=0, alignment=QtCore.Qt.AlignTop) self.w2.cat_params = QtHelp.StackedWidget() vbox.addWidget(self.w2.cat_params, stretch=1, alignment=QtCore.Qt.AlignTop) combobox = self.w2.server index = 0 self.catalog_server_options = self.fv.imgsrv.getServerNames( kind='catalog') for name in self.catalog_server_options: combobox.addItem(name) index += 1 index = 0 combobox.setCurrentIndex(index) combobox.activated.connect(self.setup_params_catalog) if len(self.catalog_server_options) > 0: self.setup_params_catalog(index, redo=False) btns = QtHelp.HBox() btns.setSpacing(5) btn = QtGui.QRadioButton("Rectangle") if self.drawtype == 'rectangle': btn.setChecked(True) btn.toggled.connect(lambda tf: self.set_drawtype_cb(tf, 'rectangle')) btns.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignLeft) btn = QtGui.QRadioButton("Circle") if self.drawtype == 'circle': btn.setChecked(True) btn.toggled.connect(lambda tf: self.set_drawtype_cb(tf, 'circle')) btns.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignLeft) btn = QtGui.QPushButton("Entire image") btn.clicked.connect(self.setfromimage) btns.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignLeft) vbox0.addWidget(btns, stretch=0, alignment=QtCore.Qt.AlignTop) self.w.params = vbox0 sw = QtGui.QScrollArea() sw.setWidgetResizable(True) sw.setWidget(vbox0) nb.addTab(sw, "Params") vbox = QtHelp.VBox() self.table = CatalogListing(self.logger, vbox) hbox = QtHelp.HBox() adj = QtGui.QScrollBar(QtCore.Qt.Horizontal) adj.setRange(0, 1000) adj.setSingleStep(1) adj.setPageStep(10) #adj.setMaximum(1000) adj.setValue(0) #adj.resize(200, -1) adj.setTracking(True) adj.setToolTip("Choose subset of stars plotted") self.w.plotgrp = adj adj.valueChanged.connect(self.plot_pct_cb) hbox.addWidget(adj, stretch=1) sb = QtGui.QSpinBox() sb.setRange(10, self.plot_max) sb.setValue(self.plot_limit) sb.setSingleStep(10) adj.setPageStep(100) sb.setWrapping(False) self.w.plotnum = sb sb.setToolTip("Adjust size of subset of stars plotted") sb.valueChanged.connect(self.plot_limit_cb) hbox.addWidget(sb, stretch=0) vbox.addWidget(hbox, stretch=0) self.w.listing = vbox nb.addTab(vbox, "Listing") btns = QtHelp.HBox() btns.setSpacing(3) #btns.set_child_size(15, -1) self.w.buttons = btns btn = QtGui.QPushButton("Close") btn.clicked.connect(self.close) btns.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignLeft) if future: btn = QtGui.QPushButton('Ok') btn.clicked.connect(lambda w: self.ok()) btns.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignLeft) btn = QtGui.QPushButton('Cancel') btn.clicked.connect(lambda w: self.cancel()) btns.addWidget(btn, stretch=0, alignment=QtCore.Qt.AlignLeft) vbox1.addWidget(btns, stretch=0) cw = container.get_widget() cw.addWidget(vbox1, stretch=1)
def build_gui(self, container): top = Widgets.VBox() top.set_border_width(4) vbox, sw, orientation = Widgets.get_oriented_box(container) vbox.set_border_width(4) vbox.set_spacing(2) msgFont = self.fv.getFont('sansFont', 12) tw = Widgets.TextArea(wrap=True, editable=False) tw.set_font(msgFont) self.tw = tw fr = Widgets.Frame('Instructions') vbox2 = Widgets.VBox() vbox2.add_widget(tw) vbox2.add_widget(Widgets.Label(''), stretch=1) fr.set_widget(vbox2) vbox.add_widget(fr, stretch=0) fr = Widgets.Frame('Single Pixel') captions = [('X:', 'label', 'X', 'entry'), ('Y:', 'label', 'Y', 'entry'), ('DQ Flag:', 'label', 'DQ', 'llabel')] w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) b.x.set_tooltip('X of pixel') b.x.set_text(str(self.xcen)) b.x.widget.editingFinished.connect(self.set_xcen) b.y.set_tooltip('Y of pixel') b.y.set_text(str(self.ycen)) b.y.widget.editingFinished.connect(self.set_ycen) b.dq.set_tooltip('DQ value of pixel') b.dq.set_text(self._no_keyword) b.dq.widget.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) self.pxdqlist = QtGui.QListWidget() splitter = Widgets.Splitter('vertical') splitter.add_widget(w) splitter.widget.addWidget(self.pxdqlist) fr.set_widget(splitter) vbox.add_widget(fr, stretch=1) fr = Widgets.Frame('Whole Image') captions = [('Number of pixels:', 'llabel', 'npix', 'llabel', 'spacer1', 'spacer')] w, b = Widgets.build_info(captions, orientation=orientation) self.w.update(b) b.npix.set_tooltip('Number of affected pixels') b.npix.set_text(self._no_keyword) b.npix.widget.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) self.imdqlist = QtGui.QListWidget() self.imdqlist.setSelectionMode( QtGui.QAbstractItemView.ExtendedSelection) self.imdqlist.itemSelectionChanged.connect(self.mark_dqs) splitter = Widgets.Splitter('vertical') splitter.add_widget(w) splitter.widget.addWidget(self.imdqlist) fr.set_widget(splitter) vbox.add_widget(fr, stretch=1) top.add_widget(sw, stretch=1) btns = Widgets.HBox() btns.set_border_width(4) btns.set_spacing(3) btn = Widgets.Button('Close') btn.add_callback('activated', lambda w: self.close()) btns.add_widget(btn, stretch=0) btns.add_widget(Widgets.Label(''), stretch=1) top.add_widget(btns, stretch=0) container.add_widget(top, stretch=1) self.gui_up = True # Populate fields based on active image self.redo()
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('gray') 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 self.drawcolors = ['white', 'black', 'red', 'yellow', 'blue', 'green'] fi = FitsImageCanvas(logger, render='widget') fi.enable_autocuts('on') fi.enable_zoom('on') fi.enable_cuts(True) fi.enable_flip(True) fi.enable_rotate(True) fi.enable_draw(True) fi.set_drawtype('ruler') fi.set_drawcolor('blue') fi.set_callback('drag-drop', self.drop_file) fi.set_callback('motion', self.motion) fi.set_bg(0.2, 0.2, 0.2) fi.ui_setActive(True) self.fitsimage = fi 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)
import sys from ginga.qtw.QtHelp import QtGui, QtCore from ginga.qtw import ColorBar from ginga import cmap, imap import logging if __name__ == "__main__": 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): nb = QtGui.QStackedWidget() self.nb = nb container.addWidget(self.nb, stretch=1)
def __init__(self, logger): super(FitsViewer, self).__init__() self.logger = logger self.drawcolors = colors.get_colors() fig = Figure() w = FigureCanvas(fig) fi = ImageViewCanvas(logger=logger) 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_cb) fi.set_callback('cursor-changed', self.cursor_cb) fi.set_bg(0.2, 0.2, 0.2) fi.ui_set_active(True) self.fitsimage = fi fi.set_figure(fig) bd = fi.get_bindings() bd.enable_all(True) # canvas that we will draw on DrawingCanvas = fi.getDrawClass('drawingcanvas') canvas = DrawingCanvas() canvas.enable_draw(True) #canvas.enable_edit(True) canvas.set_drawtype('rectangle', color='lightblue') canvas.set_surface(fi) self.canvas = canvas # add canvas to view fi.add(canvas) canvas.ui_set_active(True) 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('rectangle') wdrawtype.setCurrentIndex(index) wdrawtype.activated.connect(self.set_drawparams) self.wdrawtype = wdrawtype wdrawcolor = QtGui.QComboBox() for name in self.drawcolors: wdrawcolor.addItem(name) index = self.drawcolors.index('lightblue') wdrawcolor.setCurrentIndex(index) wdrawcolor.activated.connect(self.set_drawparams) self.wdrawcolor = wdrawcolor wfill = QtGui.QCheckBox("Fill") wfill.stateChanged.connect(self.set_drawparams) self.wfill = wfill walpha = QtGui.QDoubleSpinBox() walpha.setRange(0.0, 1.0) walpha.setSingleStep(0.1) walpha.setValue(1.0) walpha.valueChanged.connect(self.set_drawparams) self.walpha = walpha wclear = QtGui.QPushButton("Clear Canvas") wclear.clicked.connect(self.clear_canvas) wopen = QtGui.QPushButton("Open File") wopen.clicked.connect(self.open_file) wquit = QtGui.QPushButton("Quit") wquit.clicked.connect(self.close) hbox.addStretch(1) for w in (wopen, wdrawtype, wdrawcolor, wfill, QtGui.QLabel('Alpha:'), walpha, 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)
def setup_cr(self): cr = QtGui.QPainter(self.pixmap) pen = QtGui.QPen() pen.setWidth(1) cr.setPen(pen) return cr
def __init__(self, logger): super(FitsViewer, self).__init__() self.logger = logger self.drawcolors = colors.get_colors() self.dc = get_canvas_types() #fi = ImageViewCanvas(logger, render='widget') fi = CanvasView(logger, render='widget') 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.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 bd = fi.get_bindings() bd.enable_all(True) # canvas that we will draw on canvas = self.dc.DrawingCanvas() canvas.enable_draw(True) canvas.set_drawtype('rectangle', color='lightblue') canvas.set_surface(fi) self.canvas = canvas # add canvas to view #fi.add(canvas) private_canvas = fi.get_canvas() private_canvas.add(canvas) canvas.ui_setActive(True) self.drawtypes = canvas.get_drawtypes() self.drawtypes.sort() # add a color bar private_canvas.add(self.dc.ColorBar(side='bottom', offset=10)) # add little mode indicator that shows modal states in # the corner private_canvas.add(self.dc.ModeIndicator(corner='ur')) # 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)) 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() for name in self.drawtypes: wdrawtype.addItem(name) index = self.drawtypes.index('rectangle') wdrawtype.setCurrentIndex(index) wdrawtype.activated.connect(self.set_drawparams) self.wdrawtype = wdrawtype wdrawcolor = QtGui.QComboBox() for name in self.drawcolors: wdrawcolor.addItem(name) index = self.drawcolors.index('lightblue') wdrawcolor.setCurrentIndex(index) wdrawcolor.activated.connect(self.set_drawparams) self.wdrawcolor = wdrawcolor wfill = QtGui.QCheckBox("Fill") wfill.stateChanged.connect(self.set_drawparams) self.wfill = wfill walpha = QtGui.QDoubleSpinBox() walpha.setRange(0.0, 1.0) walpha.setSingleStep(0.1) walpha.setValue(1.0) walpha.valueChanged.connect(self.set_drawparams) self.walpha = walpha wclear = QtGui.QPushButton("Clear Canvas") wclear.clicked.connect(self.clear_canvas) wopen = QtGui.QPushButton("Open File") wopen.clicked.connect(self.open_file) wquit = QtGui.QPushButton("Quit") wquit.clicked.connect(self.quit) hbox.addStretch(1) for w in (wopen, wdrawtype, wdrawcolor, wfill, QtGui.QLabel('Alpha:'), walpha, 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)
def __init__(self, logger): super(FitsViewer, self).__init__() self.logger = logger self.drawcolors = colors.get_colors() self.dc = get_canvas_types() self.set_medfilt(0) self.set_c2c(0) # create the ginga viewer and configure it fi = CanvasView(self.logger, render='widget') fi.enable_autocuts('on') fi.set_autocut_params('zscale') fi.enable_autozoom('on') fi.set_callback('drag-drop', self.drop_file) fi.add_callback('cursor-changed', self.cursor_cb) fi.add_callback('cursor-down', self.click_cb) fi.set_bg(0.2, 0.2, 0.2) fi.ui_set_active(True) self.fitsimage = fi # enable some user interaction bd = fi.get_bindings() bd.enable_all(True) # canvas that we will draw on canvas = self.dc.DrawingCanvas() # canvas.enable_draw(True) # canvas.enable_edit(True) # canvas.set_drawtype('circle', color='lightblue') canvas.set_surface(fi) self.canvas = canvas # add canvas to view #fi.add(canvas) private_canvas = fi.get_canvas() private_canvas.add(canvas) # canvas.register_for_cursor_drawing(fi) # canvas.add_callback('draw-event', self.draw_cb) # canvas.set_draw_mode('draw') canvas.ui_set_active(True) self.drawtypes = canvas.get_drawtypes() self.drawtypes.sort() w = fi.get_widget() w.resize(1000, 1000) # --------------------------------------------------------------------- # add scrollbar interface around this viewer si = ScrolledView(fi) vbox = QtGui.QVBoxLayout() vbox.setContentsMargins(QtCore.QMargins(2, 2, 2, 2)) vbox.setSpacing(1) vbox.addWidget(si, stretch=1) # --------------------------------------------------------------------- # add live cursor readout self.readout = QtGui.QLabel("") vbox.addWidget(self.readout, stretch=0, alignment=QtCore.Qt.AlignCenter) # --------------------------------------------------------------------- # add row of interface widgets hbox = QtGui.QHBoxLayout() hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2)) wzoomfit = QtGui.QPushButton("Z0") wzoomfit.clicked.connect(self.zoom_fit) wzoomin = QtGui.QPushButton("Z+") wzoomin.clicked.connect(self.zoom_in) wzoomout = QtGui.QPushButton("Z-") wzoomout.clicked.connect(self.zoom_out) wc2c = QtGui.QCheckBox("Click to Center") wc2c.stateChanged.connect(self.set_c2c) self.wc2c = wc2c wsolve = QtGui.QPushButton("Solve") wsolve.clicked.connect(self.solve_astrometry) woverlay = QtGui.QPushButton("Overlay Catalog") woverlay.clicked.connect(self.overlay_catalog) wclear = QtGui.QPushButton("Clear Overlays") wclear.clicked.connect(self.clear_overlays) wmedfilt = QtGui.QCheckBox("Median Filter") wmedfilt.stateChanged.connect(self.set_medfilt) self.wmedfilt = wmedfilt wopen = QtGui.QPushButton("Open File") wopen.clicked.connect(self.open_file) wquit = QtGui.QPushButton("Quit") wquit.clicked.connect(self.quit) hbox.addStretch(1) hbox.addWidget(wzoomfit, stretch=0) hbox.addWidget(wzoomin, stretch=0) hbox.addWidget(wzoomout, stretch=0) hbox.addWidget(wc2c, stretch=0) # hbox.addWidget(wsolve, stretch=0) hbox.addWidget(woverlay, stretch=0) hbox.addWidget(wclear, stretch=0) hbox.addWidget(wmedfilt, stretch=0) # hbox.addWidget(wopen, stretch=0) hbox.addWidget(wquit, stretch=0) # --------------------------------------------------------------------- hw = QtGui.QWidget() hw.setLayout(hbox) vbox.addWidget(hw, stretch=0) vw = QtGui.QWidget() self.setCentralWidget(vw) vw.setLayout(vbox)
def __init__(self, logger): super(FitsViewer, self).__init__() self.logger = logger self.drawcolors = colors.get_colors() self.dc = get_canvas_types() fi = CanvasView(logger, render='widget') 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.enable_draw(False) fi.add_callback('drag-drop', self.drop_file_cb) fi.add_callback('cursor-changed', self.cursor_cb) fi.set_bg(0.2, 0.2, 0.2) fi.ui_set_active(True) self.fitsimage = fi bd = fi.get_bindings() bd.enable_all(True) # 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.set_surface(fi) self.canvas = canvas # add canvas to view #fi.add(canvas) private_canvas = fi.get_canvas() private_canvas.add(canvas) canvas.register_for_cursor_drawing(fi) canvas.add_callback('draw-event', self.draw_cb) canvas.set_draw_mode('draw') canvas.ui_set_active(True) self.drawtypes = canvas.get_drawtypes() self.drawtypes.sort() # add a color bar #fi.show_color_bar(True) fi.show_focus_indicator(True) # add little mode indicator that shows keyboard modal states fi.show_mode_indicator(True, corner='ur') 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() for name in self.drawtypes: wdrawtype.addItem(name) index = self.drawtypes.index('rectangle') wdrawtype.setCurrentIndex(index) wdrawtype.activated.connect(self.set_drawparams) self.wdrawtype = wdrawtype wdrawcolor = QtGui.QComboBox() for name in self.drawcolors: wdrawcolor.addItem(name) index = self.drawcolors.index('lightblue') wdrawcolor.setCurrentIndex(index) wdrawcolor.activated.connect(self.set_drawparams) self.wdrawcolor = wdrawcolor wfill = QtGui.QCheckBox("Fill") wfill.stateChanged.connect(self.set_drawparams) self.wfill = wfill walpha = QtGui.QDoubleSpinBox() walpha.setRange(0.0, 1.0) walpha.setSingleStep(0.1) walpha.setValue(1.0) walpha.valueChanged.connect(self.set_drawparams) self.walpha = walpha wclear = QtGui.QPushButton("Clear Canvas") wclear.clicked.connect(self.clear_canvas) wopen = QtGui.QPushButton("Open File") wopen.clicked.connect(self.open_file) wquit = QtGui.QPushButton("Quit") wquit.clicked.connect(self.quit) hbox.addStretch(1) for w in (wopen, wdrawtype, wdrawcolor, wfill, QtGui.QLabel('Alpha:'), walpha, wclear, wquit): hbox.addWidget(w, stretch=0) hw = QtGui.QWidget() hw.setLayout(hbox) vbox.addWidget(hw, stretch=0) mode = self.canvas.get_draw_mode() hbox = QtGui.QHBoxLayout() hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2)) btn1 = QtGui.QRadioButton("Draw") btn1.setChecked(mode == 'draw') btn1.toggled.connect(lambda val: self.set_mode_cb('draw', val)) btn1.setToolTip("Choose this to draw on the canvas") hbox.addWidget(btn1) btn2 = QtGui.QRadioButton("Edit") btn2.setChecked(mode == 'edit') btn2.toggled.connect(lambda val: self.set_mode_cb('edit', val)) btn2.setToolTip("Choose this to edit things on the canvas") hbox.addWidget(btn2) btn3 = QtGui.QRadioButton("Pick") btn3.setChecked(mode == 'pick') btn3.toggled.connect(lambda val: self.set_mode_cb('pick', val)) btn3.setToolTip("Choose this to pick things on the canvas") hbox.addWidget(btn3) hbox.addWidget(QtGui.QLabel(''), stretch=1) hw = QtGui.QWidget() hw.setLayout(hbox) vbox.addWidget(hw, stretch=0) vw = QtGui.QWidget() self.setCentralWidget(vw) vw.setLayout(vbox)
def _get_color(self, r, g, b): n = 255.0 clr = QtGui.QColor(int(r * n), int(g * n), int(b * n)) return clr
def __init__(self, text=''): super(Label, self).__init__() self.widget = QtGui.QLabel(text)
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_cb) fi.set_callback('cursor-changed', self.cursor_cb) fi.set_bg(0.2, 0.2, 0.2) fi.ui_set_active(True) self.fitsimage = fi fi.show_color_bar(True) # 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') # 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() 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 start(kapp): global app_ref if use_null_logger: logger = log.NullLogger() else: logger = logging.getLogger("ipg") logger.setLevel(logging.INFO) fmt = logging.Formatter(STD_FORMAT) stderrHdlr = logging.StreamHandler() stderrHdlr.setFormatter(fmt) logger.addHandler(stderrHdlr) fileHdlr = logging.FileHandler("ipg.log") fileHdlr.setFormatter(fmt) logger.addHandler(fileHdlr) kapp.logger = logger # Get settings (preferences) basedir = paths.ginga_home if not os.path.exists(basedir): try: os.mkdir(basedir) except OSError as e: logger.warning("Couldn't create ginga settings area (%s): %s" % (basedir, str(e))) logger.warning("Preferences will not be able to be saved") # Set up preferences prefs = Settings.Preferences(basefolder=basedir, logger=logger) settings = prefs.createCategory('general') settings.load(onError='silent') settings.setDefaults(useMatplotlibColormaps=False) bindprefs = prefs.createCategory('bindings') bindprefs.load(onError='silent') # So we can find our plugins sys.path.insert(0, basedir) moduleHome = os.path.split(sys.modules['ginga.version'].__file__)[0] childDir = os.path.join(moduleHome, 'misc', 'plugins') sys.path.insert(0, childDir) childDir = os.path.join(basedir, 'plugins') sys.path.insert(0, childDir) # User configuration (custom star catalogs, etc.) try: import ipg_config ipg_config.pre_gui_config(kapp) except Exception as e: try: (type, value, tb) = sys.exc_info() tb_str = "\n".join(traceback.format_tb(tb)) except Exception: tb_str = "Traceback information unavailable." logger.error("Error importing Ginga config file: %s" % (str(e))) logger.error("Traceback:\n%s" % (tb_str)) # create Qt app # Note: workaround for pyside bug where QApplication is not deleted app = QtGui.QApplication.instance() if not app: app = QtGui.QApplication([]) app.connect(app, QtCore.SIGNAL('lastWindowClosed()'), app, QtCore.SLOT('quit()')) # here is our little launcher w = StartMenu(logger, app, kapp, prefs) app_ref = w w.show() app.setActiveWindow(w) #app.exec_() # Very important, IPython-specific step: this gets GUI event loop # integration going, and it replaces calling app.exec_() kapp.start() return w