-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chiara Tomaiuolo
committed
Mar 5, 2025
1 parent
9811a8e
commit 3dbd835
Showing
1 changed file
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# System libraries first... | ||
import os | ||
import sys | ||
from ttkbootstrap.dialogs import Messagebox | ||
# ... then installed libraries... | ||
# ... and eventually local modules. | ||
from spectratools.spectraio import create_parser, check_file_format | ||
from spectratools.spectraplot import SpectraPlotter | ||
|
||
def main(): | ||
# Parsing arguments from parser | ||
parser = create_parser() | ||
args = parser.parse_args() | ||
|
||
# Checking file format | ||
if not args.filepaths: | ||
filepaths = [] | ||
app = SpectraPlotter(filepaths, nbins=args.nbins, treename=args.treename) | ||
app.mainloop() | ||
else: | ||
for file in args.filepaths: | ||
opened_files = [] | ||
if not check_file_format(file): | ||
Messagebox.show_error(message=f"{file} format not supported.") | ||
continue | ||
else: | ||
opened_files.append(file) | ||
if not opened_files: | ||
Messagebox.show_error(message="No valid file to show.") | ||
sys.exit(1) | ||
|
||
# Filling the file list obtained from parser | ||
for file in args.filepaths: | ||
try: | ||
app = SpectraPlotter(opened_files, nbins=args.nbins, treename=args.treename) | ||
app.mainloop() | ||
except FileNotFoundError: | ||
Messagebox.show_warning(message=f"File {os.path.basename(file)} not found.") | ||
except ValueError: | ||
Messagebox.show_error(message=f"File format not supported.") | ||
|
||
if __name__ == "__main__": | ||
main() |