diff --git a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_choose_col.py b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_choose_col.py new file mode 100644 index 000000000000..0f1d288a15d7 --- /dev/null +++ b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_choose_col.py @@ -0,0 +1,33 @@ +#This is an extension of refl_columns.py as that is a auto-generated script form pyqt and shouldn't be edited +#so this file provides any extra GUI tweaks not easily doable in the designer +#for the time being this also includes non-GUI behaviour +import refl_columns +from PyQt4 import QtCore, QtGui + +try: + _fromUtf8 = QtCore.QString.fromUtf8 +except AttributeError: + _fromUtf8 = lambda s: s + +class ReflChoose(refl_columns.Ui_ChooseColumnsDialog): + visiblestates = {} + def setupUi(self, Dialog, ColHeaders, table): + super(ReflChoose, self).setupUi(Dialog) + self.visiblestates.clear() + self.listColumns.itemChanged.connect(self.on_listColumns_itemChanged) + self.buttonsColumns.clicked.connect(self.on_buttonsColumns_Clicked) + for key, value in ColHeaders.iteritems(): + header = table.horizontalHeaderItem(key).text() + item = QtGui.QListWidgetItem(header) + if value: + item.setCheckState(2) + else: + item.setCheckState(0) + self.listColumns.insertItem(key, item) + def on_listColumns_itemChanged(self, item): + colno=self.listColumns.row(item) + self.visiblestates[colno] = (item.checkState() > 0) + def on_buttonsColumns_Clicked(self, button): + if self.buttonsColumns.button(QtGui.QDialogButtonBox.RestoreDefaults) == button: + for i in range(self.listColumns.count()): + self.listColumns.item(i).setCheckState(2) \ No newline at end of file diff --git a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_columns.py b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_columns.py new file mode 100644 index 000000000000..f192456cb315 --- /dev/null +++ b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_columns.py @@ -0,0 +1,56 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'D:\mantid\windows\Code\Mantid\scripts\Interface\ui\reflectometer/refl_columns.ui' +# +# Created: Mon Mar 10 10:17:57 2014 +# by: PyQt4 UI code generator 4.8.3 +# +# WARNING! All changes made in this file will be lost! + +from PyQt4 import QtCore, QtGui + +try: + _fromUtf8 = QtCore.QString.fromUtf8 +except AttributeError: + _fromUtf8 = lambda s: s + +class Ui_ChooseColumnsDialog(object): + def setupUi(self, ChooseColumnsDialog): + ChooseColumnsDialog.setObjectName(_fromUtf8("ChooseColumnsDialog")) + ChooseColumnsDialog.resize(231, 300) + ChooseColumnsDialog.setSizeGripEnabled(False) + self.verticalLayout = QtGui.QVBoxLayout(ChooseColumnsDialog) + self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) + self.labelColumns = QtGui.QLabel(ChooseColumnsDialog) + self.labelColumns.setObjectName(_fromUtf8("labelColumns")) + self.verticalLayout.addWidget(self.labelColumns) + self.layoutListButtons = QtGui.QHBoxLayout() + self.layoutListButtons.setObjectName(_fromUtf8("layoutListButtons")) + self.listColumns = QtGui.QListWidget(ChooseColumnsDialog) + self.listColumns.setEditTriggers(QtGui.QAbstractItemView.NoEditTriggers) + self.listColumns.setSelectionMode(QtGui.QAbstractItemView.NoSelection) + self.listColumns.setObjectName(_fromUtf8("listColumns")) + self.layoutListButtons.addWidget(self.listColumns) + self.buttonsColumns = QtGui.QDialogButtonBox(ChooseColumnsDialog) + sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Expanding) + sizePolicy.setHorizontalStretch(0) + sizePolicy.setVerticalStretch(0) + sizePolicy.setHeightForWidth(self.buttonsColumns.sizePolicy().hasHeightForWidth()) + self.buttonsColumns.setSizePolicy(sizePolicy) + self.buttonsColumns.setLayoutDirection(QtCore.Qt.LeftToRight) + self.buttonsColumns.setOrientation(QtCore.Qt.Vertical) + self.buttonsColumns.setStandardButtons(QtGui.QDialogButtonBox.Cancel|QtGui.QDialogButtonBox.Ok|QtGui.QDialogButtonBox.RestoreDefaults) + self.buttonsColumns.setCenterButtons(False) + self.buttonsColumns.setObjectName(_fromUtf8("buttonsColumns")) + self.layoutListButtons.addWidget(self.buttonsColumns) + self.verticalLayout.addLayout(self.layoutListButtons) + + self.retranslateUi(ChooseColumnsDialog) + QtCore.QObject.connect(self.buttonsColumns, QtCore.SIGNAL(_fromUtf8("accepted()")), ChooseColumnsDialog.accept) + QtCore.QObject.connect(self.buttonsColumns, QtCore.SIGNAL(_fromUtf8("rejected()")), ChooseColumnsDialog.reject) + QtCore.QMetaObject.connectSlotsByName(ChooseColumnsDialog) + + def retranslateUi(self, ChooseColumnsDialog): + ChooseColumnsDialog.setWindowTitle(QtGui.QApplication.translate("ChooseColumnsDialog", "Choose Columns...", None, QtGui.QApplication.UnicodeUTF8)) + self.labelColumns.setText(QtGui.QApplication.translate("ChooseColumnsDialog", "Choose columns to display", None, QtGui.QApplication.UnicodeUTF8)) + diff --git a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_columns.ui b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_columns.ui new file mode 100644 index 000000000000..faecc6b09eea --- /dev/null +++ b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_columns.ui @@ -0,0 +1,100 @@ + + + ChooseColumnsDialog + + + + 0 + 0 + 231 + 300 + + + + Choose Columns... + + + false + + + + + + Choose columns to display + + + + + + + + + QAbstractItemView::NoEditTriggers + + + QAbstractItemView::NoSelection + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Qt::Vertical + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok|QDialogButtonBox::RestoreDefaults + + + false + + + + + + + + + + + buttonsColumns + accepted() + ChooseColumnsDialog + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonsColumns + rejected() + ChooseColumnsDialog + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py index a827148250bc..05e08fe9a302 100644 --- a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py +++ b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py @@ -3,6 +3,7 @@ #for the time being this also includes non-GUI behaviour import refl_window import refl_save +import refl_choose_col import csv from PyQt4 import QtCore, QtGui from mantid.simpleapi import * @@ -10,7 +11,6 @@ from isis_reflectometry import load_live_runs from isis_reflectometry.combineMulti import * from latest_isis_runs import * - from mantid.api import Workspace, WorkspaceGroup try: @@ -49,7 +49,7 @@ def on_comboInstrument_activated(self, instrument): self.populateList() self.current_instrument = self.instrument_list[instrument] self.comboPolarCorrect.setEnabled(self.current_instrument in self.polarisation_instruments) # Enable as appropriate - self.comboPolarCorrect.setCurrentIndex(self.comboPolarCorrect.findText('None')) # Reset to None + self.comboPolarCorrect.setCurrentIndex(self.comboPolarCorrect.findText('None')) # Reset to None def on_actionOpen_Table_triggered(self): self.loadTable() def on_actionReload_from_Disk_triggered(self): @@ -72,6 +72,17 @@ def on_tableMain_modified(self, row, column): def on_plotButton_clicked(self): plotbutton = self.windowRefl.sender() self.plot(plotbutton) + def actionCopy_triggered(self): + self.copy_cells() + def actionCut_triggered(self): + self.copy_cells() + self.clear_cells() + def actionPaste_triggered(self): + self.paste_cells() + def actionClear_triggered(self): + self.clear_cells() + def actionChoose_Columns_triggered(self): + self.chooseColumns() ''' Event handler for polarisation correction selection. ''' @@ -83,8 +94,9 @@ def on_comboPolarCorr_activated(self): logger.notice("Polarisation correction is not supported on " + str(self.current_instrument)) def setupUi(self, windowRefl): super(ReflGui,self).setupUi(windowRefl) + self.shownCols = {} self.loading = False - + self.clip = QtGui.QApplication.clipboard() ''' Setup instrument options with defaults assigned. ''' @@ -136,6 +148,9 @@ def initTable(self): return self.current_table = None self.accMethod = None + settings = QtCore.QSettings() + settings.beginGroup("Mantid/ISISReflGui/Columns") + for column in range(self.tableMain.columnCount()): for row in range(self.tableMain.rowCount()): if (column == 0) or (column == 5) or (column == 10): @@ -180,6 +195,14 @@ def initTable(self): item = QtGui.QTableWidgetItem() item.setText('') self.tableMain.setItem(row, column, item) + vis_state = settings.value(str(column), True, type=bool) + self.shownCols[column] = vis_state + if vis_state: + self.tableMain.showColumn(column) + else: + self.tableMain.hideColumn(column) + settings.endGroup() + del settings self.tableMain.resizeColumnsToContents() self.windowRefl.modFlag = False @@ -205,6 +228,11 @@ def connectSlots(self): self.actionClear_Table.triggered.connect(self.on_buttonClear_clicked) self.actionProcess.triggered.connect(self.on_buttonProcess_clicked) self.actionTransfer.triggered.connect(self.on_buttonTransfer_clicked) + self.actionClear.triggered.connect(self.actionClear_triggered) + self.actionPaste.triggered.connect(self.actionPaste_triggered) + self.actionCut.triggered.connect(self.actionCut_triggered) + self.actionCopy.triggered.connect(self.actionCopy_triggered) + self.actionChoose_Columns.triggered.connect(self.actionChoose_Columns_triggered) self.tableMain.cellChanged.connect(self.on_tableMain_modified) def populateList(self): # Clear existing @@ -274,7 +302,113 @@ def create_workspace_display_name(self, candidate): else: todisplay = groupGet(mtd[candidate], "samp", "run_number") return todisplay - + def clear_cells(self): + cells = self.tableMain.selectedItems() + for cell in cells: + column = cell.column() + if not (column == 17 or column == 18): + cell.setText('') + def copy_cells(self): + cells = self.tableMain.selectedItems() + if not cells: + print 'nothing to copy' + return + #first discover the size of the selection and initialise a list + mincol = cells[0].column() + if mincol == 17 or mincol == 18: + return + logger.error("Cannot copy, all cells out of range") + maxrow = -1 + maxcol = -1 + minrow = cells[0].row() + for cell in reversed(range(len(cells))): + col = cells[cell].column() + if col != 17 and col != 18: + maxcol = col + maxrow = cells[cell].row() + break + colsize = maxcol - mincol + 1 + rowsize = maxrow - minrow + 1 + selection = [['' for x in range(colsize)] for y in range(rowsize)] + #now fill that list + for cell in cells: + row = cell.row() + col = cell.column() + if col != 17 and col != 18: + selection[row - minrow][col - mincol] = str(cell.text()) + tocopy = '' + for y in range(rowsize): + for x in range(colsize): + if x > 0: + tocopy += '\t' + tocopy += selection[y][x] + if y < (rowsize - 1): + tocopy += '\n' + self.copy_to_clipboard(tocopy) + def paste_cells(self): + pastedtext = self.clip.text() + if not pastedtext: + logger.warning("Nothing to Paste") + return + selected = self.tableMain.selectedItems() + if not selected: + logger.warning("Cannot paste, no editable cells selected") + return + ''' + quickly check if the last row is a single cell and blank + MS excel adds a line break at the end of copied cells which can mess with this a bit + I'd like this to be compatible both ways + ''' + if pastedtext[-1] == '\n': + pastedtext = pastedtext[:-1] + #if the string is now empty the only thing on the clipboard as a line break + if not pastedtext: + logger.warning("Nothing to Paste") + return + pasted = pastedtext.split('\n') + pastedcells = [] + for row in pasted: + pastedcells.append(row.split('\t')) + pastedcols = len(pastedcells[0]) + pastedrows = len(pastedcells) + if len(selected) > 1: + #discover the size of the selection + mincol = selected[0].column() + if mincol == 17 or mincol == 18: + return + logger.error("Cannot copy, all cells out of range") + minrow = selected[0].row() + #now fill that list + for cell in selected: + row = cell.row() + col = cell.column() + if col != 17 and col != 18 and (col - mincol) < pastedcols and (row - minrow) < pastedrows: + cell.setText(pastedcells[row - minrow][col - mincol]) + elif selected: + #when only a single cell is selected, paste all the copied item up until the table limits + cell = selected[0] + currow = cell.row() + homecol = cell.column() + tablerows = self.tableMain.rowCount() + for row in pastedcells: + curcol = homecol + if currow < tablerows: + for col in row: + if curcol != 17 and curcol != 18: + curcell = self.tableMain.item(currow, curcol) + curcell.setText(col) + curcol += 1 + else: + #the row has hit the end of the editable cells + break + currow += 1 + else: + #it's dropped off the bottom of the table + break + else: + logger.warning("Cannot paste, no editable cells selected") + def copy_to_clipboard(self,text): + self.clip.setText(str(text)) def transfer(self): col = 0 row = 0 @@ -653,6 +787,26 @@ def saveWorkspaces(self): except Exception as ex: logger.notice("Could not open save workspace dialog") logger.notice(str(ex)) + def chooseColumns(self): + try: + Dialog = QtGui.QDialog() + u = refl_choose_col.ReflChoose() + u.setupUi(Dialog, self.shownCols, self.tableMain) + if Dialog.exec_(): + settings = QtCore.QSettings() + settings.beginGroup("Mantid/ISISReflGui/Columns") + for key, value in u.visiblestates.iteritems(): + self.shownCols[key] = value + settings.setValue(str(key), value) + if value: + self.tableMain.showColumn(key) + else: + self.tableMain.hideColumn(key) + settings.endGroup() + del settings + except Exception as ex: + logger.notice("Could not open choose columns dialog") + logger.notice(str(ex)) def showHelp(self): import webbrowser webbrowser.open('http://www.mantidproject.org/ISIS_Reflectometry_GUI') diff --git a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_window.py b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_window.py index 07aa3b689e6c..183c30cf980a 100644 --- a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_window.py +++ b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_window.py @@ -2,7 +2,7 @@ # Form implementation generated from reading ui file 'D:\mantid\windows\Code\Mantid\scripts\Interface\ui\reflectometer/refl_window.ui' # -# Created: Tue Feb 25 11:55:14 2014 +# Created: Mon Mar 10 10:17:57 2014 # by: PyQt4 UI code generator 4.8.3 # # WARNING! All changes made in this file will be lost! @@ -134,7 +134,9 @@ def setupUi(self, windowRefl): font.setWeight(50) font.setBold(False) self.tableMain.setFont(font) + self.tableMain.setEditTriggers(QtGui.QAbstractItemView.AnyKeyPressed|QtGui.QAbstractItemView.DoubleClicked|QtGui.QAbstractItemView.EditKeyPressed|QtGui.QAbstractItemView.SelectedClicked) self.tableMain.setAlternatingRowColors(True) + self.tableMain.setSelectionMode(QtGui.QAbstractItemView.ContiguousSelection) self.tableMain.setRowCount(100) self.tableMain.setColumnCount(19) self.tableMain.setObjectName(_fromUtf8("tableMain")) @@ -178,10 +180,13 @@ def setupUi(self, windowRefl): self.tableMain.setHorizontalHeaderItem(17, item) item = QtGui.QTableWidgetItem() self.tableMain.setHorizontalHeaderItem(18, item) - self.tableMain.horizontalHeader().setCascadingSectionResizes(True) + self.tableMain.horizontalHeader().setCascadingSectionResizes(False) self.tableMain.horizontalHeader().setDefaultSectionSize(60) self.tableMain.horizontalHeader().setMinimumSectionSize(20) + self.tableMain.horizontalHeader().setStretchLastSection(False) + self.tableMain.verticalHeader().setCascadingSectionResizes(False) self.tableMain.verticalHeader().setDefaultSectionSize(20) + self.tableMain.verticalHeader().setStretchLastSection(False) self.layoutTableColumn.addWidget(self.tableMain) self.layoutTableButton = QtGui.QHBoxLayout() self.layoutTableButton.setObjectName(_fromUtf8("layoutTableButton")) @@ -209,6 +214,10 @@ def setupUi(self, windowRefl): self.menuHelp.setObjectName(_fromUtf8("menuHelp")) self.menuFunction = QtGui.QMenu(self.menuBar) self.menuFunction.setObjectName(_fromUtf8("menuFunction")) + self.menuEdit = QtGui.QMenu(self.menuBar) + self.menuEdit.setObjectName(_fromUtf8("menuEdit")) + self.menuView = QtGui.QMenu(self.menuBar) + self.menuView.setObjectName(_fromUtf8("menuView")) windowRefl.setMenuBar(self.menuBar) self.statusMain = QtGui.QStatusBar(windowRefl) font = QtGui.QFont() @@ -240,6 +249,16 @@ def setupUi(self, windowRefl): self.actionClear_Table.setObjectName(_fromUtf8("actionClear_Table")) self.actionSearch_RB = QtGui.QAction(windowRefl) self.actionSearch_RB.setObjectName(_fromUtf8("actionSearch_RB")) + self.actionCopy = QtGui.QAction(windowRefl) + self.actionCopy.setObjectName(_fromUtf8("actionCopy")) + self.actionPaste = QtGui.QAction(windowRefl) + self.actionPaste.setObjectName(_fromUtf8("actionPaste")) + self.actionCut = QtGui.QAction(windowRefl) + self.actionCut.setObjectName(_fromUtf8("actionCut")) + self.actionClear = QtGui.QAction(windowRefl) + self.actionClear.setObjectName(_fromUtf8("actionClear")) + self.actionChoose_Columns = QtGui.QAction(windowRefl) + self.actionChoose_Columns.setObjectName(_fromUtf8("actionChoose_Columns")) self.menuFile.addAction(self.actionOpen_Table) self.menuFile.addAction(self.actionReload_from_Disk) self.menuFile.addSeparator() @@ -256,7 +275,14 @@ def setupUi(self, windowRefl): self.menuFunction.addAction(self.actionClear_Table) self.menuFunction.addSeparator() self.menuFunction.addAction(self.actionSearch_RB) + self.menuEdit.addAction(self.actionCopy) + self.menuEdit.addAction(self.actionCut) + self.menuEdit.addAction(self.actionPaste) + self.menuEdit.addAction(self.actionClear) + self.menuView.addAction(self.actionChoose_Columns) self.menuBar.addAction(self.menuFile.menuAction()) + self.menuBar.addAction(self.menuEdit.menuAction()) + self.menuBar.addAction(self.menuView.menuAction()) self.menuBar.addAction(self.menuFunction.menuAction()) self.menuBar.addAction(self.menuHelp.menuAction()) self.labelInstrument.setBuddy(self.comboInstrument) @@ -324,6 +350,8 @@ def retranslateUi(self, windowRefl): self.menuFile.setTitle(QtGui.QApplication.translate("windowRefl", "File", None, QtGui.QApplication.UnicodeUTF8)) self.menuHelp.setTitle(QtGui.QApplication.translate("windowRefl", "Help", None, QtGui.QApplication.UnicodeUTF8)) self.menuFunction.setTitle(QtGui.QApplication.translate("windowRefl", "Function", None, QtGui.QApplication.UnicodeUTF8)) + self.menuEdit.setTitle(QtGui.QApplication.translate("windowRefl", "Edit", None, QtGui.QApplication.UnicodeUTF8)) + self.menuView.setTitle(QtGui.QApplication.translate("windowRefl", "View", None, QtGui.QApplication.UnicodeUTF8)) self.actionSave_As.setText(QtGui.QApplication.translate("windowRefl", "Save As...", None, QtGui.QApplication.UnicodeUTF8)) self.actionSave_As.setShortcut(QtGui.QApplication.translate("windowRefl", "Ctrl+Alt+S", None, QtGui.QApplication.UnicodeUTF8)) self.actionOpen_Table.setText(QtGui.QApplication.translate("windowRefl", "Open Table...", None, QtGui.QApplication.UnicodeUTF8)) @@ -348,4 +376,13 @@ def retranslateUi(self, windowRefl): self.actionClear_Table.setShortcut(QtGui.QApplication.translate("windowRefl", "Alt+C", None, QtGui.QApplication.UnicodeUTF8)) self.actionSearch_RB.setText(QtGui.QApplication.translate("windowRefl", "Search RB", None, QtGui.QApplication.UnicodeUTF8)) self.actionSearch_RB.setShortcut(QtGui.QApplication.translate("windowRefl", "Alt+R", None, QtGui.QApplication.UnicodeUTF8)) + self.actionCopy.setText(QtGui.QApplication.translate("windowRefl", "Copy", None, QtGui.QApplication.UnicodeUTF8)) + self.actionCopy.setShortcut(QtGui.QApplication.translate("windowRefl", "Ctrl+C", None, QtGui.QApplication.UnicodeUTF8)) + self.actionPaste.setText(QtGui.QApplication.translate("windowRefl", "Paste", None, QtGui.QApplication.UnicodeUTF8)) + self.actionPaste.setShortcut(QtGui.QApplication.translate("windowRefl", "Ctrl+V", None, QtGui.QApplication.UnicodeUTF8)) + self.actionCut.setText(QtGui.QApplication.translate("windowRefl", "Cut", None, QtGui.QApplication.UnicodeUTF8)) + self.actionCut.setShortcut(QtGui.QApplication.translate("windowRefl", "Ctrl+X", None, QtGui.QApplication.UnicodeUTF8)) + self.actionClear.setText(QtGui.QApplication.translate("windowRefl", "Clear", None, QtGui.QApplication.UnicodeUTF8)) + self.actionClear.setShortcut(QtGui.QApplication.translate("windowRefl", "Del", None, QtGui.QApplication.UnicodeUTF8)) + self.actionChoose_Columns.setText(QtGui.QApplication.translate("windowRefl", "Choose Columns...", None, QtGui.QApplication.UnicodeUTF8)) diff --git a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_window.ui b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_window.ui index 6e5a7f216511..111f79775a1f 100644 --- a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_window.ui +++ b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_window.ui @@ -331,9 +331,15 @@ false + + QAbstractItemView::AnyKeyPressed|QAbstractItemView::DoubleClicked|QAbstractItemView::EditKeyPressed|QAbstractItemView::SelectedClicked + true + + QAbstractItemView::ContiguousSelection + 100 @@ -341,7 +347,7 @@ 19 - true + false 60 @@ -349,9 +355,18 @@ 20 + + false + + + false + 20 + + false + @@ -621,7 +636,24 @@ + + + Edit + + + + + + + + + View + + + + + @@ -728,6 +760,43 @@ Alt+R + + + Copy + + + Ctrl+C + + + + + Paste + + + Ctrl+V + + + + + Cut + + + Ctrl+X + + + + + Clear + + + Del + + + + + Choose Columns... + + comboInstrument