[chirp_devel] [PATCH] Improve latitude/longitude entry

Dan Smith
Fri Mar 2 07:52:25 PST 2012


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!

-- 
Dan Smith
www.danplanet.com
KK7DS

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: OpenPGP digital signature
Url : http://intrepid.danplanet.com/pipermail/chirp_devel/attachments/20120302/5ec6c61b/attachment-0001.bin 


More information about the chirp_devel mailing list