Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show dataset name in table viewer title #1973

Merged
merged 2 commits into from
Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Full changelog
v0.15.0 (unreleased)
--------------------

* Show dataset name in table viewer title. [#1973]

* Expose an option (``inherit_tools``) on data viewer classes
related to whether tools should be inherited or not from
parent classes. [#1972]
Expand Down
43 changes: 34 additions & 9 deletions glue/core/layer_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ def __init__(self):
self.artists = []
self.empty_callbacks = CallbackContainer()
self.change_callbacks = CallbackContainer()
self._ignore_callbacks = False
self._ignore_empty_callbacks = False
self._ignore_change_callbacks = False

def on_empty(self, func):
"""
Expand Down Expand Up @@ -304,13 +305,12 @@ def clear_callbacks(self):
self.change_callbacks.clear()

def _notify(self):
if self._ignore_callbacks:
return

for cb in self.change_callbacks:
cb()
if not self._ignore_change_callbacks:
for cb in self.change_callbacks:
cb()

if len(self) == 0:
if not self._ignore_empty_callbacks and len(self) == 0:
for cb in self.empty_callbacks:
cb()

Expand All @@ -328,12 +328,37 @@ def layers(self):

@contextmanager
def ignore_empty(self):
"""A context manager that temporarily disables calling callbacks if container is emptied"""
"""
A context manager that temporarily disables calling callbacks if
container is empty.
"""
try:
self._ignore_empty_callbacks = True
yield
finally:
self._ignore_empty_callbacks = False

@contextmanager
def ignore_change(self):
"""
A context manager that temporarily disables calling callbacks if
container is changed.
"""
try:
self._ignore_change_callbacks = True
yield
finally:
self._ignore_change_callbacks = False

@contextmanager
def ignore_callbacks(self):
try:
self._ignore_callbacks = True
self._ignore_change_callbacks = True
self._ignore_empty_callbacks = True
yield
finally:
self._ignore_callbacks = False
self._ignore_change_callbacks = False
self._ignore_empty_callbacks = False

def __len__(self):
return len(self.artists)
Expand Down
2 changes: 2 additions & 0 deletions glue/viewers/common/qt/data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def __init__(self, session, state=None, parent=None):
self._layer_artist_container.on_empty(self._close_nowarn)
self._layer_artist_container.on_changed(self.update_window_title)

self.update_window_title()

@property
def selected_layer(self):
return self._view.layer_list.current_artist()
Expand Down
2 changes: 1 addition & 1 deletion glue/viewers/common/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ def __setgluestate__(cls, rec, context):

# Restore layer artists. Ideally we would delay instead of ignoring the
# callback here.
with viewer._layer_artist_container.ignore_empty():
with viewer._layer_artist_container.ignore_callbacks():
for l in rec['layers']:
cls = lookup_class_with_patches(l.pop('_type'))
layer_state = context.object(l['state'])
Expand Down
7 changes: 7 additions & 0 deletions glue/viewers/table/qt/data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,13 @@ def add_data(self, data):
self.state.layers[:] = []
return super(TableViewer, self).add_data(data)

@property
def window_title(self):
if len(self.state.layers) > 0:
return 'Table: ' + self.state.layers[0].layer.label
else:
return 'Table'

def closeEvent(self, event):
"""
On close, Qt seems to scan through the entire model
Expand Down
24 changes: 24 additions & 0 deletions glue/viewers/table/qt/tests/test_data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,27 @@ def test_change_components():
assert data_changed.call_count == 2
assert layout_changed.call_count == 2
viewer.model.columnCount() == 2


def test_table_title():

app = get_qapp() # noqa

data1 = Data(a=[1, 2, 3, 4, 5], label='test1')
data2 = Data(a=[1, 2, 3, 4, 5], label='test2')

dc = DataCollection([data1, data2])

gapp = GlueApplication(dc)

viewer = gapp.new_data_viewer(TableViewer)

assert viewer.windowTitle() == 'Table'

viewer.add_data(data1)

assert viewer.windowTitle() == 'Table: test1'

viewer.add_data(data2)

assert viewer.windowTitle() == 'Table: test2'