本文整理汇总了Python中glue.app.qt.GlueApplication.restore_session方法的典型用法代码示例。如果您正苦于以下问题:Python GlueApplication.restore_session方法的具体用法?Python GlueApplication.restore_session怎么用?Python GlueApplication.restore_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类glue.app.qt.GlueApplication
的用法示例。
在下文中一共展示了GlueApplication.restore_session方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_table_widget_session_no_subset
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import restore_session [as 别名]
def test_table_widget_session_no_subset(tmpdir):
# Regression test for a bug that caused table viewers with no subsets to
# not be restored correctly and instead raise an exception.
app = get_qapp() # noqa
d = Data(a=[1, 2, 3, 4, 5],
b=[3.2, 1.2, 4.5, 3.3, 2.2],
c=['e', 'b', 'c', 'a', 'f'], label='test')
dc = DataCollection([d])
gapp = GlueApplication(dc)
widget = gapp.new_data_viewer(TableViewer)
widget.add_data(d)
session_file = tmpdir.join('table.glu').strpath
gapp.save_session(session_file)
gapp2 = GlueApplication.restore_session(session_file)
gapp2.show()
gapp2.data_collection[0]
gapp2.viewers[0][0]
示例2: test_add_viewer
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import restore_session [as 别名]
def test_add_viewer(self, tmpdir):
d1 = Data(x=np.random.random((2,) * self.ndim))
d2 = Data(x=np.random.random((2,) * self.ndim))
dc = DataCollection([d1, d2])
app = GlueApplication(dc)
w = app.new_data_viewer(self.widget_cls, data=d1)
w.viewer_size = (300, 400)
filename = tmpdir.join('session.glu').strpath
app.save_session(filename, include_data=True)
app2 = GlueApplication.restore_session(filename)
# test session is restored correctly
for viewer in app2.viewers:
assert viewer[0].viewer_size == (300, 400)
app.close()
app2.close()
示例3: test_viewer_size
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import restore_session [as 别名]
def test_viewer_size(self, tmpdir):
# regression test for #781
# viewers were not restored with the right size
d1 = Data(x=np.random.random((2,) * self.ndim))
d2 = Data(x=np.random.random((2,) * self.ndim))
dc = DataCollection([d1, d2])
app = GlueApplication(dc)
w = app.new_data_viewer(self.widget_cls, data=d1)
w.viewer_size = (300, 400)
filename = tmpdir.join('session.glu').strpath
app.save_session(filename, include_data=True)
app2 = GlueApplication.restore_session(filename)
for viewer in app2.viewers:
assert viewer[0].viewer_size == (300, 400)
app.close()
app2.close()
示例4: test_save_aggregate_slice
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import restore_session [as 别名]
def test_save_aggregate_slice(self, tmpdir):
# Regression test to make sure that image viewers that include
# aggregate slice objects in the slices can be saved/restored
self.viewer.add_data(self.hypercube)
self.viewer.state.slices = AggregateSlice(slice(1, 3), 10, np.sum), 3, 0, 0
filename = tmpdir.join('session.glu').strpath
self.application.save_session(filename)
self.application.close()
app2 = GlueApplication.restore_session(filename)
viewer_state = app2.viewers[0][0].state
slices = viewer_state.slices
assert isinstance(slices[0], AggregateSlice)
assert slices[0].slice == slice(1, 3)
assert slices[0].center == 10
assert slices[0].function is np.sum
assert slices[1:] == (3, 0, 0)
app2.close()
示例5: restore_session
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import restore_session [as 别名]
def restore_session(gluefile):
"""Load a .glu file and return a DataCollection, Hub tuple"""
from glue.app.qt import GlueApplication
return GlueApplication.restore_session(gluefile)
示例6: test_table_widget
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import restore_session [as 别名]
#.........这里部分代码省略.........
widget.toolbar.actions['table:rowselect'].toggle()
def press_key(key):
event = QtGui.QKeyEvent(QtCore.QEvent.KeyPress, key, Qt.NoModifier)
app.postEvent(widget.ui.table, event)
app.processEvents()
process_events()
# We now use key presses to navigate down to the third row
press_key(Qt.Key_Tab)
press_key(Qt.Key_Down)
press_key(Qt.Key_Down)
process_events()
indices = selection.selectedRows()
# We make sure that the third row is selected
assert len(indices) == 1
assert indices[0].row() == 2
# At this point, the subsets haven't changed yet
np.testing.assert_equal(d.subsets[0].to_mask(), [1, 1, 1, 0, 0])
np.testing.assert_equal(d.subsets[1].to_mask(), [0, 1, 1, 0, 0])
# We specify that we are editing the second subset, and use a 'not' logical
# operation to remove the currently selected line from the second subset.
subset_mode.edit_subset = [d.subsets[1]]
subset_mode.mode = AndNotMode
press_key(Qt.Key_Enter)
np.testing.assert_equal(d.subsets[0].to_mask(), [1, 1, 1, 0, 0])
np.testing.assert_equal(d.subsets[1].to_mask(), [0, 1, 0, 0, 0])
# At this point, the selection should be cleared
indices = selection.selectedRows()
assert len(indices) == 0
# We move to the fourth row and now do an 'or' selection with the first
# subset.
press_key(Qt.Key_Down)
subset_mode.mode = OrMode
subset_mode.edit_subset = [d.subsets[0]]
press_key(Qt.Key_Enter)
np.testing.assert_equal(d.subsets[0].to_mask(), [1, 1, 1, 1, 0])
np.testing.assert_equal(d.subsets[1].to_mask(), [0, 1, 0, 0, 0])
# Finally we move to the fifth row and deselect all subsets so that
# pressing enter now creates a new subset.
press_key(Qt.Key_Down)
subset_mode.mode = ReplaceMode
subset_mode.edit_subset = None
press_key(Qt.Key_Enter)
np.testing.assert_equal(d.subsets[0].to_mask(), [1, 1, 1, 1, 0])
np.testing.assert_equal(d.subsets[1].to_mask(), [0, 1, 0, 0, 0])
np.testing.assert_equal(d.subsets[2].to_mask(), [0, 0, 0, 0, 1])
# Make the color for the new subset deterministic
dc.subset_groups[2].style.color = '#bababa'
# Now finally check saving and restoring session
session_file = tmpdir.join('table.glu').strpath
gapp.save_session(session_file)
gapp2 = GlueApplication.restore_session(session_file)
gapp2.show()
d = gapp2.data_collection[0]
widget2 = gapp2.viewers[0][0]
model2 = widget2.ui.table.model()
data = {'a': [1, 2, 3, 4, 5],
'b': [3.2, 1.2, 4.5, 3.3, 2.2],
'c': ['e', 'b', 'c', 'a', 'f']}
# Need to take into account new selections above
colors = ['#aa0000', '#380088', '#aa0000', "#aa0000", "#bababa"]
check_values_and_color(model2, data, colors)
示例7: start_glue
# 需要导入模块: from glue.app.qt import GlueApplication [as 别名]
# 或者: from glue.app.qt.GlueApplication import restore_session [as 别名]
def start_glue(gluefile=None, config=None, datafiles=None, maximized=True,
startup_actions=None, auto_merge=False):
"""Run a glue session and exit
Parameters
----------
gluefile : str
An optional ``.glu`` file to restore.
config : str
An optional configuration file to use.
datafiles : str
An optional list of data files to load.
maximized : bool
Maximize screen on startup. Otherwise, use default size.
auto_merge : bool, optional
Whether to automatically merge data passed in `datafiles` (default is `False`)
"""
import glue
# Some Qt modules are picky in terms of being imported before the
# application is set up, so we import them here. We do it here rather
# than in get_qapp since in the past, including this code in get_qapp
# caused severe issues (e.g. segmentation faults) in plugin packages
# during testing.
try:
from qtpy import QtWebEngineWidgets # noqa
except ImportError: # Not all PyQt installations have this module
pass
from glue.utils.qt.decorators import die_on_error
from glue.utils.qt import get_qapp
app = get_qapp()
splash = get_splash()
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)
from glue.app.qt import GlueApplication
datafiles = datafiles or []
hub = None
from qtpy.QtCore import QTimer
timer = QTimer()
timer.setInterval(1000)
timer.setSingleShot(True)
timer.timeout.connect(splash.close)
timer.start()
if gluefile is not None:
with die_on_error("Error restoring Glue session"):
app = GlueApplication.restore_session(gluefile, show=False)
return app.start(maximized=maximized)
if config is not None:
glue.env = glue.config.load_configuration(search_path=[config])
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)
if datafiles:
with die_on_error("Error reading data file"):
datasets = load_data_files(datafiles)
ga.add_datasets(data_collection, datasets, auto_merge=auto_merge)
if startup_actions is not None:
for name in startup_actions:
ga.run_startup_action(name)
return ga.start(maximized=maximized)