[change] delete old obspy dmt database files, current files unselectable

The metadata files that come from the obspy dmt database are saved in a list. When a new event is opened, the obspy dmt metadata files from the old event are deleted from the inventory (and the new ones are added). 
The metadata files from the obspy dmt database are now unselectable in the MetadataWidget. 
The clear inventory function is called when saving the project (otherwise the obspy dmt metadata gets saved and becomes editable). The update_obspy_dmt function is called after the save to get the obspy_dmt_metadata back to continue working after the save.
This commit is contained in:
Sally 2019-04-01 10:55:38 +02:00
parent be71fc0298
commit 8270bd4974
3 changed files with 19 additions and 3 deletions

View File

@ -1978,10 +1978,11 @@ class MainWindow(QMainWindow):
self.update_obspy_dmt()
def update_obspy_dmt(self):
self.metadata.clear_inventory()
if self.obspy_dmt:
invpath = os.path.join(self.get_current_event_path(), 'resp')
if not invpath in self.metadata.inventories:
self.metadata.add_inventory(invpath)
self.metadata.add_inventory(invpath, obspy_dmt_inv = True)
# check if directory is empty
if os.listdir(invpath):
self.init_map_button.setEnabled(True)
@ -3369,6 +3370,7 @@ class MainWindow(QMainWindow):
'''
Save back project to new pickle file.
'''
self.metadata.clear_inventory()
dlg = QFileDialog(self)
fnm = dlg.getSaveFileName(self, 'Create a new project file...', filter='Pylot project (*.plp)')
filename = fnm[0]
@ -3383,6 +3385,7 @@ class MainWindow(QMainWindow):
self.saveProjectAsAction.setEnabled(True)
self.update_status('Saved new project to {}'.format(filename), duration=5000)
self.add2recentProjects(filename)
self.update_obspy_dmt()
return True
def saveProject(self, new=False):
@ -3395,9 +3398,11 @@ class MainWindow(QMainWindow):
self.setDirty(True)
return False
else:
self.metadata.clear_inventory()
self.project.parameter = self._inputs
self.exportEvents()
self.project.save()
self.update_obspy_dmt()
if not self.project.dirty:
self.setDirty(False)
self.update_status('Saved back project to file:\n{}'.format(self.project.location), duration=5000)

View File

@ -22,6 +22,8 @@ class Metadata(object):
# seed id as key, path to file as value
self.seed_ids = {}
self.stations_dict = {}
# saves which metadata files are from obspy dmt
self.obspy_dmt_invs = []
if inventory:
if os.path.isdir(inventory):
self.add_inventory(inventory)
@ -44,7 +46,7 @@ class Metadata(object):
def __repr__(self):
return self.__str__()
def add_inventory(self, path_to_inventory):
def add_inventory(self, path_to_inventory, obspy_dmt_inv = False):
"""
Add path to list of inventories.
:param path_to_inventory: Path to a folder
@ -54,6 +56,8 @@ class Metadata(object):
assert (os.path.isdir(path_to_inventory)), '{} is no directory'.format(path_to_inventory)
if path_to_inventory not in self.inventories:
self.inventories.append(path_to_inventory)
if obspy_dmt_inv == True:
self.obspy_dmt_invs.append(path_to_inventory)
def add_inventory_file(self, path_to_inventory_file):
"""
@ -89,6 +93,11 @@ class Metadata(object):
# this will be rebuilt for the next init of the arraymap anyway, so just reset it
self.stations_dict = {}
def clear_inventory(self):
for inv in self.obspy_dmt_invs:
self.remove_inventory(inv)
self.obspy_dmt_invs = []
def get_metadata(self, seed_id, time=None):
"""
Get metadata for seed id at time. When time is not specified, metadata for current time is fetched.

View File

@ -206,7 +206,7 @@ class AddMetadataWidget(QWidget):
def init_add_remove_buttons(self):
self.add_remove_layout = QVBoxLayout()
self.add_button = self.init_button("Add", Qt.Key_Insert, "Choose a file to add \n(Ins)")
self.remove_button = self.init_button("Remove", Qt.Key_Delete, "Remove selected file \n(Del)")
self.remove_button = self.init_button("Remove", Qt.Key_Delete, "Remove selected file(s) \n(Del)")
self.add_remove_layout.addWidget(self.add_button, 0, QtCore.Qt.AlignBottom)
self.add_remove_layout.addWidget(self.remove_button, 0, QtCore.Qt.AlignTop)
self.list_buttons_layout.insertLayout(1, self.add_remove_layout, 0)
@ -252,6 +252,8 @@ class AddMetadataWidget(QWidget):
for inventory_path in self.metadata.inventories:
item = QtGui.QStandardItem(inventory_path)
self.list_model.appendRow(item)
if inventory_path in self.metadata.obspy_dmt_invs:
item.setFlags(Qt.NoItemFlags)
def directory_to_lineedit(self):
inventory_path = self.open_directory()