Commit e42639ec authored by Yan's avatar Yan
Browse files

Copy/Paste in DRL tables, remove_rows update

* remove_rows written nicer
* copy/paste initial commit, still rough but working somehow..
parent f9ac65b4
......@@ -183,6 +183,7 @@ def ptable_changed(row, column, ptable, dtable, ds, drlspectrum):
if column in (1, 2):
update_profile(ptable, row, ds)
def dtable_changed(row, column, ptable, dtable, ds, drlspectrum):
"""routine called by change of the dtable spectra"""
if dtable.cellWidget(row, 0).checkState() == 2:
......@@ -199,34 +200,31 @@ def corr_changed(row, ptable, dtable, ds, drlspectrum):
update_drlspectrum(ptable, dtable, ds, drlspectrum)
def delete_row(row, ptable, dtable, ds, drlspectrum):
dtable.cellWidget(row,0).setCheckState(0)
dtable.removeRow(row)
ptable.removeRow(row)
for i in range(dtable.rowCount()):
corfor = dtable.cellWidget(i, 1)
corfor.disconnect()
index = corfor.currentIndex()
corfor.clear()
corfor.addItem("")
corfor.addItems(gettableitemlist(ptable))
if index == row+1:
corfor.setCurrentIndex(0)
corr_changed(i, ptable, dtable, ds, drlspectrum)
elif index > row+1:
corfor.setCurrentIndex(index-1)
else:
corfor.setCurrentIndex(index)
corfor.currentIndexChanged.connect(lambda: corr_changed(
i, ptable, dtable, ds, drlspectrum))
def remove_rows(ptable, dtable, ds, drlspectrum):
def remove_rows(ptable, dtable, ds, drlspectrum, rows=None):
# TODO: maybe nicer selection in future, but this works for now
rows = reversed(list(set(
map(lambda x: x.row(), ptable.selectedIndexes()))))
if rows == None:
rows = reversed(list(set(
map(lambda x: x.row(), ptable.selectedIndexes()))))
for row in rows:
delete_row(row, ptable, dtable, ds, drlspectrum)
dtable.cellWidget(row,0).setCheckState(0)
dtable.removeRow(row)
ptable.removeRow(row)
for i in range(dtable.rowCount()):
corfor = dtable.cellWidget(i, 1)
corfor.disconnect()
index = corfor.currentIndex()
corfor.clear()
corfor.addItem("")
corfor.addItems(gettableitemlist(ptable))
if index == row+1:
corfor.setCurrentIndex(0)
corr_changed(i, ptable, dtable, ds, drlspectrum)
elif index > row+1:
corfor.setCurrentIndex(index-1)
else:
corfor.setCurrentIndex(index)
corfor.currentIndexChanged.connect(lambda:
corr_changed(i, ptable, dtable, ds, drlspectrum))
def add_line(ds, parenttable, daughtertable, drlspectrum):
......@@ -253,12 +251,14 @@ def add_line(ds, parenttable, daughtertable, drlspectrum):
daughtertable.setRowCount(newrow + 1)
checkbox = QtWidgets.QCheckBox()
checkbox.setFocusProxy(daughtertable)
dname = QtWidgets.QTableWidgetItem()
dname.setFlags(dname.flags() & ~QtCore.Qt.ItemIsEditable)
dname.setTextAlignment(QtCore.Qt.AlignRight)
daughtertable.setItem(newrow, 0, dname)
daughtertable.setCellWidget(newrow, 0, checkbox)
corfor = QtWidgets.QComboBox()
corfor.setFocusProxy(daughtertable)
corfor.setFrame(False)
daughtertable.setCellWidget(newrow, 1, corfor)
daughtertable.setItem(newrow, 2, QtWidgets.QTableWidgetItem())
......@@ -421,15 +421,75 @@ def print_graph(labels, ptable, dtable, ds):
widget.close()
def clip_range(ptable, dtable):
activeObject = QtWidgets.QApplication.focusWidget()
if activeObject in (ptable, dtable):
table = activeObject
if len(table.selectedRanges()) == 0:
return
if len(table.selectedRanges()) > 1:
QtWidgets.QMessageBox.warning(
None, "Operation not supported",
"Operation not supported for multiple ranges,\n"
"cancelling request")
return
sr = table.selectedRanges()[0]
rows = []
for row in range(sr.topRow(), sr.bottomRow() + 1):
line = []
for col in range(sr.leftColumn(), sr.rightColumn() + 1):
if isinstance(table.cellWidget(row, col),
QtWidgets.QComboBox):
line.append(
table.cellWidget(row, col).currentText())
elif isinstance(table.item(row, col),
QtWidgets.QTableWidgetItem):
line.append(table.item(row, col).text())
rows.append(("\t").join(line))
QtWidgets.QApplication.clipboard().setText(("\n").join(rows))
def paste_clip(ptable, dtable, ds, drlspectrum):
activeObject = QtWidgets.QApplication.focusWidget()
if activeObject in (ptable, dtable)\
and activeObject.selectedRanges() != []:
table = activeObject
if len(table.selectedRanges()) > 1:
QtWidgets.QMessageBox.warning(
None, "Operation not supported",
"Operation not supported for multiple ranges,\n"
"cancelling request")
cliptext = QtWidgets.QApplication.clipboard().text()
rows = cliptext.split("\n")
startrow = table.selectedRanges()[0].topRow()
startcol = table.selectedRanges()[0].leftColumn()
for i, row in enumerate(rows, start=startrow):
cols = row.split("\t")
for j, col in enumerate(cols, start=startcol):
if table == ptable and j < 3:
if i >= (table.rowCount()):
add_line(ds, ptable, dtable, drlspectrum)
table.item(i, j).setText(col)
if table == dtable and j == 2\
and i < table.rowCount():
table.item(i,j).setText(col)
def key_pressed(event, ptable, dtable, ds, drlspectrum):
if event.key() == QtCore.Qt.Key_Delete:
for row in map(lambda x: x.row(),
ptable.selectionModel().selectedRows()):
delete_row(row, ptable, dtable, ds, drlspectrum)
rows = reversed(list(map(lambda x: x.row(),
ptable.selectionModel().selectedRows())))
remove_rows(ptable, dtable, ds, drlspectrum, rows)
if event.key() == QtCore.Qt.Key_F5:
update_drlspectrum(ptable, dtable, ds, drlspectrum)
for row in range(ptable.rowCount()):
update_profile(ptable, row, ds)
if event.key() == QtCore.Qt.Key_C\
and event.modifiers().__int__() == QtCore.Qt.ControlModifier:
clip_range(ptable, dtable)
if event.key() == QtCore.Qt.Key_V\
and event.modifiers().__int__() == QtCore.Qt.ControlModifier:
paste_clip(ptable, dtable, ds, drlspectrum)
def main_window(parent, ds, filename, cache):
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment