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

Added a new metadata/header viewer for datasets/subsets #1659

Merged
merged 2 commits into from
Apr 14, 2018
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
4 changes: 3 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Full changelog
v0.13.0 (unreleased)
--------------------

* Added a new metadata/header viewer for datasets/subsets. [#1659]

* Re-write spectrum viewer into a generic profile viewer that uses
subsets to define the areas in which to compute profiles rather
than custom ROIs. [#1635]
Expand Down Expand Up @@ -114,7 +116,7 @@ v0.13.0 (unreleased)

* Added a new selection mode that always forces the creation of a new subset.
[#1525]

* Added a mouse over pixel selection tool, which creates a one pixel subset
under the mouse cursor. [#1619]

Expand Down
1 change: 1 addition & 0 deletions doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
('py:class', 'PyQt5.QtWidgets.QLabel'),
('py:class', 'PyQt5.QtWidgets.QComboBox'),
('py:class', 'PyQt5.QtWidgets.QMessageBox'),
('py:class', 'PyQt5.QtWidgets.QDialog'),
('py:class', 'PyQt5.QtWidgets.QToolBar'),
('py:class', 'PyQt5.QtWidgets.QStyledItemDelegate'),
('py:class', 'PyQt5.QtCore.QMimeData'),
Expand Down
20 changes: 20 additions & 0 deletions glue/app/qt/layer_tree_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from glue.utils.qt import load_ui
from glue.core.message import EditSubsetMessage
from glue.core.hub import HubListener
from glue.app.qt.metadata import MetadataDialog


@core.decorators.singleton
Expand Down Expand Up @@ -143,6 +144,24 @@ def _do_action(self):
parent=self._layer_tree, default=default)


class MetadataAction(LayerAction):

_title = "View metadata/header"
_tooltip = "View metadata/header"
_shortcut = QtGui.QKeySequence('Ctrl+I')

def _can_trigger(self):
return self.single_selection_data() or self.single_selection_subset()

def _do_action(self):
layers = self.selected_layers()
if isinstance(layers[0], core.Subset):
data = layers[0].data
else:
data = layers[0]
MetadataDialog(data).exec_()


class NewAction(LayerAction):
_title = "New Subset"
_tooltip = "Create a new subset"
Expand Down Expand Up @@ -556,6 +575,7 @@ def _create_actions(self):
self._actions['clear'] = ClearAction(self)
self._actions['delete'] = DeleteAction(self)
self._actions['facet'] = FacetAction(self)
self._actions['metadata'] = MetadataAction(self)
self._actions['merge'] = MergeAction(self)
self._actions['maskify'] = MaskifySubsetAction(self)
self._actions['link'] = LinkAction(self)
Expand Down
38 changes: 38 additions & 0 deletions glue/app/qt/metadata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from __future__ import absolute_import, division, print_function

import os
from collections import OrderedDict

from qtpy import QtWidgets
from qtpy.QtCore import Qt

from glue.utils.qt import load_ui, CenteredDialog

__all__ = ['MetadataDialog']


class MetadataDialog(CenteredDialog):
"""
A dialog to view the metadata in a data object.
"""

def __init__(self, data, *args, **kwargs):

super(MetadataDialog, self).__init__(*args, **kwargs)

self.ui = load_ui('metadata.ui', self, directory=os.path.dirname(__file__))

self.resize(400, 500)
self.setWindowFlags(Qt.Window | Qt.WindowStaysOnTopHint)

self._text = ""
for name, value in OrderedDict(data.coords.header).items():
QtWidgets.QTreeWidgetItem(self.ui.meta_tree.invisibleRootItem(), [name, str(value)])

if data.label:
self.setWindowTitle("Metadata for {0}".format(data.label))

self.ui.label_ndim.setText(str(data.ndim))
self.ui.label_shape.setText(str(data.shape))

self.center()
133 changes: 133 additions & 0 deletions glue/app/qt/metadata.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>362</width>
<height>397</height>
</rect>
</property>
<property name="windowTitle">
<string>Metadata viewer</string>
</property>
<property name="sizeGripEnabled">
<bool>false</bool>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="verticalSpacing">
<number>5</number>
</property>
<item row="0" column="2">
<widget class="QLabel" name="label_ndim">
<property name="text">
<string>ndim</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="label_shape">
<property name="text">
<string>shape</string>
</property>
</widget>
</item>
<item row="0" column="0">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Data shape:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string>Number of dimensions:</string>
</property>
</widget>
</item>
<item row="0" column="3">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>5</width>
<height>5</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QTreeWidget" name="meta_tree">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="selectionMode">
<enum>QAbstractItemView::NoSelection</enum>
</property>
<property name="uniformRowHeights">
<bool>true</bool>
</property>
<property name="itemsExpandable">
<bool>true</bool>
</property>
<property name="wordWrap">
<bool>false</bool>
</property>
<property name="expandsOnDoubleClick">
<bool>false</bool>
</property>
<column>
<property name="text">
<string>Keyword</string>
</property>
</column>
<column>
<property name="text">
<string>Value</string>
</property>
</column>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
19 changes: 4 additions & 15 deletions glue/app/qt/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
from qtpy.QtCore import Qt

from glue.utils import nonpartial
from glue.utils.qt import load_ui
from glue.utils.qt import load_ui, CenteredDialog
from glue._deps import get_status_as_odict

__all__ = ['QVersionsDialog']


class QVersionsDialog(QtWidgets.QDialog):
class QVersionsDialog(CenteredDialog):

def __init__(self, *args, **kwargs):

Expand All @@ -30,28 +30,17 @@ def __init__(self, *args, **kwargs):
self._clipboard = QtWidgets.QApplication.clipboard()
self.ui.button_copy.clicked.connect(nonpartial(self._copy))



def _update_deps(self):
status = get_status_as_odict()
self._text = ""
for name, version in [('Glue', __version__)] + list(status.items()):
check = QtWidgets.QTreeWidgetItem(self.ui.version_tree.invisibleRootItem(),
[name, version])
QtWidgets.QTreeWidgetItem(self.ui.version_tree.invisibleRootItem(),
[name, version])
self._text += "{0}: {1}\n".format(name, version)

def _copy(self):
self._clipboard.setText(self._text)

def center(self):
# Adapted from StackOverflow
# https://stackoverflow.com/questions/20243637/pyqt4-center-window-on-active-screen
frameGm = self.frameGeometry()
screen = QtWidgets.QApplication.desktop().screenNumber(QtWidgets.QApplication.desktop().cursor().pos())
centerPoint = QtWidgets.QApplication.desktop().screenGeometry(screen).center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())


if __name__ == "__main__":

Expand Down
1 change: 1 addition & 0 deletions glue/core/data_factories/fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ def new_data():
)
data = Data(label=label)
data.coords = coords
data.meta.update(OrderedDict(hdu.header))
groups[hdu_name] = data
extension_by_shape[shape] = hdu_name
return data
Expand Down
17 changes: 16 additions & 1 deletion glue/utils/qt/dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from qtpy import QtWidgets

__all__ = ['pick_item', 'pick_class', 'get_text']
__all__ = ['pick_item', 'pick_class', 'get_text', 'CenteredDialog']


def pick_item(items, labels, title="Pick an item", label="Pick an item",
Expand Down Expand Up @@ -84,3 +84,18 @@ def get_text(title='Enter a label', default=None):
result, isok = QtWidgets.QInputDialog.getText(None, title, title, text=default)
if isok:
return str(result)


class CenteredDialog(QtWidgets.QDialog):
"""
A dialog that is centered on the screen.
"""

def center(self):
# Adapted from StackOverflow
# https://stackoverflow.com/questions/20243637/pyqt4-center-window-on-active-screen
frameGm = self.frameGeometry()
screen = QtWidgets.QApplication.desktop().screenNumber(QtWidgets.QApplication.desktop().cursor().pos())
centerPoint = QtWidgets.QApplication.desktop().screenGeometry(screen).center()
frameGm.moveCenter(centerPoint)
self.move(frameGm.topLeft())