From 77047d56709e180da4284b41328e0fb9d1c57ad2 Mon Sep 17 00:00:00 2001 From: "Christian T. Jacobs" Date: Mon, 3 Jul 2017 00:58:44 +0100 Subject: [PATCH] Only create a new log once the records in the ADIF file have been read in. --- pyqso/logbook.py | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/pyqso/logbook.py b/pyqso/logbook.py index 4192e87..aeb5c2f 100644 --- a/pyqso/logbook.py +++ b/pyqso/logbook.py @@ -530,6 +530,8 @@ class Logbook: def import_log(self, widget=None): """ Import a log from an ADIF file. """ + + # Get the path to the ADIF file. dialog = Gtk.FileChooserDialog("Import ADIF Log File", self.application.window, Gtk.FileChooserAction.OPEN, @@ -556,7 +558,15 @@ class Logbook: if(path is None): logging.debug("No file path specified.") return + else: + # Read the records. + adif = ADIF() + records = adif.read(path) + if(records is None): + error(parent=self.application.window, message="Could not import the log.") + return + # Get the new log's name (or the name of the existing log the user wants to import into). ln = LogNameDialog(self.application, title="Import Log") while(True): response = ln.dialog.run() @@ -598,25 +608,19 @@ class Logbook: ln.dialog.destroy() - adif = ADIF() + # Update new or existing Log object. + l.add_record(records) + l.populate() - records = adif.read(path) + if(not exists): + self.logs.append(l) + self.render_log(self.log_count-1) - if(records is None): - error(parent=self.application.window, message="Could not import the log.") - else: - l.add_record(records) - l.populate() + # Update statistics, etc. + self.summary.update() + self.application.toolbox.awards.count(self) - if(not exists): - self.logs.append(l) - self.render_log(self.log_count-1) - - # Update statistics, etc. - self.summary.update() - self.application.toolbox.awards.count(self) - - info(parent=self.application.window, message="Imported %d QSOs into log '%s'." % (len(records), l.name)) + info(parent=self.application.window, message="Imported %d QSOs into log '%s'." % (len(records), l.name)) return