Skip to content

Commit

Permalink
Re #4048 Add copy-to-clipboard to data catalog
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Jan 5, 2012
1 parent 79a0260 commit 267e6b4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,25 @@ def __init__(self, parent=None):
self._settings.data_updated.connect(self._data_updated)

def initialize_content(self):
self.copyAction = QtGui.QAction("Copy", self)
self.copyAction.setShortcut("Ctrl+C")
self.addAction(self.copyAction)

self.connect(self.copyAction, QtCore.SIGNAL("triggered()"), self.copyCells)
self._content.data_set_table.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.connect(self._content.data_set_table, QtCore.SIGNAL("customContextMenuRequested(QPoint)"), self.tableWidgetContext)
self.connect(self._content.refresh_button, QtCore.SIGNAL("clicked()"), self._update_content)
self.connect(self._content.browse_button, QtCore.SIGNAL("clicked()"), self._browse_directory)
self.connect(self._content.directory_edit, QtCore.SIGNAL("returnPressed()"), self._update_content)
self._content.directory_edit.setText(self._settings.data_path)
self._update_content(False)

def tableWidgetContext(self, point):
'''Create a menu for the tableWidget and associated actions'''
tw_menu = QtGui.QMenu("Menu", self)
tw_menu.addAction(self.copyAction)
tw_menu.exec_(self.mapToGlobal(point))

def is_running(self, is_running):
"""
Enable/disable controls depending on whether a reduction is running or not
Expand Down Expand Up @@ -87,6 +100,28 @@ def _data_updated(self, key, value):
else:
print "SANSCatalogWidget: Could not access local data catalog"

def copyCells(self):
indices = self._content.data_set_table.selectedIndexes()
if len(indices)==0:
return

col_count = self._content.data_set_table.columnCount()
rows = []
for r in indices:
if r.row() not in rows:
rows.append(r.row())

selected_text = ""
for row in rows:
for i in range(col_count):
data = self._content.data_set_table.item(row,i)
if data is not None:
selected_text += str(data.text())
if i<col_count-1:
selected_text += '\t'
selected_text += '\n'

QtGui.QApplication.clipboard().setText(selected_text)

def _update_content(self, process_files=True):
self._settings.data_path = str(self._content.directory_edit.text())
Expand Down
3 changes: 3 additions & 0 deletions Code/Mantid/scripts/Interface/ui/data_catalog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
</widget>
</item>
<item>
Expand Down
3 changes: 2 additions & 1 deletion Code/Mantid/scripts/Interface/ui/ui_data_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Form implementation generated from reading ui file 'ui/data_catalog.ui'
#
# Created: Wed Nov 16 13:57:36 2011
# Created: Thu Jan 5 16:52:14 2012
# by: PyQt4 UI code generator 4.7.4
#
# WARNING! All changes made in this file will be lost!
Expand All @@ -23,6 +23,7 @@ def setupUi(self, Frame):
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.data_set_table.sizePolicy().hasHeightForWidth())
self.data_set_table.setSizePolicy(sizePolicy)
self.data_set_table.setSelectionBehavior(QtGui.QAbstractItemView.SelectRows)
self.data_set_table.setObjectName("data_set_table")
self.data_set_table.setColumnCount(0)
self.data_set_table.setRowCount(0)
Expand Down

0 comments on commit 267e6b4

Please sign in to comment.