From 74da851997e89fe5e2db9e0f033d6a86c05b28ae Mon Sep 17 00:00:00 2001 From: CMDR-Kiel42 Date: Sat, 1 Jun 2019 00:25:03 +0200 Subject: [PATCH] Add only csv files in file explorer + avoid dirty exception if no file is chosen --- load.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/load.py b/load.py index c0e1da3..c7ee74e 100644 --- a/load.py +++ b/load.py @@ -49,19 +49,21 @@ def copy_waypoint(self=None): this.parent.update() def new_route(self=None): - filename = filedialog.askopenfilename() # show an "Open" dialog box and return the path to the selected file - this.next_route = filename + filename = filedialog.askopenfilename(filetypes = (("csv files", "*.csv"),)) # show an "Open" dialog box and return the path to the selected file - with open(filename, 'r') as csvfile: - route_reader = csv.reader(csvfile) - this.route = [row for row in route_reader] + if filename.__len__() > 0: + this.next_route = filename - if monitor.system == this.route[1][0]: - del this.route[1] + with open(filename, 'r') as csvfile: + route_reader = csv.reader(csvfile) + this.route = [row for row in route_reader] - this.next_stop = this.route[1][0] - copy_waypoint() - update_gui() + if monitor.system == this.route[1][0]: + del this.route[1] + + this.next_stop = this.route[1][0] + copy_waypoint() + update_gui() def update_route(): del(this.route[1])