def main(options, args): QtGui.QApplication.setGraphicsSystem('raster') app = QtGui.QApplication(args) app.connect(app, QtCore.SIGNAL('lastWindowClosed()'), app, QtCore.SLOT('quit()')) logger = logging.getLogger("example2") logger.setLevel(options.loglevel) fmt = logging.Formatter(STD_FORMAT) if options.logfile: fileHdlr = logging.handlers.RotatingFileHandler(options.logfile) fileHdlr.setLevel(options.loglevel) fileHdlr.setFormatter(fmt) logger.addHandler(fileHdlr) if options.logstderr: stderrHdlr = logging.StreamHandler() stderrHdlr.setLevel(options.loglevel) stderrHdlr.setFormatter(fmt) logger.addHandler(stderrHdlr) w = FitsViewer(logger) w.resize(524, 540) w.show() app.setActiveWindow(w) if len(args) > 0: w.load_file(args[0]) app.exec_()
def __init__(self, logger): super(FitsViewer, self).__init__() self.logger = logger fi = FitsImageZoom(self.logger, render='widget') fi.enable_autocuts('on') fi.enable_zoom('on') fi.enable_cuts(True) fi.enable_flip(True) fi.enable_rotate(True) fi.set_callback('drag-drop', self.drop_file) 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) hbox = QtGui.QHBoxLayout() hbox.setContentsMargins(QtCore.QMargins(4, 2, 4, 2)) 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, 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 main(options, args): QtGui.QApplication.setGraphicsSystem('raster') app = QtGui.QApplication(args) app.connect(app, QtCore.SIGNAL('lastWindowClosed()'), app, QtCore.SLOT('quit()')) logger = log.get_logger(name="example2", options=options) w = FitsViewer(logger) w.resize(524, 540) w.show() app.setActiveWindow(w) w.raise_() w.activateWindow() if len(args) > 0: w.load_file(args[0]) app.exec_()
def main(options, args): app = QtGui.QApplication(sys.argv) app.connect(app, QtCore.SIGNAL('lastWindowClosed()'), app, QtCore.SLOT('quit()')) logger = logging.getLogger("example1") logger.setLevel(logging.INFO) fmt = logging.Formatter(STD_FORMAT) stderrHdlr = logging.StreamHandler() stderrHdlr.setFormatter(fmt) logger.addHandler(stderrHdlr) w = FitsViewer(logger) w.resize(524, 540) w.show() app.setActiveWindow(w) if len(args) > 0: w.load_file(args[0]) app.exec_()
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)
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