Skip to content

Commit

Permalink
User-friendly messages within inspector when GPX is invalid
Browse files Browse the repository at this point in the history
  • Loading branch information
ymollard committed Aug 19, 2018
1 parent 0ec83ce commit 34ac759
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
13 changes: 11 additions & 2 deletions src/gpicsync-GUI.py
Expand Up @@ -1134,6 +1134,7 @@ def sync():
webKml.writeInKml("</Folder>\n")
webKml.close()
wx.CallAfter(self.consolePrint,_("( A Google Maps doc-web.kml file has been created with the given url )")+"\n")
wx.CallAfter(self.consolePrint,_("If the geocoding process was not satisfactory, consider using the GPX inspector from Tools menu to debug your GPX")+"\n")

start_new_thread(sync,())

Expand Down Expand Up @@ -1404,16 +1405,24 @@ def gpxInspector(self,evt):
wx.CallAfter(self.consolePrint,"\n"+_("Select a gpx file first."))
else:
gpxPath=[gpxPath]
myGpx=Gpx(gpxPath).extract()
gpxObject = Gpx(gpxPath)
myGpx=gpxObject.extract()
wx.CallAfter(self.consolePrint,"\n"+_("Looking at ")+gpxPath[0]+"\n")
wx.CallAfter(self.consolePrint,"\n"+_("Number of valid track points found")+" : "+str(len(myGpx))+"\n\n")
points_found_str = _("Number of valid track points found")+" : " + str(len(myGpx))
check_console_msg = "\n\n" + _("Check the console logs to get help about the issues with your gpx file") if len(myGpx) == 0 else ""
def warn_user():
self.consolePrint(gpxObject.errors + points_found_str +"\n")
dialog=wx.MessageDialog(self, message=points_found_str + check_console_msg, style=wx.OK | wx.ICON_INFORMATION)
dialog.ShowModal()

def inspect():
for trkpt in myGpx:
wx.CallAfter(self.consolePrint,_("Date")+": "+trkpt["date"]+"\t"+_("Time")+": "\
+trkpt["time"]+"\t"+_("Latitude")+": "+trkpt["lat"]
+"\t"+_("Longitude")+": "+trkpt["lon"]
+"\t"+_("Altitude")+": "+trkpt["ele"]+"\n")
start_new_thread(inspect,())
wx.CallAfter(warn_user)

def tzMenuPopup(self, evt):
"""Show timezones menu"""
Expand Down
20 changes: 15 additions & 5 deletions src/gpx.py
Expand Up @@ -26,19 +26,27 @@ class Gpx(object):
def __init__(self,gpxFile):
""" create a list with the trkpts found in the .gpx file """
self.gpx_trkpts=[]#The valid list of trackpoints
self.errors = ""
gpx_file=""
i=0
for f in gpxFile:
gpx_file+= open(gpxFile[i],'r').read()
i+=1
#print gpx_file
regex=re.compile('(<trkpt.*?</trkpt>)',re.S)
gpx_trkpts_found=regex.findall(gpx_file)
regex=re.compile('(<trkpt.*?</trkpt>)|(<trkpt.*?/>)',re.S)
gpx_trkpts_found_tuples=regex.findall(gpx_file)
gpx_trkpts_found = [y for x in gpx_trkpts_found_tuples for y in x if y !='']
#print gpx_trkpts_found
print "Number of raw track points found: ",len(gpx_trkpts_found)
self.errors += "Number of raw track points found: " + str(len(gpx_trkpts_found)) + "\n"
if len(gpx_trkpts_found) == 0: self.errors += "There is no <trkpt> or <trkpt/> tag recognized in this gpx file\n"
i=1
num_points_with_time = 0
for trkpt in gpx_trkpts_found:
if trkpt.find("time")>0: self.gpx_trkpts.append(trkpt)
if trkpt.find("time")>0:
self.gpx_trkpts.append(trkpt)
num_points_with_time += 1
else:
self.errors += "Ignoring trkpt " + str(i) + " because it has no <time> tag\n"
i=i+1
regex=re.compile('(<wpt.*?</wpt>)',re.S)
gpx_wpts_found=regex.findall(gpx_file)
Expand All @@ -48,7 +56,9 @@ def __init__(self,gpxFile):
waypoint="<trkpt "+waypoint[5:-7]+"\n</trkpt>"
#print waypoint,"\n"
self.gpx_trkpts.append(waypoint)
if len(self.gpx_trkpts)==0:print "Didn't find any valid trkpt :("
if len(self.gpx_trkpts)==0: self.errors += "Didn't find any valid trkpt :(\n"
if num_points_with_time == 0: self.errors += "None of your points have a <time> tag, please add such tags before processing with GPicSync\n"
print(self.errors)
print "Number of valid track points found: ",len(self.gpx_trkpts)
#print self.gpx_trkpts

Expand Down

0 comments on commit 34ac759

Please sign in to comment.