Commit 14f2e4ca authored by Yan's avatar Yan
Browse files

Delete row on Delete keyPressEvent in DRL menu

parent 54b963f7
......@@ -185,30 +185,34 @@ 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):
# TODO: maybe nicer selection in future, but this works for now
rows = reversed(list(set(
map(lambda x: x.row(), ptable.selectedIndexes()))))
for row in rows:
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))
delete_row(row, ptable, dtable, ds, drlspectrum)
def add_line(ds, parenttable, daughtertable, drlspectrum):
......@@ -374,6 +378,13 @@ def print_graph(labels, ptable, dtable, ds):
widget.close()
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)
def main_window(parent, ds, filename, cache):
"""constructs a dialog window"""
def saveonclose(widget, event, buffer, ptable, dautable, canvas):
......@@ -422,6 +433,9 @@ def main_window(parent, ds, filename, cache):
dtable = cache[1]
graph_canvas = cache[2]
window.keyPressEvent = lambda event: key_pressed(
event, pt, dtable, ds, chromplot)
btn_add.clicked.connect(lambda: add_line(
ds, pt, dtable, chromplot))
btn_rem.clicked.connect(lambda: remove_rows(
......
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