From bcc5055ef34900c4d8b32b251a8a28fdde586d74 Mon Sep 17 00:00:00 2001 From: Sally Date: Thu, 21 Mar 2019 12:37:09 +0100 Subject: [PATCH 1/3] [bugfix] Sorting items before removing them from list The selectedIndexes are now sorted before the are removed from the listView. Otherwise you get problems with indices that aren't in descending order. --- pylot/core/util/widgets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 1d0b1844..d828b8cb 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -308,7 +308,7 @@ class AddMetadataWidget(QWidget): also adds the path to the list of inventories that get deleted upon accepting all changes or deletes the path from the list of of inventories that get added to the metadata upon accepting all changes """ - for index in reversed(self.list_view.selectionModel().selectedIndexes()): + for index in reversed(sorted(self.list_view.selectionModel().selectedIndexes())): item = self.list_model.itemData(index) inventory_path = item[0] # marked path self.list_model.removeRow(index.row()) # aus der Anzeige-Liste gelöscht From be71fc0298277b85fc8832c4337719188ec61b86 Mon Sep 17 00:00:00 2001 From: Sally Date: Thu, 21 Mar 2019 12:40:35 +0100 Subject: [PATCH 2/3] Removal of Dead Code Old Code that is not used any longer (was rewritten). --- pylot/core/util/widgets.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index d828b8cb..93ce1519 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -268,9 +268,6 @@ class AddMetadataWidget(QWidget): return fninv def on_clicked(self): - #for index in self.list_view.selectionModel().selectedIndexes(): - # item = self.list_model.itemData(index) - # inventory_path = item[0] indices = self.list_view.selectionModel().selectedIndexes() try: item = self.list_model.itemData(indices[-1]) From 8270bd4974ebe60e695fd71695ef4570a607bac6 Mon Sep 17 00:00:00 2001 From: Sally Date: Mon, 1 Apr 2019 10:55:38 +0200 Subject: [PATCH 3/3] [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. --- PyLoT.py | 7 ++++++- pylot/core/util/dataprocessing.py | 11 ++++++++++- pylot/core/util/widgets.py | 4 +++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/PyLoT.py b/PyLoT.py index 8dba633e..e5be7b92 100755 --- a/PyLoT.py +++ b/PyLoT.py @@ -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) diff --git a/pylot/core/util/dataprocessing.py b/pylot/core/util/dataprocessing.py index 4d4818aa..d564b4a3 100644 --- a/pylot/core/util/dataprocessing.py +++ b/pylot/core/util/dataprocessing.py @@ -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. diff --git a/pylot/core/util/widgets.py b/pylot/core/util/widgets.py index 93ce1519..1d1d6ea4 100644 --- a/pylot/core/util/widgets.py +++ b/pylot/core/util/widgets.py @@ -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()