Skip to content

Commit

Permalink
Merge pull request #1116 from mantidproject/1115-metadata-copy
Browse files Browse the repository at this point in the history
Copy everything from metadata dialog
  • Loading branch information
samtygier-stfc authored Aug 26, 2021
2 parents 3bdaf51 + cb9d80f commit d2e585b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/release_notes/next.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ Fixes
- #1093: TIFF output blank if NaN in stack
- #1095: AttributeError loading 180 deg projection
- #1110: Segmentation fault COR table refine
- #1115: Copy everything from metadata dialog

Developer Changes
-----------------
Expand Down
18 changes: 17 additions & 1 deletion mantidimaging/gui/windows/stack_visualiser/metadata_dialog.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Copyright (C) 2021 ISIS Rutherford Appleton Laboratory UKRI
# SPDX - License - Identifier: GPL-3.0-or-later

from PyQt5.QtWidgets import QWidget, QTreeWidget, QTreeWidgetItem, QDialog, QDialogButtonBox, QVBoxLayout
import json

from PyQt5.QtWidgets import (QWidget, QTreeWidget, QTreeWidgetItem, QDialog, QDialogButtonBox, QVBoxLayout, QShortcut,
QPushButton)
from PyQt5.QtGui import QKeySequence, QGuiApplication

from mantidimaging.core.data import Images
from mantidimaging.core.operation_history import const
Expand All @@ -18,16 +22,24 @@ def __init__(self, parent: QWidget, images: Images):
self.setSizeGripEnabled(True)
self.resize(600, 300)

self.metadata = images.metadata
main_widget = MetadataDialog.build_metadata_tree(images.metadata)

buttons = QDialogButtonBox(QDialogButtonBox.Ok)
buttons.accepted.connect(self.accept)

copy_button = QPushButton("Copy")
buttons.addButton(copy_button, QDialogButtonBox.ActionRole)
copy_button.clicked.connect(self.copy_metadata_to_clipboard)

layout = QVBoxLayout()
layout.addWidget(main_widget)
layout.addWidget(buttons)
self.setLayout(layout)

shortcut = QShortcut(QKeySequence("Ctrl+C"), self)
shortcut.activated.connect(self.copy_metadata_to_clipboard)

@staticmethod
def build_metadata_tree(metadata):
"""
Expand Down Expand Up @@ -72,3 +84,7 @@ def _build_operation_history(main_widget, metadata):
for kw, val in op[const.OPERATION_KEYWORD_ARGS].items():
kwargs_item = QTreeWidgetItem(kwargs_list_item)
kwargs_item.setText(0, f"{kw}: {val}")

def copy_metadata_to_clipboard(self):
meta_data_as_text = json.dumps(self.metadata, indent=4)
QGuiApplication.clipboard().setText(meta_data_as_text)

0 comments on commit d2e585b

Please sign in to comment.