def OnGpsUpload(self, event=None): """ Uploads caches to GPS """ self.pushStatus(_("Uploading caches to GPS")) opts = ExportOptions(self, True) if opts.ShowModal() == wx.ID_OK: opts.SaveConf() caches = self.selectCaches(True) if len(caches) == 0: wx.MessageBox( parent=self, message=_("With the current settings there is nothing to export!"), caption=_("Nothing to export"), style=wx.OK | wx.ICON_ERROR, ) else: fd, tmpFile = tempfile.mkstemp() gpx = Gpx() if gpx.export(tmpFile, caches): gpsCom = GpsCom(gps=geocacher.config().gpsType, port=geocacher.config().gpsConnection) ok, message = gpsCom.gpxToGps(tmpFile) if not ok: self.GpsError(message) os.remove(tmpFile) self.popStatus()
def LoadFile(self, path): """ Handles the loading/importing of a waypoint file. Argument path: Path to the file to be loaded/imported. """ ext = os.path.splitext(path)[1] sucess = False gpx = Gpx() if ext == ".gpx": sucess, changes = gpx.load(path) elif ext == ".zip": sucess, changes = gpx.zipLoad(path) else: changes = {} sucess = True if sucess == False: wx.MessageDialog( self, _('Could not import "%s" due to an error accessing the file') % path, caption=_("File import error"), style=wx.OK | wx.ICON_WARNING, ) return changes
def OnGpsUpload(self, event=None): ''' Uploads caches to GPS ''' self.pushStatus(_('Uploading caches to GPS')) opts = ExportOptions(self, True) if opts.ShowModal() == wx.ID_OK: opts.SaveConf() caches = self.selectCaches(True) if len(caches) == 0: wx.MessageBox( parent=self, message=_( 'With the current settings there is nothing to export!' ), caption=_('Nothing to export'), style=wx.OK | wx.ICON_ERROR) else: fd, tmpFile = tempfile.mkstemp() gpx = Gpx() if gpx.export( tmpFile, caches, ): gpsCom = GpsCom(gps=geocacher.config().gpsType, port=geocacher.config().gpsConnection) ok, message = gpsCom.gpxToGps(tmpFile) if not ok: self.GpsError(message) os.remove(tmpFile) self.popStatus()
def LoadFile(self, path): ''' Handles the loading/importing of a waypoint file. Argument path: Path to the file to be loaded/imported. ''' ext = os.path.splitext(path)[1] sucess = False gpx = Gpx() if ext == '.gpx': sucess, changes = gpx.load(path) elif ext == '.zip': sucess, changes = gpx.zipLoad(path) else: changes = {} sucess = True if sucess == False: wx.MessageDialog( self, _('Could not import "%s" due to an error accessing the file') % path, caption=_("File import error"), style=wx.OK | wx.ICON_WARNING) return changes
def OnExportWpt(self, event=None): ''' Handles the event from the "Export Waypoints to file" menu item. Keyword Argument event: The event causing this function to be called. ''' self.pushStatus(_('Exporting caches to file')) opts = ExportOptions(self, False) if opts.ShowModal() == wx.ID_OK: opts.SaveConf() config = geocacher.config() path = config.exportFile self.popStatus() self.pushStatus(_('Exporting caches to file: %s') % path) if os.path.isfile(path): question = wx.MessageDialog( None, message= _('"%s" already exists are you sure you want to replace it ?' ) % path, caption=_('File Already Exists'), style=wx.YES_NO | wx.ICON_WARNING) if question.ShowModal() == wx.ID_NO: question.Destroy() self.popStatus() return ext = os.path.splitext(path)[1] caches = self.selectCaches(False) if len(caches) == 0: wx.MessageBox( parent=self, message=_( 'With the current settings there is nothing to export!' ), caption=_('Nothing to export'), style=wx.OK | wx.ICON_ERROR) else: gpx = Gpx() if ext == '.gpx': ret = gpx.export(path, caches) elif ext == '.zip': ret = gpx.zipExport(path, caches) else: ret = True wx.MessageBox( parent=self, message= _('Error exporting to file: %s\n file type not supported' ) % config.exportPath, caption=_('Way point export Error'), style=wx.OK | wx.ICON_ERROR) if not ret: wx.MessageBox(parent=self, message=_('Error exporting to file: %s') % path, caption=_('Way point export Error'), style=wx.OK | wx.ICON_ERROR) self.popStatus()
def OnExportWpt(self, event=None): """ Handles the event from the "Export Waypoints to file" menu item. Keyword Argument event: The event causing this function to be called. """ self.pushStatus(_("Exporting caches to file")) opts = ExportOptions(self, False) if opts.ShowModal() == wx.ID_OK: opts.SaveConf() config = geocacher.config() path = config.exportFile self.popStatus() self.pushStatus(_("Exporting caches to file: %s") % path) if os.path.isfile(path): question = wx.MessageDialog( None, message=_('"%s" already exists are you sure you want to replace it ?') % path, caption=_("File Already Exists"), style=wx.YES_NO | wx.ICON_WARNING, ) if question.ShowModal() == wx.ID_NO: question.Destroy() self.popStatus() return ext = os.path.splitext(path)[1] caches = self.selectCaches(False) if len(caches) == 0: wx.MessageBox( parent=self, message=_("With the current settings there is nothing to export!"), caption=_("Nothing to export"), style=wx.OK | wx.ICON_ERROR, ) else: gpx = Gpx() if ext == ".gpx": ret = gpx.export(path, caches) elif ext == ".zip": ret = gpx.zipExport(path, caches) else: ret = True wx.MessageBox( parent=self, message=_("Error exporting to file: %s\n file type not supported") % config.exportPath, caption=_("Way point export Error"), style=wx.OK | wx.ICON_ERROR, ) if not ret: wx.MessageBox( parent=self, message=_("Error exporting to file: %s") % path, caption=_("Way point export Error"), style=wx.OK | wx.ICON_ERROR, ) self.popStatus()