From 60f5ae3a843d3398e4b0d9b3f4b12b7c285abedd Mon Sep 17 00:00:00 2001 From: Loic-Lenof <loic.lenof@gmail.com> Date: Tue, 24 Jan 2023 15:42:49 +0100 Subject: [PATCH] Fixed bugs + fixed layout shift when loading a new file + fixed entries not being updated when loading a new file - removed reset_toolbar() --- README.md | 2 +- interface.py | 59 ++++++++++++++++++++++++++-------------------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index 9688f9b..71d8638 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ annot_data.display_contours() # or annot_data.display_contours(img="pcen") ``` To modify previous annotations, run the following line (using annotations on file SCW6070_20220717_174215.wav as an example): -`$python PyAVA_V2.py --modify SCW6070_20220717_174215-contours.json SCW6070_20220717_174215.wav` +`$python PyAVA.py --modify SCW6070_20220717_174215-contours.json SCW6070_20220717_174215.wav` ## Support diff --git a/interface.py b/interface.py index 0dc8900..b5b6e1e 100644 --- a/interface.py +++ b/interface.py @@ -49,7 +49,7 @@ class FileExplorer(object): file : str Path to a file selected by the user in the file explorer window. """ - self.path = path # folder to be opened + self.path = path # folder or file to be opened self.explorer_window() # start function auto def explorer_window(self): @@ -64,13 +64,23 @@ class FileExplorer(object): path : str Path to the directory in which the file explorer will be opened. """ - self.file = fd.askopenfilename( - title='Open a file', - initialdir=self.path, - filetypes=( - ('Audio Files', '*.wav'), - ('All files', '*.*') - )) + if os.path.splitext(self.path)[1] == "": + self.file = fd.askopenfilename( + title='Open a file', + initialdir=self.path, + filetypes=( + ('Audio Files', '*.wav'), + ('All files', '*.*') + )) + else: + self.file = fd.askopenfilename( + title='Open a file', + initialdir=os.path.dirname(self.path), + initialfile=os.path.basename(self.path), + filetypes=( + ('Audio Files', '*.wav'), + ('All files', '*.*') + )) class App(object): """ @@ -168,9 +178,6 @@ class App(object): the selected item in listbox widget. load_audio(): Loads audio data. Waveform and spectrogram. - reset_toolbar(): - Resets the toolbar associated to the matplotlib figure, - this is to avoid overlapping when the canvas is updated. select_file(): Opens a file explorer window to select a new wavefile. Saves contours if a new file is selected. @@ -369,7 +376,7 @@ class App(object): toolbarFrame, toolbar, loading_screen """ # configure main window - self.root.wm_title("Spectrogram annotator") + self.root.wm_title("PyAVA interface") self.root.geometry( f"{str(self._default_width)}x{str(self._default_height)}") self.root.rowconfigure(1, weight=1) @@ -527,15 +534,6 @@ class App(object): self.HOP_LENGTH, self.CLIPPING) - def reset_toolbar(self): - """ - A function to destroy and create a new toolbar - that interacts with matplotlib canvas. - """ - self.toolbar.destroy() - self.toolbar = NavigationToolbar2Tk(self.canvas, self.toolbarFrame) - self.toolbar.update() - def select_file(self): """ A function that calls a new window to select a wavefile. @@ -548,7 +546,7 @@ class App(object): None : If a new file is selected, saves current coordinates to json file and generate a new window for annotation. """ - new_wavefile = FileExplorer(self.DIR).file + new_wavefile = FileExplorer(self.WAVEFILE).file if len(new_wavefile) > 0 : # save current coords @@ -557,7 +555,7 @@ class App(object): self.WAVEFILE = new_wavefile # display loading scree - self.loading_screen.grid(row=1, column=1, rowspan=13) + self.loading_screen.grid(row=1, column=1, rowspan=14) self.canvas.get_tk_widget().destroy() # load new data @@ -575,11 +573,10 @@ class App(object): self.figure.canvas.mpl_disconnect(self.klicker.key_press) # update interface + self.toolbar.destroy() self.entry_setup() - self._frame_listbox_scroll() - self.canvas.get_tk_widget().grid(row=1, column=1, rowspan=13) + self.layout() self.loading_screen.grid_forget() - self.reset_toolbar() def setup(self): """ @@ -603,9 +600,9 @@ class App(object): None : Updates spectrogram and data_showed according to new fft, hop_length and clipping values. """ - if ((self.FFT_IN != self.NFFT) or - (self.HOP_IN != self.HOP_LENGTH) or - (self.CLIP_IN != self.CLIPPING)): + if ((self.FFT_IN.get() != self.NFFT) or + (self.HOP_IN.get() != self.HOP_LENGTH) or + (self.CLIP_IN.get() != self.CLIPPING)): self.NFFT = self.FFT_IN.get() self.HOP_LENGTH = self.HOP_IN.get() @@ -616,7 +613,9 @@ class App(object): self.NEW_SR, self.NFFT, self.HOP_LENGTH, - self.CLIPPING) + self.CLIPPING, + as_pcen=(False if self.switch_view_button['text'] == "Switch to PCEN" + else True)) self.data_showed.set_data(self.spectrogram[::-1]) self.data_showed.set_clim( vmin=np.nanmin(self.spectrogram), -- GitLab