Exemplo n.º 1
0
    def __init__(self, guitype, root):
        gobject.GObject.__init__(self)
        self.current_target = None
        self.current_position = None
        self.create_recursive(self.SETTINGS_DIR)

        dataroot = path.join(root, "data")

        self._install_updates()

        self.__read_config()
        self.connect("settings-changed", self.__on_settings_changed)
        self.connect("save-settings", self.__on_save_settings)
        self.create_recursive(self.settings["download_output_dir"])
        self.create_recursive(self.settings["download_map_path"])

        self.downloader = downloader.FileDownloader(
            self.settings["options_username"],
            self.settings["options_password"],
            self.COOKIE_FILE,
            cachedownloader.GeocachingComCacheDownloader.login_callback,
        )

        self.pointprovider = provider.PointProvider(self.CACHES_DB, geocaching.GeocacheCoordinate, "geocaches")

        self.gui = guitype(self, dataroot)

        actor_tts = TTS(self)
        actor_tts.connect("error", lambda caller, msg: self.gui.show_error(msg))
        # actor_notify = Notify(self)

        self.emit("settings-changed", self.settings, self)

        if "--sim" in argv:
            self.gps_thread = gpsreader.FakeGpsReader(self)
            gobject.timeout_add(1000, self.__read_gps)
            self.set_target(gpsreader.FakeGpsReader.get_target())
        elif "gpsprovider" in self.gui.USES:
            self.gps_thread = gpsreader.GpsReader()
            # self.gps_thread = gpsreader.FakeGpsReader(self)
            gobject.timeout_add(1000, self.__read_gps)
        elif "locationgpsprovider" in self.gui.USES:
            self.gps_thread = gpsreader.LocationGpsReader(self.__read_gps_cb_error, self.__read_gps_cb_changed)
            gobject.idle_add(self.gps_thread.start)
        if "geonames" in self.gui.USES:
            import geonames

            self.geonames = geonames.Geonames(self.downloader)

        if "--startup-only" in argv:
            return

        self.gui.show()
Exemplo n.º 2
0
class Core(gobject.GObject):

    __gsignals__ = {
        'map-marks-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()),
        'cache-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
                          (gobject.TYPE_PYOBJECT, )),
        'fieldnotes-changed':
        (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()),
        'good-fix': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
                     (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
                      gobject.TYPE_PYOBJECT)),
        'no-fix': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
                   (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT)),
        'target-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
                           (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT,
                            gobject.TYPE_PYOBJECT)),
        'settings-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (
            gobject.TYPE_PYOBJECT,
            gobject.TYPE_PYOBJECT,
        )),
        'save-settings': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()),
        'error': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
                  (gobject.TYPE_PYOBJECT, )),
        'progress': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, (
            gobject.TYPE_PYOBJECT,
            gobject.TYPE_PYOBJECT,
        )),
        'hide-progress': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ()),
    }

    SETTINGS_DIR = path.expanduser(path.join('~', '.agtl'))
    CACHES_DB = path.join(SETTINGS_DIR, "caches.db")
    COOKIE_FILE = path.join(SETTINGS_DIR, "cookies.lwp")
    UPDATE_DIR = path.join(SETTINGS_DIR, 'updates')

    MAEMO_HOME = path.expanduser(path.join('~', 'MyDocs', '.'))
    MAPS_DIR = path.join('Maps', '')

    DATA_DIR = path.expanduser(path.join(
        '~', '')) if not path.exists(MAEMO_HOME) else MAEMO_HOME

    UPDATE_MODULES = [cachedownloader]

    updating_lock = threading.Lock()
    _geocache_by_name_event = threading.Event()

    DEFAULT_SETTINGS = {
        'download_visible':
        True,
        'download_notfound':
        True,
        'download_new':
        True,
        'download_nothing':
        False,
        'download_create_index':
        False,
        'download_run_after':
        False,
        'download_run_after_string':
        '',
        'download_output_dir':
        path.expanduser(path.join(DATA_DIR, '.geocaches', '')),
        'map_position_lat':
        49.7540,
        'map_position_lon':
        6.66135,
        'map_follow_position':
        True,
        'map_zoom':
        7,
        'download_resize':
        True,
        'download_resize_pixel':
        400,
        'options_show_name':
        True,
        'options_username':
        "",
        'options_password':
        "",
        'last_target_lat':
        50,
        'last_target_lon':
        10,
        'last_target_name':
        'default',
        'last_selected_geocache':
        '',
        'download_noimages':
        False,
        'download_map_path':
        DATA_DIR + MAPS_DIR,
        'options_hide_found':
        False,
        'options_show_error':
        True,
        'options_show_html_description':
        False,
        'map_providers': [
            ('OpenStreetMaps', {
                'remote_url':
                "http://tile.openstreetmap.org/%(zoom)d/%(x)d/%(y)d.png",
                'prefix': 'OpenStreetMap I',
                'max_zoom': 18
            }),
            ('OpenCycleMaps', {
                'remote_url':
                'http://a.tile.opencyclemap.org/cycle/%(zoom)d/%(x)d/%(y)d.png',
                'prefix': 'OpenCycleMap',
                'max_zoom': 18
            }),
        ],
        'options_map_double_size':
        False,
        'options_rotate_screen':
        0,
        'tts_interval':
        0,
        'options_default_log_text':
        'TFTC!\n\nLogged at %X from my %(machine)s using AGTL.',
        'options_auto_update':
        True,
        'download_num_logs':
        20,
        'options_night_view_mode':
        0,
        'debug_log_to_http':
        False,
        'options_backend':
        'geocaching-com-new',
        'options_redownload_after':
        14,
        'use_assisted_gps':
        True,
        'gps_interval_seconds':
        1,
    }

    def __init__(self, guitype, gpstype, extensions):
        """
        Initialize the application.
        
        guitype -- Python type of the gui which is to be used.
        gpstype -- String indicating the desired GPS access method.
        extensions -- List of strings indicating desired extensions.
        """
        gobject.GObject.__init__(self)
        self.current_target = None
        self.current_position = None
        self.auto_update_checked = False
        self.create_recursive(self.SETTINGS_DIR)

        # self.cachedownloader is populated in settings handling.
        self.cachedownloader = None
        self._install_updates()

        self.__read_config()

        # Check tile URLs for outdated URLs after Openstreetmap URL change
        for name, details in self.settings['map_providers']:
            prev = details['remote_url']
            details['remote_url'] = sub(r'//(.*).openstreetmap.org/([a-z]*/)?',
                                        '//tile.openstreetmap.org/', prev)
            if prev != details['remote_url']:
                logger.info(
                    "Replaced url '%s' with '%s' because Openstreetmaps changed their URLs."
                    % (prev, details['remote_url']))

        self.connect('settings-changed', self.__on_settings_changed)
        self.connect('save-settings', self.__on_save_settings)
        self.create_recursive(self.settings['download_output_dir'])
        self.create_recursive(self.settings['download_map_path'])

        self.downloader = downloader.FileDownloader(
            self.settings['options_username'],
            self.settings['options_password'], self.COOKIE_FILE)

        # Download log-type icons
        #logger.info("Download log-type icons")
        import os
        filename = os.path.join(self.settings['download_output_dir'], "1.png")
        if os.path.isfile(filename):
            logger.info("%s exists already, don't reload icons for log-types" %
                        filename)
        else:
            #server have mystery ranges of filenames
            icons = range(1, 26) + range(45, 49) + range(54, 58) + range(
                67, 78)
            #for some reason some numbers are not used
            icons.remove(8)
            icons.remove(20)
            icons.remove(21)

            for i in icons:
                filename = os.path.join(self.settings['download_output_dir'],
                                        "%s.png" % i)
                url = "https://www.geocaching.com/images/logtypes/%s.png" % i
                logger.info("Downloading icon for log-type %s to %s" %
                            (url, filename))

                try:
                    f = open(filename, 'wb')
                    f.write(
                        downloader.read_from_network(
                            self.downloader.get_reader(url, login=False)))
                    f.close()
                except Exception, e:
                    logger.exception(e)
                    logger.error("Failed to download image from URL %s" % url)

        self.pointprovider = provider.PointProvider(
            self.CACHES_DB, geocaching.GeocacheCoordinate)

        self.gui = guitype(self)

        if ('debug_log_to_http' in self.settings
                and self.settings['debug_log_to_http']) or '--remote' in argv:
            http_handler = logging.handlers.HTTPHandler(
                "danielfett.de", "https://www.danielfett.de/files/collect.php")
            buffering_handler = logging.handlers.MemoryHandler(
                100, target=http_handler)
            logging.getLogger('').addHandler(buffering_handler)
            logging.getLogger('').setLevel(logging.DEBUG)
            logging.debug("Remote logging activated!")
            # Now reset the setting to default
            self.settings['debug_log_to_http'] = False

        self.emit('settings-changed', self.settings, self)
        self.emit('fieldnotes-changed')

        self.__setup_gps(gps)

        if 'geonames' in extensions:
            import geonames
            self.geonames = geonames.Geonames(self.downloader)

        if 'tts' in extensions:
            from actors.notify import Notify
            actor_tts = TTS(self)
            actor_tts.connect('error',
                              lambda caller, msg: self.emit('error', msg))
            actor_notify = Notify(self)

        if '--startup-only' in argv:
            return

        self.gui.show()
        if not '--profile' in argv:
            exit()
Exemplo n.º 3
0
    def __init__(self, guitype, gpstype, extensions):
        """
        Initialize the application.
        
        guitype -- Python type of the gui which is to be used.
        gpstype -- String indicating the desired GPS access method.
        extensions -- List of strings indicating desired extensions.
        """
        gobject.GObject.__init__(self)
        self.current_target = None
        self.current_position = None
        self.auto_update_checked = False
        self.create_recursive(self.SETTINGS_DIR)

        # self.cachedownloader is populated in settings handling.
        self.cachedownloader = None
        self._install_updates()

        self.__read_config()
        
        # Check tile URLs for outdated URLs after Openstreetmap URL change
        for name, details in self.settings['map_providers']:
            prev = details['remote_url']
            details['remote_url'] = sub(r'//(.*).openstreetmap.org/([a-z]*/)?', '//tile.openstreetmap.org/', prev)
            if prev != details['remote_url']:
                logger.info("Replaced url '%s' with '%s' because Openstreetmaps changed their URLs." % (prev, details['remote_url']))
        
        self.connect('settings-changed', self.__on_settings_changed)
        self.connect('save-settings', self.__on_save_settings)
        self.create_recursive(self.settings['download_output_dir'])
        self.create_recursive(self.settings['download_map_path'])
        
        self.downloader = downloader.FileDownloader(self.COOKIE_FILE)
                
        self.pointprovider = provider.PointProvider(self.CACHES_DB, geocaching.GeocacheCoordinate)

        self.gui = guitype(self)
        
        
        if ('debug_log_to_http' in self.settings and self.settings['debug_log_to_http']) or '--remote' in argv:
            http_handler = logging.handlers.HTTPHandler("danielfett.de", "http://www.danielfett.de/files/collect.php")
            buffering_handler = logging.handlers.MemoryHandler(100, target = http_handler)
            logging.getLogger('').addHandler(buffering_handler)
            logging.getLogger('').setLevel(logging.DEBUG)
            logging.debug("Remote logging activated!")
            # Now reset the setting to default
            self.settings['debug_log_to_http'] = False
        
        
        self.emit('settings-changed', self.settings, self)
        self.emit('fieldnotes-changed')  

        self.__setup_gps(gps)
            
        if 'geonames' in extensions:
            import geonames
            self.geonames = geonames.Geonames(self.downloader)
            
        if 'tts' in extensions:
            from actors.notify import Notify
            actor_tts = TTS(self)
            actor_tts.connect('error', lambda caller, msg: self.emit('error', msg))
            actor_notify = Notify(self)

        if '--startup-only' in argv:
            return

        self.gui.show()
        if not '--profile' in argv:
            exit()