Skip to content

Commit

Permalink
Merge pull request #2407 from Carifio24/change-title
Browse files Browse the repository at this point in the history
Add subtool for changing window title
  • Loading branch information
astrofrog authored Jun 1, 2023
2 parents c9da44e + b996115 commit 73a2679
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 5 deletions.
Binary file added glue/icons/window_tab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions glue/icons/window_tab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added glue/icons/window_title.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions glue/icons/window_title.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion glue/viewers/common/qt/data_viewer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from qtpy.QtCore import Qt
from qtpy import QtWidgets
from echo import add_callback
from glue.core.qt.layer_artist_model import QtLayerArtistContainer, LayerArtistWidget
from glue.utils.qt import set_cursor, messagebox_on_error
from glue.core.qt.dialogs import warn
Expand Down Expand Up @@ -68,7 +69,7 @@ class DataViewer(Viewer, BaseQtViewerWidget,
tools = ['save', 'window']
subtools = {
'save': [],
'window': ['window:movetab']
'window': ['window:movetab', 'window:title']
}

_close_on_last_layer_removed = True
Expand Down Expand Up @@ -107,6 +108,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)

add_callback(self.state, 'title', self._on_title_change)

self.update_window_title()

@property
Expand All @@ -131,6 +134,9 @@ def closeEvent(self, event):
if self.toolbar:
self.toolbar.cleanup()

def _on_title_change(self, title):
self.update_window_title()

def layer_view(self):
return self._view

Expand Down
27 changes: 27 additions & 0 deletions glue/viewers/common/qt/tests/test_data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,33 @@ def test_viewer_size(self, tmpdir):
app.close()
app2.close()

def test_correct_window_title(self):

# check that the viewer is displaying the correct title

d = Data(x=np.random.random((2,) * self.ndim))
dc = DataCollection([d])
app = GlueApplication(dc)
w = app.new_data_viewer(self.widget_cls, data=d)
w.state.title = "My Viewer"
assert w.parent().windowTitle() == "My Viewer"

def test_viewer_title_tool(self):

# check that the viewer title tool correctly updates the title

d = Data(x=np.random.random((2,) * self.ndim))
dc = DataCollection([d])
app = GlueApplication(dc)
w = app.new_data_viewer(self.widget_cls, data=d)

tool = w.toolbar.tools["window"].subtools[1]
with patch('glue.viewers.common.qt.tools.get_text') as gt:
gt.return_value = "My Viewer"
tool.activate()
assert w.state.title == "My Viewer"
assert w.parent().windowTitle() == "My Viewer"


class TestDataViewerScatter(BaseTestDataViewer):
widget_cls = ScatterViewer
Expand Down
18 changes: 16 additions & 2 deletions glue/viewers/common/qt/tools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from glue.config import viewer_tool
from glue.utils.qt import pick_item
from glue.utils.qt import get_text, pick_item
from glue.viewers.common.tool import Tool, SimpleToolMenu

__all__ = ['MoveTabTool', 'WindowTool']
Expand All @@ -20,7 +20,7 @@ class WindowTool(SimpleToolMenu):
@viewer_tool
class MoveTabTool(Tool):

icon = 'windows'
icon = 'window_tab'
tool_id = 'window:movetab'
action_text = 'Move to another tab'
tool_tip = 'Move viewer to another tab'
Expand All @@ -31,3 +31,17 @@ def activate(self):
tab = pick_item(range(app.tab_count), app.tab_names, title="Move Viewer", label="Select a tab", default=default)
if tab is not None:
app.move_viewer_to_tab(self.viewer, tab)


@viewer_tool
class ChangeTitleTool(Tool):

icon = 'window_title'
tool_id = 'window:title'
action_text = 'Change viewer title'
tool_tip = 'Change the viewer title'

def activate(self):
title = get_text(title="Enter a new title")
if title:
self.viewer.state.title = title
1 change: 1 addition & 0 deletions glue/viewers/common/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class ViewerState(State):
"""

layers = ListCallbackProperty(docstring='A collection of all layers in the viewer')
title = CallbackProperty(docstring='The title of the viewer')

@property
def layers_data(self):
Expand Down
3 changes: 3 additions & 0 deletions glue/viewers/common/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,9 @@ def _update_computation(self, message=None):
def _update_appearance_from_settings(self, message=None):
pass

def __str__(self):
return self.state.title or self.LABEL

def __gluestate__(self, context):
return dict(state=self.state.__gluestate__(context),
session=context.id(self._session),
Expand Down
9 changes: 7 additions & 2 deletions glue/viewers/table/qt/data_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ class TableViewer(DataViewer):
_state_cls = TableViewerState

inherit_tools = False
tools = ['table:rowselect']
tools = ['table:rowselect', 'window']
subtools = {
'window': ['window:movetab', 'window:title']
}

def __init__(self, session, state=None, parent=None, widget=None):

Expand Down Expand Up @@ -376,7 +379,9 @@ def add_subset(self, subset):

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

0 comments on commit 73a2679

Please sign in to comment.