[update] further improved Pickfile selection dialog, now providing methods "overwrite" or "merge"
This commit is contained in:
parent
ad62284e0e
commit
356988e71d
14
PyLoT.py
14
PyLoT.py
@ -1011,11 +1011,12 @@ class MainWindow(QMainWindow):
|
|||||||
events=events)
|
events=events)
|
||||||
if not sld.exec_():
|
if not sld.exec_():
|
||||||
return
|
return
|
||||||
|
|
||||||
filenames = sld.getChecked()
|
filenames = sld.getChecked()
|
||||||
for event in events:
|
for event in events:
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
if os.path.isfile(filename) and event.pylot_id in filename:
|
if os.path.isfile(filename) and event.pylot_id in filename:
|
||||||
self.load_data(filename, draw=False, event=event, overwrite=True)
|
self.load_data(filename, draw=False, event=event, ask_user=True, merge_strategy=sld.merge_strategy)
|
||||||
refresh = True
|
refresh = True
|
||||||
if not refresh:
|
if not refresh:
|
||||||
return
|
return
|
||||||
@ -1024,8 +1025,8 @@ class MainWindow(QMainWindow):
|
|||||||
self.fill_eventbox()
|
self.fill_eventbox()
|
||||||
self.setDirty(True)
|
self.setDirty(True)
|
||||||
|
|
||||||
def load_data(self, fname=None, loc=False, draw=True, event=None, overwrite=False):
|
def load_data(self, fname=None, loc=False, draw=True, event=None, ask_user=False, merge_strategy='Overwrite'):
|
||||||
if not overwrite:
|
if not ask_user:
|
||||||
if not self.okToContinue():
|
if not self.okToContinue():
|
||||||
return
|
return
|
||||||
if fname is None:
|
if fname is None:
|
||||||
@ -1039,9 +1040,12 @@ class MainWindow(QMainWindow):
|
|||||||
data = Data(self, event)
|
data = Data(self, event)
|
||||||
try:
|
try:
|
||||||
data_new = Data(self, evtdata=str(fname))
|
data_new = Data(self, evtdata=str(fname))
|
||||||
# MP MP commented because adding several picks might cause inconsistencies
|
if merge_strategy == 'Overwrite':
|
||||||
data = data_new
|
data = data_new
|
||||||
# data += data_new
|
elif merge_strategy == 'Merge':
|
||||||
|
data += data_new
|
||||||
|
else:
|
||||||
|
raise NotImplementedError(f'Unknown merge strategy: {merge_strategy}')
|
||||||
except ValueError:
|
except ValueError:
|
||||||
qmb = QMessageBox(self, icon=QMessageBox.Question,
|
qmb = QMessageBox(self, icon=QMessageBox.Question,
|
||||||
text='Warning: Missmatch in event identifiers {} and {}. Continue?'.format(
|
text='Warning: Missmatch in event identifiers {} and {}. Continue?'.format(
|
||||||
|
@ -1577,6 +1577,7 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
|
|||||||
self.filepaths = []
|
self.filepaths = []
|
||||||
self.file_extensions = []
|
self.file_extensions = []
|
||||||
self.check_all_state = True
|
self.check_all_state = True
|
||||||
|
self.merge_strategy = None
|
||||||
self.default_text = default_text
|
self.default_text = default_text
|
||||||
self.label = label
|
self.label = label
|
||||||
self.setButtons()
|
self.setButtons()
|
||||||
@ -1611,6 +1612,15 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
|
|||||||
# check/uncheck button for table
|
# check/uncheck button for table
|
||||||
self.checkAllButton = QtWidgets.QPushButton('Check/Uncheck all')
|
self.checkAllButton = QtWidgets.QPushButton('Check/Uncheck all')
|
||||||
|
|
||||||
|
# radiobutton for merge selection
|
||||||
|
self.mergeRadioButtonGroup = QtWidgets.QButtonGroup()
|
||||||
|
self.merge_button = QtWidgets.QRadioButton('Merge')
|
||||||
|
self.overwrite_button = QtWidgets.QRadioButton('Overwrite')
|
||||||
|
self.mergeRadioButtonGroup.addButton(self.merge_button)
|
||||||
|
self.mergeRadioButtonGroup.addButton(self.overwrite_button)
|
||||||
|
self.merge_button.setChecked(True)
|
||||||
|
self.merge_strategy = self.merge_button.text()
|
||||||
|
|
||||||
# table
|
# table
|
||||||
self.tableWidget = QtWidgets.QTableWidget()
|
self.tableWidget = QtWidgets.QTableWidget()
|
||||||
tableWidget = self.tableWidget
|
tableWidget = self.tableWidget
|
||||||
@ -1631,7 +1641,11 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
|
|||||||
|
|
||||||
self.footer_layout.addWidget(self.checkAllButton)
|
self.footer_layout.addWidget(self.checkAllButton)
|
||||||
self.footer_layout.addWidget(self.statusText)
|
self.footer_layout.addWidget(self.statusText)
|
||||||
|
self.footer_layout.addWidget(self.merge_button)
|
||||||
|
self.footer_layout.addWidget(self.overwrite_button)
|
||||||
|
|
||||||
self.footer_layout.setStretch(0, 0)
|
self.footer_layout.setStretch(0, 0)
|
||||||
|
self.footer_layout.setStretch(1, 1)
|
||||||
|
|
||||||
self.main_layout.addLayout(self.header_layout)
|
self.main_layout.addLayout(self.header_layout)
|
||||||
self.main_layout.addWidget(self.tableWidget)
|
self.main_layout.addWidget(self.tableWidget)
|
||||||
@ -1645,10 +1659,8 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
|
|||||||
for index, event in enumerate(self.events):
|
for index, event in enumerate(self.events):
|
||||||
filename = get_pylot_eventfile_with_extension(event, fext)
|
filename = get_pylot_eventfile_with_extension(event, fext)
|
||||||
pf_selected_item = QtWidgets.QTableWidgetItem()
|
pf_selected_item = QtWidgets.QTableWidgetItem()
|
||||||
if filename:
|
check_state = QtCore.Qt.Checked if filename else QtCore.Qt.Unchecked
|
||||||
pf_selected_item.setCheckState(QtCore.Qt.Checked)
|
pf_selected_item.setCheckState(check_state)
|
||||||
#check_state = QtCore.Qt.Checked if filename else QtCore.Qt.Unchecked
|
|
||||||
#pf_selected_item.setCheckState(check_state)
|
|
||||||
self.tableWidget.setItem(index, 0, pf_selected_item)
|
self.tableWidget.setItem(index, 0, pf_selected_item)
|
||||||
self.tableWidget.setItem(index, 1, QtWidgets.QTableWidgetItem(f'{event.pylot_id}'))
|
self.tableWidget.setItem(index, 1, QtWidgets.QTableWidgetItem(f'{event.pylot_id}'))
|
||||||
if filename:
|
if filename:
|
||||||
@ -1698,6 +1710,7 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
|
|||||||
item_check = self.tableWidget.item(row_ind, 0)
|
item_check = self.tableWidget.item(row_ind, 0)
|
||||||
if item_check.checkState() == QtCore.Qt.Checked:
|
if item_check.checkState() == QtCore.Qt.Checked:
|
||||||
item_fname = self.tableWidget.item(row_ind, 2)
|
item_fname = self.tableWidget.item(row_ind, 2)
|
||||||
|
if item_fname:
|
||||||
filepath = item_fname.data(3)
|
filepath = item_fname.data(3)
|
||||||
filepaths.append(filepath)
|
filepaths.append(filepath)
|
||||||
return filepaths
|
return filepaths
|
||||||
@ -1707,11 +1720,15 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
|
|||||||
return
|
return
|
||||||
filepaths = self.getChecked()
|
filepaths = self.getChecked()
|
||||||
if len(filepaths) > 0:
|
if len(filepaths) > 0:
|
||||||
status_text = f'Found {len(filepaths)} eventfiles. Do you want to load them?'
|
status_text = f"Found {len(filepaths)} eventfile{'s' if len(filepaths) > 1 else ''}. Do you want to load them?"
|
||||||
else:
|
else:
|
||||||
status_text = 'Did not find any files for specified file mask.'
|
status_text = 'Did not find/select any files for specified file mask.'
|
||||||
self.statusText.setText(status_text)
|
self.statusText.setText(status_text)
|
||||||
|
|
||||||
|
def update_merge_strategy(self):
|
||||||
|
for button in (self.merge_button, self.overwrite_button):
|
||||||
|
if button.isChecked():
|
||||||
|
self.merge_strategy = button.text()
|
||||||
|
|
||||||
def connectSignals(self):
|
def connectSignals(self):
|
||||||
self._buttonbox.accepted.connect(self.accept)
|
self._buttonbox.accepted.connect(self.accept)
|
||||||
@ -1721,7 +1738,8 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
|
|||||||
self.checkAllButton.clicked.connect(self.toggleCheckAll)
|
self.checkAllButton.clicked.connect(self.toggleCheckAll)
|
||||||
self.checkAllButton.clicked.connect(self.update_status)
|
self.checkAllButton.clicked.connect(self.update_status)
|
||||||
self.tableWidget.cellClicked.connect(self.update_status)
|
self.tableWidget.cellClicked.connect(self.update_status)
|
||||||
|
self.merge_button.clicked.connect(self.update_merge_strategy)
|
||||||
|
self.overwrite_button.clicked.connect(self.update_merge_strategy)
|
||||||
|
|
||||||
|
|
||||||
class SingleTextLineDialog(QtWidgets.QDialog):
|
class SingleTextLineDialog(QtWidgets.QDialog):
|
||||||
|
Loading…
Reference in New Issue
Block a user