Skip to content
Snippets Groups Projects
Commit 60f5ae3a authored by Loic-Lenof's avatar Loic-Lenof
Browse files

Fixed bugs

+ fixed layout shift when loading a new file
+ fixed entries not being updated when loading a new file
- removed reset_toolbar()
parent 37c43f0d
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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,6 +64,7 @@ class FileExplorer(object):
path : str
Path to the directory in which the file explorer will be opened.
"""
if os.path.splitext(self.path)[1] == "":
self.file = fd.askopenfilename(
title='Open a file',
initialdir=self.path,
......@@ -71,6 +72,15 @@ class FileExplorer(object):
('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),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment