[chirp_devel] [PATCH] Improve latitude/longitude entry
The attached patch adds support for a wider variety of latitude/longitude input formats in the RFinder search dialog.
What should work:
dd mm.m N/S/E/W dd mm ss.s N/S/E/W
with any separator between the fields, and with or without a separator between the final group of digits and the direction.
The parsing code is currently extremely permissive. It doesn't complain about seconds or minutes values greater than 60; it just adds them in (so 45 90 N produces the same result as 46 30 N). Should it care? I could see that decision going either way.
-- Brad Ackerman N1MNB PGP: 0x9F49A373 brad@facefault.org <*> http://bsa.smugmug.com/
Hi Brad,
The attached patch adds support for a wider variety of latitude/longitude input formats in the RFinder search dialog.
Sweet, thanks! Does the RFinder search still work? I was actually thinking of yanking it out recently as it didn't seem to be returning any useful data anymore.
The parsing code is currently extremely permissive. It doesn't complain about seconds or minutes values greater than 60; it just adds them in (so 45 90 N produces the same result as 46 30 N). Should it care? I could see that decision going either way.
I think it should, FWIW.
diff -r ec8f0349892b chirp/chirp_common.py --- a/chirp/chirp_common.py Tue Feb 28 18:13:21 2012 -0800 +++ b/chirp/chirp_common.py Thu Mar 01 21:19:19 2012 -0800 @@ -19,6 +19,7 @@
Can you put this in either chirpui/mainapp.py or maybe chirpui/common.py? The chirp_common bit is really supposed to be for the stuff in chirp/, which is all non-UI-related and parsing lat/lon values is only a UI thing.
+def parse_latlong(s):
- """
- Convert a string latitude/longitude to a float.
- Convert a string representation of a latitude or longitude to a float
- between -90 and 90 (latitude) or -180 and 180 (longitude).
- """
- value = 0
- try:
value = float(s)
- except ValueError:
# It's not a valid float as-is. Lat-long?
m = re.match(
'^\s*([0-9.]+)\D+([0-9.]+)\D*(([0-9.]+)\D*)?([NSEW])\s*$',
s,
re.IGNORECASE)
This is a total nit, but if you're going to re-do this to move it anyway, can you just change the bit in the try to:
try: return float(s) except ValueError: pass
That way the rest of the parsing code isn't all indented under the except and looks better (IMHO, of course).
diff -r ec8f0349892b chirpui/mainapp.py --- a/chirpui/mainapp.py Tue Feb 28 18:13:21 2012 -0800 +++ b/chirpui/mainapp.py Thu Mar 01 21:19:19 2012 -0800 @@ -815,14 +815,16 @@ reporting.report_model_usage(eset.rthread.radio, "import", count > 0)
def do_rfinder_prompt(self):
latitude_ok = lambda x: float(x) < 90 and float(x) > -90
longitude_ok = lambda x: float(x) < 180 and float(x) > -180 fields = {"1Email" : (gtk.Entry(), lambda x: "@" in x), "2Password" : (gtk.Entry(), lambda x: x), "3Latitude" : (gtk.Entry(),
lambda x: float(x) < 90 and float(x) > -90),
lambda x: latitude_ok(chirp_common.parse_latlong(x))), "4Longitude": (gtk.Entry(),
lambda x: float(x) < 180 and float(x) > -180),
lambda x: longitude_ok(chirp_common.parse_latlong(x))), }
We probably need to add tooltips to the input boxes to show the format(s) that they can use, don't you think?
If you're not familiar with pygtk I can do that part in a follow-on.
Thanks!
participants (2)
-
Brad Ackerman
-
Dan Smith