Skip to content

Commit

Permalink
[databrowser] somewhat improved error handling for file opening
Browse files Browse the repository at this point in the history
  • Loading branch information
janscience committed Jan 23, 2025
1 parent fdb757a commit db35b33
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/audian/audian.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ def load_files(self, file_paths):
# prepare open all files in a single buffer:
browser = DataBrowser(file_paths, self.load_kwargs, self.plugins,
self.channels, self.audio, self.acts)
self.tabs.addTab(browser, os.path.basename(file_paths[0]))
self.tabs.addTab(browser, browser.name())
self.browsers.append(browser)
self.tabs.setCurrentWidget(browser)
QTimer.singleShot(100, self.load_data)
Expand Down Expand Up @@ -1243,8 +1243,7 @@ def load_data(self):
self.channels,
self.audio,
self.acts)
self.tabs.addTab(browser,
os.path.basename(file_path))
self.tabs.addTab(browser, browser.name())
self.browsers.append(browser)
if first:
self.tabs.setCurrentWidget(browser)
Expand All @@ -1258,7 +1257,7 @@ def load_data(self):
Can not open file <b>{browser.file_path}</b>!''')
break
self.tabs.setTabText(self.tabs.indexOf(browser),
os.path.basename(browser.data.file_path))
browser.name())
for b in self.browsers:
if not b.data.data is None and \
b.data.channels != browser.data.channels:
Expand Down
2 changes: 2 additions & 0 deletions src/audian/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ def open(self, unwrap, unwrap_clip):
# raw data:
tbuffer = self.buffer_time + self.tbefore + self.tafter
tback = self.back_time + self.tbefore
verbose = isinstance(self.file_path, (list, tuple, np.ndarray))
try:
self.data = DataLoader(self.file_path, tbuffer, tback,
verbose=verbose,
**self.load_kwargs)
except IOError:
self.data = None
Expand Down
7 changes: 7 additions & 0 deletions src/audian/databrowser.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,13 @@ def __del__(self):
self.close()


def name(self):
if isinstance(self.data.file_path, (list, tuple, np.ndarray)):
return os.path.basename(self.data.file_path[0])
else:
return os.path.basename(self.data.file_path)


def get_trace(self, name):
return self.data[name]

Expand Down

0 comments on commit db35b33

Please sign in to comment.