예제 #1
0
def pytest_configure(config):

    if config.getoption('no_optional_skip'):
        from glue.tests import helpers
        for attr in helpers.__dict__:
            if attr.startswith('requires_'):
                # The following line replaces the decorators with a function
                # that does noting, effectively disabling it.
                setattr(helpers, attr, lambda f: f)

    # Make sure we don't affect the real glue config dir
    import tempfile
    from glue import config
    config.CFG_DIR = tempfile.mkdtemp()

    # Start up QApplication, if the Qt code is present
    try:
        from glue.utils.qt import get_qapp
    except ImportError:
        pass
    else:
        get_qapp()

    # Force loading of plugins
    from glue.main import load_plugins
    load_plugins()
예제 #2
0
파일: conftest.py 프로젝트: sunn-e/glue
def pytest_configure(config):

    os.environ['GLUE_TESTING'] = 'True'

    if config.getoption('no_optional_skip'):
        from glue.tests import helpers
        for attr in helpers.__dict__:
            if attr.startswith('requires_'):
                # The following line replaces the decorators with a function
                # that does noting, effectively disabling it.
                setattr(helpers, attr, lambda f: f)

    # Make sure we don't affect the real glue config dir
    import tempfile
    from glue import config
    config.CFG_DIR = tempfile.mkdtemp()

    # Start up QApplication, if the Qt code is present
    try:
        from glue.utils.qt import get_qapp
    except Exception:
        # Note that we catch any exception, not just ImportError, because
        # QtPy can raise a PythonQtError.
        pass
    else:
        get_qapp()

    # Force loading of plugins
    from glue.main import load_plugins
    load_plugins()
예제 #3
0
파일: app.py 프로젝트: pllim/glue-jupyter
    def __init__(self, data_collection=None, session=None, settings=None):

        super(JupyterApplication,
              self).__init__(data_collection=data_collection, session=session)

        try:
            from glue.main import load_plugins
            load_plugins()
        except Exception:  # Compatibility with glue <0.16
            from glue.main import REQUIRED_PLUGINS
            REQUIRED_PLUGINS.clear()
            load_plugins()

        self.output = widgets.Output()
        self.widget_data_collection = widgets.SelectMultiple()
        self.widget_subset_select = SubsetSelect(session=self.session)
        self.widget_subset_mode = SelectionModeMenu(session=self.session)
        self.widget = widgets.VBox(
            children=[self.widget_subset_mode, self.output])

        self._settings['new_subset_on_selection_tool_change'] = [
            False, is_bool
        ]

        if settings is not None:
            for key, value in settings.items():
                self.set_setting(key, value)

        self._viewer_refs = []
예제 #4
0
파일: conftest.py 프로젝트: glue-viz/glue
def pytest_configure(config):

    os.environ['GLUE_TESTING'] = 'True'

    if config.getoption('no_optional_skip'):
        from glue.tests import helpers
        for attr in helpers.__dict__:
            if attr.startswith('requires_'):
                # The following line replaces the decorators with a function
                # that does noting, effectively disabling it.
                setattr(helpers, attr, lambda f: f)

    # Make sure we don't affect the real glue config dir
    import tempfile
    from glue import config
    config.CFG_DIR = tempfile.mkdtemp()

    # Start up QApplication, if the Qt code is present
    try:
        from glue.utils.qt import get_qapp
    except Exception:
        # Note that we catch any exception, not just ImportError, because
        # QtPy can raise a PythonQtError.
        pass
    else:
        get_qapp()

    # Force loading of plugins
    from glue.main import load_plugins
    load_plugins()
예제 #5
0
파일: conftest.py 프로젝트: bmorris3/glue
def pytest_configure(config):

    if config.getoption('no_optional_skip'):
        from glue.tests import helpers
        for attr in helpers.__dict__:
            if attr.startswith('requires_'):
                # The following line replaces the decorators with a function
                # that does noting, effectively disabling it.
                setattr(helpers, attr, lambda f: f)

    # Make sure we don't affect the real glue config dir
    import tempfile
    from glue import config
    config.CFG_DIR = tempfile.mkdtemp()

    # Start up QApplication, if the Qt code is present
    try:
        from glue.external.qt import get_qapp
    except ImportError:
        pass
    else:
        app = get_qapp()

    # Force loading of plugins
    from glue.main import load_plugins
    load_plugins()
예제 #6
0
    def __init__(self, data_collection=None, session=None):

        # At this point we need to check if a Qt application already exists -
        # this happens for example if using the %gui qt/qt5 mode in Jupyter. We
        # should keep a reference to the original icon so that we can restore it
        # later
        self._original_app = QtWidgets.QApplication.instance()
        if self._original_app is not None:
            self._original_icon = self._original_app.windowIcon()

        self._export_helper = ExportHelper(self)
        self._import_helper = ImportHelper(self)

        # Now we can get the application instance, which involves setting it
        # up if it doesn't already exist.
        self.app = get_qapp()

        QtWidgets.QMainWindow.__init__(self)
        Application.__init__(self,
                             data_collection=data_collection,
                             session=session)

        # Pull in any keybindings from an external file
        self.keybindings = keyboard_shortcut

        icon = get_icon('app_icon')
        self.app.setWindowIcon(icon)

        # Even though we loaded the plugins in start_glue, we re-load them here
        # in case glue was started directly by initializing this class.
        load_plugins(require_qt_plugins=True)

        self.setWindowTitle("Glue")
        self.setWindowIcon(icon)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self._actions = {}
        self._terminal = None
        self._setup_ui()
        self.tab_widget.setMovable(True)
        self.tab_widget.setTabsClosable(True)

        # The following is a counter that never goes down, even if tabs are
        # deleted (this is by design, to avoid having two tabs called the
        # same if a tab is removed then a new one added again)
        self._total_tab_count = 0

        lwidget = self._layer_widget
        a = PlotAction(lwidget, self)
        lwidget.ui.layerTree.addAction(a)

        self._tweak_geometry()
        self._create_actions()
        self._create_menu()
        self._connect()
        self.new_tab()
        self._update_viewer_in_focus()
예제 #7
0
파일: cli.py 프로젝트: bsipocz/mosviz
def main(argv=sys.argv):
    """
    The majority of the code in this function was taken from start_glue() in main.py after a discussion with
    Tom Robataille. We wanted the ability to get command line arguments and use them in here and this seemed
    to be the cleanest way to do it.
    """
    # Make sure the mosviz startup item is registered
    from .startup import mosviz_setup  # noqa

    parser = argparse.ArgumentParser()
    parser.add_argument('data_files', nargs=argparse.REMAINDER)
    args = parser.parse_known_args(argv[1:])

    import glue
    from glue.utils.qt import get_qapp
    app = get_qapp()

    # Splash screen
    splash = get_splash()
    splash.image = QtGui.QPixmap(MOSVIZ_SPLASH_PATH)
    splash.show()

    # Start off by loading plugins. We need to do this before restoring
    # the session or loading the configuration since these may use existing
    # plugins.
    load_plugins(splash=splash)

    datafiles = args[0].data_files

    # # Show the splash screen for 2 seconds
    timer = QTimer()
    timer.setInterval(2000)
    timer.setSingleShot(True)
    timer.timeout.connect(splash.close)
    timer.start()

    data_collection = glue.core.DataCollection()
    hub = data_collection.hub

    splash.set_progress(100)

    session = glue.core.Session(data_collection=data_collection, hub=hub)
    ga = GlueApplication(session=session)
    qapp = QtWidgets.QApplication.instance()
    ga.setWindowTitle('MOSViz v{0}'.format(__version__))
    qapp.setWindowIcon(QtGui.QIcon(MOSVIZ_ICON_PATH))
    ga.setWindowIcon(QtGui.QIcon(MOSVIZ_ICON_PATH))

    # Load the data files.
    if datafiles:
        datasets = load_data_files(datafiles)
        ga.add_datasets(data_collection, datasets, auto_merge=False)

    ga.run_startup_action('mosviz')

    sys.exit(ga.start(maximized=True))
예제 #8
0
    def __init__(self, data_collection=None, session=None):

        # At this point we need to check if a Qt application already exists -
        # this happens for example if using the %gui qt/qt5 mode in Jupyter. We
        # should keep a reference to the original icon so that we can restore it
        # later
        self._original_app = QtWidgets.QApplication.instance()
        if self._original_app is not None:
            self._original_icon = self._original_app.windowIcon()

        self._export_helper = ExportHelper(self)
        self._import_helper = ImportHelper(self)

        # Now we can get the application instance, which involves setting it
        # up if it doesn't already exist.
        self.app = get_qapp()

        QtWidgets.QMainWindow.__init__(self)
        Application.__init__(self, data_collection=data_collection,
                             session=session)

        # Pull in any keybindings from an external file
        self.keybindings = keyboard_shortcut

        icon = get_icon('app_icon')
        self.app.setWindowIcon(icon)

        # Even though we loaded the plugins in start_glue, we re-load them here
        # in case glue was started directly by initializing this class.
        load_plugins()

        self.setWindowTitle("Glue")
        self.setWindowIcon(icon)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self._actions = {}
        self._terminal = None
        self._setup_ui()
        self.tab_widget.setMovable(True)
        self.tab_widget.setTabsClosable(True)

        # The following is a counter that never goes down, even if tabs are
        # deleted (this is by design, to avoid having two tabs called the
        # same if a tab is removed then a new one added again)
        self._total_tab_count = 0

        lwidget = self._layer_widget
        a = PlotAction(lwidget, self)
        lwidget.ui.layerTree.addAction(a)

        self._tweak_geometry()
        self._create_actions()
        self._create_menu()
        self._connect()
        self.new_tab()
        self._update_viewer_in_focus()
예제 #9
0
파일: gs9.py 프로젝트: glue-viz/glue-cli
def gs9(data, vmin, vmax, percentile, stretch, cmap):

    load_plugins()

    if cmap is not None:
        for cmap_name, cmap_obj in colormaps.members:
            if cmap == cmap_name:
                cmap = cmap_obj
                break
        else:
            colormaps.add(cmap, cm.get_cmap(cmap))
            cmap = cm.get_cmap(cmap)

    ga = GlueApplication()

    image = ga.new_data_viewer(ImageViewer)

    datasets = []
    for filename in data:
        datasets.append(load_data(filename))

    # Add datasets all in one go to do all linking in one pass
    ga.add_datasets(datasets)

    for d in ga.data_collection:
        image.add_data(d)

    for layer_state in image.state.layers:

        if vmin is not None:
            layer_state.v_min = vmin

        if vmax is not None:
            layer_state.v_min = vmax

        if percentile is not None:
            choices = ImageLayerState.percentile.get_choices(layer_state)
            for choice in choices:
                if percentile == choice:
                    percentile = choice
                    break
            layer_state.percentile = percentile

        if stretch is not None:
            layer_state.stretch = stretch

        if cmap is not None:
            layer_state.cmap = cmap

    image.viewer_size = (600, 600)

    ga.gather_current_tab()
    ga.start(maximized=False, size=(1024, 768))
예제 #10
0
    def __init__(self, data_collection=None, session=None):

        super(JupyterApplication, self).__init__(data_collection=data_collection, session=session)

        try:
            from glue.main import load_plugins
            load_plugins()
        except Exception:  # Compatibility with glue <0.16
            from glue.main import REQUIRED_PLUGINS
            REQUIRED_PLUGINS.clear()
            load_plugins()

        self.output = widgets.Output()
        self.widget_data_collection = widgets.SelectMultiple()
        self.widget_subset_select = SubsetSelect(session=self.session)
        self.widget_subset_mode = SelectionModeMenu(session=self.session)
        self.widget = widgets.VBox(children=[self.widget_subset_mode, self.output])
예제 #11
0
def main():  # pragma: no cover
    import numpy as np
    from glue.main import load_plugins
    from glue.utils.qt import get_qapp
    from glue.core import Data, DataCollection

    load_plugins()

    app = get_qapp()

    dc = DataCollection()

    for i in range(10):
        x = np.array([1, 2, 3])
        d = Data(label='data_{0:02d}'.format(i), x=x, y=x * 2)
        dc.append(d)

    LinkEditor.update_links(dc)
예제 #12
0
def main():  # pragma: no cover
    import numpy as np
    from glue.main import load_plugins
    from glue.utils.qt import get_qapp
    from glue.core import Data, DataCollection

    load_plugins()

    app = get_qapp()

    dc = DataCollection()

    for i in range(10):
        x = np.array([1, 2, 3])
        d = Data(label='data_{0:02d}'.format(i), x=x, y=x * 2)
        dc.append(d)

    LinkEditor.update_links(dc)
예제 #13
0
파일: conftest.py 프로젝트: antonl/glue
def pytest_configure(config):

    if config.getoption('no_optional_skip'):
        from glue.tests import helpers
        for attr in helpers.__dict__:
            if attr.startswith('requires_'):
                # The following line replaces the decorators with a function
                # that does noting, effectively disabling it.
                setattr(helpers, attr, lambda f: f)

    # Make sure we don't affect the real glue config dir
    import tempfile
    from glue import config
    config.CFG_DIR = tempfile.mkdtemp()

    # Force loading of plugins
    from glue.main import load_plugins
    load_plugins()
예제 #14
0
파일: application.py 프로젝트: rguter/glue
    def __init__(self, data_collection=None, session=None):

        self.app = get_qapp()

        QtGui.QMainWindow.__init__(self)
        Application.__init__(self,
                             data_collection=data_collection,
                             session=session)

        self.app.setQuitOnLastWindowClosed(True)
        pth = os.path.abspath(os.path.dirname(__file__))
        pth = os.path.join(pth, 'icons', 'app_icon.png')
        self.app.setWindowIcon(QtGui.QIcon(pth))

        # Even though we loaded the plugins in start_glue, we re-load them here
        # in case glue was started directly by initializing this class.
        load_plugins()

        self.setWindowIcon(self.app.windowIcon())
        self.setAttribute(Qt.WA_DeleteOnClose)
        self._actions = {}
        self._terminal = None
        self._setup_ui()
        self.tab_widget.setMovable(True)
        self.tab_widget.setTabsClosable(True)

        # The following is a counter that never goes down, even if tabs are
        # deleted (this is by design, to avoid having two tabs called the
        # same if a tab is removed then a new one added again)
        self._total_tab_count = 0

        lwidget = self._ui.layerWidget
        a = PlotAction(lwidget, self)
        lwidget.layerTree.addAction(a)
        lwidget.bind_selection_to_edit_subset()

        self._tweak_geometry()
        self._create_actions()
        self._create_menu()
        self._connect()
        self.new_tab()
        self._update_plot_dashboard(None)

        self._load_settings()
예제 #15
0
    def __init__(self, data_collection=None, session=None):

        self.app = get_qapp()

        QtGui.QMainWindow.__init__(self)
        Application.__init__(self, data_collection=data_collection,
                             session=session)

        self.app.setQuitOnLastWindowClosed(True)
        icon = get_icon('app_icon')
        self.app.setWindowIcon(icon)

        # Even though we loaded the plugins in start_glue, we re-load them here
        # in case glue was started directly by initializing this class.
        load_plugins()

        self.setWindowTitle("Glue")
        self.setWindowIcon(icon)
        self.setAttribute(Qt.WA_DeleteOnClose)
        self._actions = {}
        self._terminal = None
        self._setup_ui()
        self.tab_widget.setMovable(True)
        self.tab_widget.setTabsClosable(True)

        # The following is a counter that never goes down, even if tabs are
        # deleted (this is by design, to avoid having two tabs called the
        # same if a tab is removed then a new one added again)
        self._total_tab_count = 0

        lwidget = self._layer_widget
        a = PlotAction(lwidget, self)
        lwidget.ui.layerTree.addAction(a)
        lwidget.bind_selection_to_edit_subset()

        self._tweak_geometry()
        self._create_actions()
        self._create_menu()
        self._connect()
        self.new_tab()
        self._update_plot_dashboard(None)

        self._load_settings()
예제 #16
0
def create_app(datafiles=[], interactive=True):

    app = get_qapp()

    if interactive:
        # Splash screen
        splash = get_splash()
        splash.image = QtGui.QPixmap(MOSVIZ_SPLASH_PATH)
        splash.show()
    else:
        splash = None

    # Start off by loading plugins. We need to do this before restoring
    # the session or loading the configuration since these may use existing
    # plugins.
    load_plugins(splash=splash)

    # # Show the splash screen for 2 seconds
    if interactive:
        timer = QTimer()
        timer.setInterval(2000)
        timer.setSingleShot(True)
        timer.timeout.connect(splash.close)
        timer.start()

    data_collection = glue.core.DataCollection()
    hub = data_collection.hub

    if interactive:
        splash.set_progress(100)

    ga = _create_glue_app(data_collection, hub)
    ga.run_startup_action('mosviz')

    # Load the data files.
    if datafiles:
        datasets = load_data_files(datafiles)
        ga.add_datasets(data_collection, datasets, auto_merge=False)

    return ga
예제 #17
0
def create_app(datafiles=[], interactive=True):

    app = get_qapp()

    if interactive:
        # Splash screen
        splash = get_splash()
        splash.image = QtGui.QPixmap(MOSVIZ_SPLASH_PATH)
        splash.show()
    else:
        splash = None

    # Start off by loading plugins. We need to do this before restoring
    # the session or loading the configuration since these may use existing
    # plugins.
    load_plugins(splash=splash)

    # # Show the splash screen for 2 seconds
    if interactive:
        timer = QTimer()
        timer.setInterval(2000)
        timer.setSingleShot(True)
        timer.timeout.connect(splash.close)
        timer.start()

    data_collection = glue.core.DataCollection()
    hub = data_collection.hub

    if interactive:
        splash.set_progress(100)

    ga = _create_glue_app(data_collection, hub)
    ga.run_startup_action('mosviz')

    # Load the data files.
    if datafiles:
        datasets = load_data_files(datafiles)
        ga.add_datasets(data_collection, datasets, auto_merge=False)

    return ga
예제 #18
0
def test_basic(tmpdir):

    # Test that things work when the plugin cfg file is populated

    from glue import config
    config.CFG_DIR = tmpdir.join('.glue').strpath

    load_plugins()

    config = ph.PluginConfig.load()
    config.plugins['spectrum_tool'] = False
    config.plugins['pv_slicer'] = False
    config.save()

    w = QtPluginManager()
    w.clear()
    w.update_list()
    w.finalize()

    config2 = ph.PluginConfig.load()

    assert config.plugins == config2.plugins
예제 #19
0
def create_app(datafiles=[], data_configs=[], data_configs_show=False,
               interactive=True):
    """
    Create and initialize a cubeviz application instance

    Parameters
    ----------
    datafiles : `list`
        A list of filenames representing data files to be loaded
    data_configs : `list`
        A list of filenames representing data configuration files to be used
    data_configs_show : `bool`
        Display matching info about data configuration files
    interactive : `bool`
        Flag to indicate whether session is interactive or not (i.e. for testing)
    """
    app = get_qapp()

    # Splash screen
    if interactive:
        splash = get_splash()
        splash.image = QtGui.QPixmap(CUBEVIZ_LOGO_PATH)
        splash.show()
    else:
        splash = None

    # Start off by loading plugins. We need to do this before restoring
    # the session or loading the configuration since these may use existing
    # plugins.
    load_plugins(splash=splash)

    dfc_kwargs = dict(remove_defaults=True, check_ifu_valid=interactive)
    DataFactoryConfiguration(data_configs, data_configs_show, **dfc_kwargs)

    # Check to make sure each file exists and raise an Exception
    # that will show in the popup if it does not exist.
    _check_datafiles_exist(datafiles)

    # Show the splash screen for 1 second
    if interactive:
        timer = QTimer()
        timer.setInterval(1000)
        timer.setSingleShot(True)
        timer.timeout.connect(splash.close)
        timer.start()

    data_collection = glue.core.DataCollection()
    hub = data_collection.hub

    ga = _create_glue_app(data_collection, hub)
    ga.run_startup_action('cubeviz')

    # Load the data files.
    if datafiles:
        datasets = load_data_files(datafiles)
        ga.add_datasets(data_collection, datasets, auto_merge=False)

    if interactive:
        splash.set_progress(100)

    return ga
예제 #20
0
def main(argv=sys.argv):
    """
    The majority of the code in this function was taken from start_glue() in main.py after a discussion with
    Tom Robataille. We wanted the ability to get command line arguments and use them in here and this seemed
    to be the cleanest way to do it.

    :param argv:
    :return:
    """

    # # Parse the arguments, ignore any unkonwn
    parser = argparse.ArgumentParser()
    parser.add_argument("--data-configs", help="Directory or file for data configuration YAML files", action='append', default=[])
    parser.add_argument("--data-configs-show", help="Show the matching info", action="store_true", default=False)
    parser.add_argument('data_files', nargs=argparse.REMAINDER)
    args = parser.parse_known_args(argv[1:])

    # Store the args for each ' --data-configs' found on the commandline
    data_configs = args[0].data_configs
    data_configs_show = args[0].data_configs_show

    import glue
    from glue.utils.qt import get_qapp
    app = get_qapp()

    # Splash screen
    splash = get_splash()
    splash.image = QtGui.QPixmap(CUBEVIZ_LOGO_PATH)
    splash.show()

    # Start off by loading plugins. We need to do this before restoring
    # the session or loading the configuration since these may use existing
    # plugins.
    load_plugins(splash=splash)

    # Load the
    DataFactoryConfiguration(data_configs, data_configs_show, remove_defaults=True)

    datafiles = args[0].data_files

    # Check to make sure each file exists and raise an Exception
    # that will show in the popup if it does not exist.
    for fileparam in datafiles:
        for filename in  fileparam.split(','):
            if not os.path.isfile(filename.strip()):
                raise IOError('The file {} does not exist'.format(filename))

    # Show the splash screen for 1 second
    timer = QTimer()
    timer.setInterval(1000)
    timer.setSingleShot(True)
    timer.timeout.connect(splash.close)
    timer.start()

    data_collection = glue.core.DataCollection()
    hub = data_collection.hub

    splash.set_progress(100)

    session = glue.core.Session(data_collection=data_collection, hub=hub)
    ga = GlueApplication(session=session)
    ga.setWindowTitle('cubeviz ({})'.format(cubeviz_version))
    qapp = QtWidgets.QApplication.instance()
    qapp.setWindowIcon(QtGui.QIcon(CUBEVIZ_ICON_PATH))
    ga.setWindowIcon(QtGui.QIcon(CUBEVIZ_ICON_PATH))

    ga.run_startup_action('cubeviz')

    # Load the data files.
    if datafiles:
        datasets = load_data_files(datafiles)
        ga.add_datasets(data_collection, datasets, auto_merge=False)


    sys.exit(ga.start(maximized=True))
예제 #21
0
def create_app(datafiles=[],
               data_configs=[],
               data_configs_show=False,
               interactive=True):
    """
    Create and initialize a cubeviz application instance

    Parameters
    ----------
    datafiles : `list`
        A list of filenames representing data files to be loaded
    data_configs : `list`
        A list of filenames representing data configuration files to be used
    data_configs_show : `bool`
        Display matching info about data configuration files
    interactive : `bool`
        Flag to indicate whether session is interactive or not (i.e. for testing)
    """
    app = get_qapp()

    # Splash screen
    if interactive:
        splash = get_splash()
        splash.image = QtGui.QPixmap(CUBEVIZ_LOGO_PATH)
        splash.show()
    else:
        splash = None

    # Start off by loading plugins. We need to do this before restoring
    # the session or loading the configuration since these may use existing
    # plugins.
    load_plugins(splash=splash)

    dfc_kwargs = dict(remove_defaults=True, check_ifu_valid=interactive)
    DataFactoryConfiguration(data_configs, data_configs_show, **dfc_kwargs)

    # Check to make sure each file exists and raise an Exception
    # that will show in the popup if it does not exist.
    _check_datafiles_exist(datafiles)

    # Show the splash screen for 1 second
    if interactive:
        timer = QTimer()
        timer.setInterval(1000)
        timer.setSingleShot(True)
        timer.timeout.connect(splash.close)
        timer.start()

    data_collection = glue.core.DataCollection()
    hub = data_collection.hub

    ga = _create_glue_app(data_collection, hub)
    ga.run_startup_action('cubeviz')

    # Load the data files.
    if datafiles:
        datasets = load_data_files(datafiles)
        ga.add_datasets(data_collection, datasets, auto_merge=False)

    if interactive:
        splash.set_progress(100)

    return ga