def new_client(self, dc=None, canvas=None): from glue.external.qt import get_qapp get_qapp() dc = dc or self.collect l = log.get_logger(name='ginga', log_stderr=True) canvas = ImageViewCanvas(l, render='widget') return GingaClient(dc, canvas)
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()
def __init__(self, axes, **kwargs): super(RoiMode, self).__init__(axes, **kwargs) self._start_event = None self._drag = False app = get_qapp() self._drag_dist = app.startDragDistance()
def result(*args, **kwargs): from glue.external.qt import get_qapp app = get_qapp() app.setOverrideCursor(shape) try: return func(*args, **kwargs) finally: app.restoreOverrideCursor()
def test_resize(self): # Regression test for a bug that caused images to not be shown at # full resolution after resizing a widget. # This test only runs correctly on Linux on Travis at the moment, # although it works fine locally on MacOS X. I have not yet tracked # down the cause of the failure, but essentially the first time that # self.widget.client._view_window is accessed below, it is still None. # The issue is made more complicated by the fact that whether the test # succeeds or not (after removing code in ImageWidget) depends on # whether another test is run first - in particular I tried with # test_resize from test_application.py. I was able to then get the # test here to pass if the other test_resize was *not* run first. # This should be investigated more in future, but for now, it's most # important that we get the fix in. # What appears to happen when the test fails is that the QTimer gets # started but basically never ends up triggering the timeout. large = core.Data(label='largeim', x=np.random.random((1024, 1024))) self.collect.append(large) app = get_qapp() self.widget.add_data(large) self.widget.show() self.widget.resize(300, 300) time.sleep(0.5) app.processEvents() if self.widget.client._view_window is None: if not CI or not TRAVIS_LINUX: pytest.xfail('Only works reliably on Travis with Linux') extx0, exty0 = self.widget.client._view_window[4:] # While resizing, the view window should not change until we've # waited for a bit, to avoid resampling the data every time. for res in range(10): self.widget.resize(300 + res * 30, 300 + res * 30) app.processEvents() extx, exty = self.widget.client._view_window[4:] assert extx == extx0 assert exty == exty0 time.sleep(0.5) app.processEvents() extx, exty = self.widget.client._view_window[4:] assert extx != extx0 assert exty != exty0 self.widget.close()
def main(): import numpy as np from glue.external.qt import get_qapp from glue.core import Data, DataCollection app = get_qapp() x = np.array([1, 2, 3]) d = Data(label='data', x=x, y=x * 2) dc = DataCollection(d) LinkEditor.update_links(dc)
def test_main(): app = get_qapp() w = QMessageBox(QMessageBox.Critical, "Error", "An error occurred") w.setDetailedText("Spam") w.select_all() w.copy_detailed() assert app.clipboard().text() == "Spam" app.quit()
def test_resize(self): # Regression test for a bug that caused images to not be shown at # full resolution after resizing a widget. # This test only runs correctly on Linux on Travis at the moment, # although it works fine locally on MacOS X. I have not yet tracked # down the cause of the failure, but essentially the first time that # self.widget.client._view_window is accessed below, it is still None. # The issue is made more complicated by the fact that whether the test # succeeds or not (after removing code in ImageWidget) depends on # whether another test is run first - in particular I tried with # test_resize from test_application.py. I was able to then get the # test here to pass if the other test_resize was *not* run first. # This should be investigated more in future, but for now, it's most # important that we get the fix in. # What appears to happen when the test fails is that the QTimer gets # started but basically never ends up triggering the timeout. large = core.Data(label='largeim', x=np.random.random((1024, 1024))) self.collect.append(large) app = get_qapp() self.widget.add_data(large) self.widget.show() self.widget.resize(300, 300) time.sleep(0.5) app.processEvents() extx0, exty0 = self.widget.client._view_window[4:] # While resizing, the view window should not change until we've # waited for a bit, to avoid resampling the data every time. for res in range(10): self.widget.resize(300 + res * 30, 300 + res * 30) app.processEvents() extx, exty = self.widget.client._view_window[4:] assert extx == extx0 assert exty == exty0 time.sleep(0.5) app.processEvents() extx, exty = self.widget.client._view_window[4:] assert extx != extx0 assert exty != exty0 self.widget.close()
def wrapper(*args, **kwargs): try: return func(*args, **kwargs) except Exception as e: import traceback # Make sure application has been started from glue.external.qt import get_qapp get_qapp() from glue.utils.qt import QMessageBoxPatched as QMessageBox m = "%s\n%s" % (msg, e) detail = str(traceback.format_exc()) if len(m) > 500: detail = "Full message:\n\n%s\n\n%s" % (m, detail) m = m[:500] + '...' qmb = QMessageBox(QMessageBox.Critical, "Error", m) qmb.setDetailedText(detail) qmb.show() qmb.raise_() qmb.exec_() sys.exit(1)
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()
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()
def __init__(self, session, parent=None): """ :type session: :class:`~glue.core.Session` """ QtGui.QMainWindow.__init__(self, parent) ViewerBase.__init__(self, session) self.setWindowIcon(get_qapp().windowIcon()) self._view = LayerArtistView() self._view.setModel(self._layer_artist_container.model) self._tb_vis = {} # store whether toolbars are enabled self.setAttribute(Qt.WA_DeleteOnClose) self.setAcceptDrops(True) self.setAnimated(False) self._toolbars = [] self._warn_close = True self.setContentsMargins(2, 2, 2, 2) self._mdi_wrapper = None # GlueMdiSubWindow that self is embedded in self.statusBar().setStyleSheet("QStatusBar{font-size:10px}") # close window when last plot layer deleted self._layer_artist_container.on_empty(lambda: self.close(warn=False)) self._layer_artist_container.on_changed(self.update_window_title)
def main(): # pragma: no cover import glue import numpy as np from glue.external.qt import get_qapp d = glue.core.Data(label="hi") d2 = glue.core.Data(label="there") c1 = glue.core.Component(np.array([1, 2, 3])) c2 = glue.core.Component(np.array([1, 2, 3])) c3 = glue.core.Component(np.array([1, 2, 3])) dc = glue.core.DataCollection() dc.append(d) dc.append(d2) d.add_component(c1, "a") d.add_component(c2, "b") d2.add_component(c3, "c") app = get_qapp() w = ComponentSelector() w.setup(dc) w.show() app.exec_()
def wrapper(): from glue.external.qt import get_qapp app = get_qapp() dialog = app.focusWidget().window() function(dialog)
raise NotImplementedError() self.ui.layerTree[key] = value def __contains__(self, obj): return obj in self.ui.layerTree def __len__(self): return len(self.ui.layerTree) def save_subset(subset): assert isinstance(subset, core.subset.Subset) fname, fltr = QtGui.QFileDialog.getSaveFileName( caption="Select an output name", filter='FITS mask (*.fits);; Fits mask (*.fits)') fname = str(fname) if not fname: return subset.write_mask(fname) if __name__ == "__main__": from glue.core.data_collection import DataCollection collection = DataCollection() from glue.external.qt import get_qapp app = get_qapp() widget = LayerTreeWidget() widget.setup(collection) widget.show() app.exec_()
from glue.external.qt import get_qapp, QtGui from glue.core.session import Session from glue.core import Data, DataCollection from viewer import ScatterViewer data = Data(x=[1, 2, 3], y=[1, 3, 2]) dc = DataCollection([data]) app = get_qapp() session = Session(application=app, data_collection=dc) viewer = ScatterViewer(session) window = QtGui.QWidget() viewer.add_data(data) vlayout = QtGui.QVBoxLayout() vlayout.addWidget(viewer._layer_artist_container[0].style_editor) vlayout.addWidget(viewer.options_widget()) vwidget = QtGui.QWidget() vwidget.setLayout(vlayout) hlayout = QtGui.QHBoxLayout() hlayout.addWidget(vwidget) hlayout.addWidget(viewer) window.setLayout(hlayout)
def pytest_configure(config): global app app = get_qapp()
import operator import pytest import numpy as np from glue.external.qt import QtGui from glue.core import Data, DataCollection from glue.core.subset import InequalitySubsetState from glue.core.qt.data_combo_helper import ComponentIDComboHelper from ..attribute_limits_helper import AttributeLimitsHelper # TEMPORARY from glue.external.qt import get_qapp get_qapp() class TestAttributeLimitsHelper(): def setup_method(self, method): self.attribute_combo = QtGui.QComboBox() self.lower_value = QtGui.QLineEdit() self.upper_value = QtGui.QLineEdit() self.mode_combo = QtGui.QComboBox() self.flip_button = QtGui.QToolButton() self.log_button = QtGui.QToolButton() self.log_button.setCheckable(True) self.data = Data(x=np.linspace(-100, 100, 10000),
def teardown(): # can be None if exceptions are raised early during setup -- #323 if get_qapp is not None: app = get_qapp() app.exit()