Compare commits

...

4 Commits

4 changed files with 106 additions and 34 deletions

View File

@ -1010,12 +1010,12 @@ class MainWindow(QMainWindow):
events=events) events=events)
if not sld.exec_(): if not sld.exec_():
return return
fext = sld.comboBox.currentText()
# fext = '.xml' filenames = sld.getChecked()
for event in events: for event in events:
filename = get_pylot_eventfile_with_extension(event, fext) for filename in filenames:
if 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 +1024,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 +1039,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(

View File

@ -124,8 +124,8 @@ class Array_map(QtWidgets.QWidget):
self.cmaps_box = QtWidgets.QComboBox() self.cmaps_box = QtWidgets.QComboBox()
self.cmaps_box.setMaxVisibleItems(20) self.cmaps_box.setMaxVisibleItems(20)
[self.cmaps_box.addItem(map_name) for map_name in sorted(plt.colormaps())] [self.cmaps_box.addItem(map_name) for map_name in sorted(plt.colormaps())]
# try to set to hsv as default # try to set to viridis as default
self.cmaps_box.setCurrentIndex(self.cmaps_box.findText('hsv')) self.cmaps_box.setCurrentIndex(self.cmaps_box.findText('viridis'))
self.top_row.addWidget(QtWidgets.QLabel('Select a phase: ')) self.top_row.addWidget(QtWidgets.QLabel('Select a phase: '))
self.top_row.addWidget(self.comboBox_phase) self.top_row.addWidget(self.comboBox_phase)

View File

@ -334,7 +334,7 @@ def get_none(value):
def get_bool(value): def get_bool(value):
""" """
Convert string representations of bools to their true boolean value Convert string representations of bools to their true boolean value. Return value if it cannot be identified as bool.
:param value: :param value:
:type value: str, bool, int, float :type value: str, bool, int, float
:return: true boolean value :return: true boolean value
@ -356,6 +356,8 @@ def get_bool(value):
False False
>>> get_bool(-0.3) >>> get_bool(-0.3)
False False
>>> get_bool(None)
None
""" """
if type(value) is bool: if type(value) is bool:
return value return value
@ -363,10 +365,13 @@ def get_bool(value):
return True return True
elif value in ['False', 'false']: elif value in ['False', 'false']:
return False return False
elif value > 0. or value > 0: elif isinstance(value, float) or isinstance(value, int):
if value > 0. or value > 0:
return True return True
else: else:
return False return False
else:
return value
def four_digits(year): def four_digits(year):

View File

@ -1576,6 +1576,8 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
self.events = events self.events = events
self.filepaths = [] self.filepaths = []
self.file_extensions = [] self.file_extensions = []
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()
@ -1583,16 +1585,17 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
self.connectSignals() self.connectSignals()
self.showPaths() self.showPaths()
self.refreshSelectionBox() self.refreshSelectionBox()
self.refresh_timer = QTimer(self) # self.refresh_timer = QTimer(self)
self.refresh_timer.timeout.connect(self.showPaths) # self.refresh_timer.timeout.connect(self.showPaths)
self.refresh_timer.start(10000) # self.refresh_timer.start(10000)
self.resize(800, 450) self.resize(800, 450)
def setupUi(self): def setupUi(self):
ncol = 4
self.main_layout = QtWidgets.QVBoxLayout() self.main_layout = QtWidgets.QVBoxLayout()
self.header_layout = QtWidgets.QHBoxLayout() self.header_layout = QtWidgets.QHBoxLayout()
self.footer_layout = QtWidgets.QHBoxLayout()
# #
self.setLayout(self.main_layout) self.setLayout(self.main_layout)
@ -1606,11 +1609,24 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
self.searchButton = QtWidgets.QPushButton('Search') self.searchButton = QtWidgets.QPushButton('Search')
self.searchButton.setVisible(False) self.searchButton.setVisible(False)
# check/uncheck button for table
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
self.tableWidget = QtWidgets.QTableWidget() self.tableWidget = QtWidgets.QTableWidget()
tableWidget = self.tableWidget tableWidget = self.tableWidget
tableWidget.setColumnCount(3) tableWidget.setColumnCount(ncol)
tableWidget.setRowCount(len(self.events)) tableWidget.setRowCount(len(self.events))
tableWidget.setHorizontalHeaderLabels(('Event ID', 'Filename', 'Last modified')) tableWidget.setHorizontalHeaderLabels(('', 'Event ID', 'Filename', 'Last modified'))
tableWidget.setEditTriggers(tableWidget.NoEditTriggers) tableWidget.setEditTriggers(tableWidget.NoEditTriggers)
tableWidget.setSortingEnabled(True) tableWidget.setSortingEnabled(True)
header = tableWidget.horizontalHeader() header = tableWidget.horizontalHeader()
@ -1623,9 +1639,17 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
self.header_layout.addWidget(self.comboBox) self.header_layout.addWidget(self.comboBox)
self.header_layout.addWidget(self.searchButton) self.header_layout.addWidget(self.searchButton)
self.footer_layout.addWidget(self.checkAllButton)
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(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)
self.main_layout.addWidget(self.statusText) self.main_layout.addLayout(self.footer_layout)
self.main_layout.addWidget(self._buttonbox) self.main_layout.addWidget(self._buttonbox)
def showPaths(self): def showPaths(self):
@ -1634,23 +1658,23 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
self.tableWidget.clearContents() self.tableWidget.clearContents()
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)
self.tableWidget.setItem(index, 0, QtWidgets.QTableWidgetItem(f'{event.pylot_id}')) pf_selected_item = QtWidgets.QTableWidgetItem()
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, 1, QtWidgets.QTableWidgetItem(f'{event.pylot_id}'))
if filename: if filename:
self.filepaths.append(filename) self.filepaths.append(filename)
ts = int(os.path.getmtime(filename)) ts = int(os.path.getmtime(filename))
# create QTableWidgetItems of filepath and last modification time # create QTableWidgetItems of filepath and last modification time
fname_item = QtWidgets.QTableWidgetItem(f'{os.path.split(filename)[-1]}') fname_item = QtWidgets.QTableWidgetItem(f'{os.path.split(filename)[-1]}')
fname_item.setData(3, filename)
ts_item = QtWidgets.QTableWidgetItem(f'{datetime.datetime.fromtimestamp(ts)}') ts_item = QtWidgets.QTableWidgetItem(f'{datetime.datetime.fromtimestamp(ts)}')
self.tableWidget.setItem(index, 1, fname_item) self.tableWidget.setItem(index, 2, fname_item)
self.tableWidget.setItem(index, 2, ts_item) self.tableWidget.setItem(index, 3, ts_item)
# TODO: Idea -> only refresh if table contents changed. Use selection to load only a subset of files self.update_status()
if len(self.filepaths) > 0:
status_text = f'Found {len(self.filepaths)} eventfiles. Do you want to load them?'
else:
status_text = 'Did not find any files for specified file mask.'
self.statusText.setText(status_text)
def refreshSelectionBox(self): def refreshSelectionBox(self):
fext = self.comboBox.currentText() fext = self.comboBox.currentText()
@ -1670,12 +1694,52 @@ class SearchFileByExtensionDialog(QtWidgets.QDialog):
self._buttonbox = QDialogButtonBox(QDialogButtonBox.Ok | self._buttonbox = QDialogButtonBox(QDialogButtonBox.Ok |
QDialogButtonBox.Cancel) QDialogButtonBox.Cancel)
def toggleCheckAll(self):
self.check_all_state = not self.check_all_state
self.checkAll(self.check_all_state)
def checkAll(self, state):
state = QtCore.Qt.Checked if state else QtCore.Qt.Unchecked
for row_ind in range(self.tableWidget.rowCount()):
item = self.tableWidget.item(row_ind, 0)
item.setCheckState(state)
def getChecked(self):
filepaths = []
for row_ind in range(self.tableWidget.rowCount()):
item_check = self.tableWidget.item(row_ind, 0)
if item_check.checkState() == QtCore.Qt.Checked:
item_fname = self.tableWidget.item(row_ind, 2)
if item_fname:
filepath = item_fname.data(3)
filepaths.append(filepath)
return filepaths
def update_status(self, row=None, col=None):
if col is not None and col != 0:
return
filepaths = self.getChecked()
if len(filepaths) > 0:
status_text = f"Found {len(filepaths)} eventfile{'s' if len(filepaths) > 1 else ''}. Do you want to load them?"
else:
status_text = 'Did not find/select any files for specified file mask.'
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)
self._buttonbox.rejected.connect(self.reject) self._buttonbox.rejected.connect(self.reject)
self.comboBox.editTextChanged.connect(self.showPaths) self.comboBox.editTextChanged.connect(self.showPaths)
self.searchButton.clicked.connect(self.showPaths) self.searchButton.clicked.connect(self.showPaths)
self.checkAllButton.clicked.connect(self.toggleCheckAll)
self.checkAllButton.clicked.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):