From 306f72129b5f2e091199d3bdc0276a7b46733272 Mon Sep 17 00:00:00 2001 From: Keith Brown Date: Tue, 11 Mar 2014 16:13:39 +0000 Subject: [PATCH] Refs #9043 Dealing with line endings differently I've been told about os.linesep so i'm using that instead, as well as suing a different way of checking for empty rows. --- .../Interface/ui/reflectometer/refl_gui.py | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py index 3c4ea09c4dd2..b5a10015cc25 100644 --- a/Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py +++ b/Code/Mantid/scripts/Interface/ui/reflectometer/refl_gui.py @@ -6,6 +6,7 @@ import refl_choose_col import csv import string +import os from PyQt4 import QtCore, QtGui from mantid.simpleapi import * from isis_reflectometry.quick import * @@ -355,21 +356,23 @@ def paste_cells(self): logger.warning("Cannot paste, no editable cells selected") return #convert line endings to windows-style - pastedtext = string.replace(pastedtext, '\r\n', '\n') - pastedtext = string.replace(pastedtext, '\n\r', '\n') - pastedtext = string.replace(pastedtext, '\r', '\n') + #pastedtext = string.replace(pastedtext, '\r\n', '\n') + #pastedtext = string.replace(pastedtext, '\n\r', '\n') + #pastedtext = string.replace(pastedtext, '\r', '\n') ''' 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') + pasted = pastedtext.split(os.linesep) pastedcells = [] for row in pasted: pastedcells.append(row.split('\t')) @@ -386,8 +389,9 @@ def paste_cells(self): for cell in selected: row = cell.row() col = cell.column() - if col < 17 and (col - mincol) < pastedcols and (row - minrow) < pastedrows: - cell.setText(pastedcells[row - minrow][col - mincol]) + if len(pastedcells[row - minrow]): + if col < 17 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] @@ -395,20 +399,21 @@ def paste_cells(self): homecol = cell.column() tablerows = self.tableMain.rowCount() for row in pastedcells: - curcol = homecol - if currow < tablerows: - for col in row: - if curcol < 17: - 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 + if len(row): + curcol = homecol + if currow < tablerows: + for col in row: + if curcol < 17: + 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):