From 8dc9ed6aac6294e1054048bb1363748dba6fd4f7 Mon Sep 17 00:00:00 2001 From: "Christian T. Jacobs" Date: Thu, 13 Jul 2017 17:21:26 +0100 Subject: [PATCH] Handle \n characters in the NOTES field more naturally. --- pyqso/adif.py | 8 +++----- pyqso/logbook.py | 10 ++++++++-- pyqso/record_dialog.py | 7 ------- pyqso/res/pyqso.glade | 2 +- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/pyqso/adif.py b/pyqso/adif.py index e3aaee6..2d4254d 100644 --- a/pyqso/adif.py +++ b/pyqso/adif.py @@ -249,10 +249,7 @@ class ADIF: # this and simply ignore it instead (if it exists). if(re.search("", text, flags=re.IGNORECASE) is not None): # There is a header present, so let's ignore everything - # up to and including the marker. Note that - # re.search has been used here to handle any case sensitivity. - # Previously we were checking for . is also valid - # but wasn't being detected before. + # up to and including the marker. while len(tokens) > 0: t = tokens.pop(0) if(re.match("", t, flags=re.IGNORECASE) is not None): @@ -281,6 +278,7 @@ class ADIF: # This will help us later when comparing the field names # against the available field names in the ADIF specification. field_name = fd[0].upper() + # Only read in the number of characters specified by the data length. field_data = fd[2][:int(fd[1])] # Combo boxes are used later on and these are case sensitive, @@ -303,7 +301,7 @@ class ADIF: if(merge_comment): if("NOTES" in list(fields_and_data_dictionary.keys()) and comment): logging.debug("Merging COMMENT field with NOTES field...") - fields_and_data_dictionary["NOTES"] += "\\n" + comment + fields_and_data_dictionary["NOTES"] += "\n" + comment logging.debug("Merged fields.") elif(comment): # Create the NOTES entry, but only store the contents of the COMMENT field. diff --git a/pyqso/logbook.py b/pyqso/logbook.py index eb7262c..5bc725c 100644 --- a/pyqso/logbook.py +++ b/pyqso/logbook.py @@ -417,6 +417,10 @@ class Logbook: field_names = AVAILABLE_FIELD_NAMES_ORDERED for i in range(0, len(field_names)): renderer = Gtk.CellRendererText() + + # Keep each row to a single line. + renderer.set_property("single-paragraph-mode", True) + column = Gtk.TreeViewColumn(AVAILABLE_FIELD_NAMES_FRIENDLY[field_names[i]], renderer, text=i+1) column.set_resizable(True) column.set_min_width(50) @@ -424,9 +428,11 @@ class Logbook: # Special cases if(field_names[i] == "NOTES"): - # Give the 'Notes' column some extra space, since this is likely to contain some long sentences... + # Give the 'Notes' column some extra space, since this is likely to contain some long sentences ... column.set_min_width(300) - # ... but don't let it automatically re-size itself. + # ... but not too much extra space ... + column.set_max_width(600) + # ... and don't let the column automatically re-size itself. column.set_sizing(Gtk.TreeViewColumnSizing.FIXED) column.connect("clicked", self.sort_log, i+1) diff --git a/pyqso/record_dialog.py b/pyqso/record_dialog.py index 35f899f..e40fbce 100644 --- a/pyqso/record_dialog.py +++ b/pyqso/record_dialog.py @@ -193,10 +193,6 @@ class RecordDialog: continue elif(field_names[i] == "QSL_SENT" or field_names[i] == "QSL_RCVD"): self.sources[field_names[i]].set_active(qsl_options.index(data)) - elif(field_names[i] == "NOTES"): - # Remember to put the new line escape characters back in when displaying the data in a Gtk.TextView - text = data.replace("\\n", "\n") - self.sources[field_names[i]].set_text(text) else: self.sources[field_names[i]].set_text(data) else: @@ -276,9 +272,6 @@ class RecordDialog: elif(field_name == "NOTES"): (start, end) = self.sources[field_name].get_bounds() text = self.sources[field_name].get_text(start, end, True) - # Replace the escape characters with a slightly different new line marker. - # If we don't do this, the rows in the Gtk.TreeView expand based on the number of new lines. - text = text.replace("\n", "\\n") return text else: return self.sources[field_name].get_text() diff --git a/pyqso/res/pyqso.glade b/pyqso/res/pyqso.glade index d91aa55..8e809fc 100644 --- a/pyqso/res/pyqso.glade +++ b/pyqso/res/pyqso.glade @@ -3513,7 +3513,7 @@ Base64-encoded plain text in the configuration file. True True - word + word-char