Permalink
Browse files

Initial - Version 0.0.2

  • Loading branch information...
0 parents commit 33ad94c13d31d5df31a1c8e262d55ef922afa6ca Daniel Fett committed Aug 29, 2009
Showing with 9,968 additions and 0 deletions.
  1. +9 −0 CONTROL/control
  2. +323 −0 usr/bin/advancedcaching.py
  3. BIN usr/bin/advancedcaching.pyc
  4. +1,309 −0 usr/lib/advancedcaching/glade/freerunner.glade
  5. +1,715 −0 usr/lib/advancedcaching/glade/main.glade
  6. +222 −0 usr/lib/advancedcaching/glade/options.glade
  7. +1,715 −0 usr/lib/advancedcaching/glade/simple.glade
  8. 0 usr/lib/site-python/advancedcachinglib/__init__.py
  9. BIN usr/lib/site-python/advancedcachinglib/__init__.pyc
  10. +821 −0 usr/lib/site-python/advancedcachinglib/biggui.py
  11. +50 −0 usr/lib/site-python/advancedcachinglib/downloader.py
  12. BIN usr/lib/site-python/advancedcachinglib/downloader.pyc
  13. +652 −0 usr/lib/site-python/advancedcachinglib/extListview.py
  14. BIN usr/lib/site-python/advancedcachinglib/extListview.pyc
  15. +114 −0 usr/lib/site-python/advancedcachinglib/geo.py
  16. BIN usr/lib/site-python/advancedcachinglib/geo.pyc
  17. +478 −0 usr/lib/site-python/advancedcachinglib/geocaching.py
  18. BIN usr/lib/site-python/advancedcachinglib/geocaching.pyc
  19. +108 −0 usr/lib/site-python/advancedcachinglib/gpsreader.py
  20. BIN usr/lib/site-python/advancedcachinglib/gpsreader.pyc
  21. +657 −0 usr/lib/site-python/advancedcachinglib/gui.py
  22. +200 −0 usr/lib/site-python/advancedcachinglib/openstreetmap.py
  23. BIN usr/lib/site-python/advancedcachinglib/openstreetmap.pyc
  24. +195 −0 usr/lib/site-python/advancedcachinglib/provider.py
  25. BIN usr/lib/site-python/advancedcachinglib/provider.pyc
  26. +1,385 −0 usr/lib/site-python/advancedcachinglib/simplegui.py
  27. BIN usr/lib/site-python/advancedcachinglib/simplegui.pyc
  28. +15 −0 usr/share/applications/advancedcaching.desktop
  29. BIN usr/share/pixmaps/advancedcaching.png
@@ -0,0 +1,9 @@
+Package: advancedcaching
+Section: x11
+Priority: optional
+Version: 0.0.2
+Architecture: all
+Maintainer: Daniel Fett
+Depends: python-pygtk, python-html, python-image, python-netclient, python-misc, python-sqlite3
+Source: none
+Description: "towards paperless geocaching"
@@ -0,0 +1,323 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Copyright (C) 2009 Daniel Fett
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Daniel Fett simplecaching@fragcom.de
+#
+
+
+
+import re
+
+### For loading the conf file
+import ConfigParser
+import os
+import sys
+import gtk
+import gobject
+import thread
+import json
+
+#import cProfile
+#import pstats
+
+sys.path.append('/usr/lib/site-python')
+from advancedcachinglib import openstreetmap, provider, downloader, geo, geocaching, gpsreader, extListview
+
+from time import sleep
+
+
+if len(sys.argv) != 2:
+ print "Usage: %s --desktop (not fully implemented yet) or %s --simple" % (sys.argv[0], sys.argv[0])
+ exit()
+
+arg = sys.argv[1].strip()
+if arg == '--simple':
+ from advancedcachinglib import simplegui
+ gui = simplegui.SimpleGui
+else:
+ from advancedcachinglib import biggui
+ gui = biggui.BigGui
+
+
+class Standbypreventer():
+ STATUS_NONE = 0
+ STATUS_ALIVE = 1
+ STATUS_SCREEN_ON = 2
+
+ def __init__(self):
+ self.requested_status = self.STATUS_NONE
+
+ def __del__(self):
+ self._unrequest_all()
+
+ def set_status(self, status):
+ if status != self.requested_status:
+ self._unrequest_all()
+ self._request(status)
+
+ def _unrequest_all(self):
+ if self.requested_status == self.STATUS_ALIVE:
+ self._try_run('dbus-send --system --type=method_call --dest=org.shr.ophonekitd.Usage /org/shr/ophonekitd/Usage org.shr.ophonekitd.Usage.ReleaseResource string:CPU')
+ elif self.requested_status == self.STATUS_SCREEN_ON:
+ self._try_run('dbus-send --system --type=method_call --dest=org.shr.ophonekitd.Usage /org/shr/ophonekitd/Usage org.shr.ophonekitd.Usage.ReleaseResource string:Display')
+
+ def _request(self, status):
+ if status == self.STATUS_ALIVE:
+ self._try_run('dbus-send --system --type=method_call --dest=org.shr.ophonekitd.Usage /org/shr/ophonekitd/Usage org.shr.ophonekitd.Usage.RequestResource string:CPU')
+ elif status == self.STATUS_SCREEN_ON:
+ self._try_run('dbus-send --system --type=method_call --dest=org.shr.ophonekitd.Usage /org/shr/ophonekitd/Usage org.shr.ophonekitd.Usage.RequestResource string:Display')
+
+ def _try_run(self, command):
+ try:
+ os.system(command)
+ except Exception as e:
+ print "Could not prevent Standby: %s" % e
+
+class Core():
+ SETTINGS_DIR = os.path.expanduser('~/.agtl')
+ DEFAULT_SETTINGS = {
+ 'download_visible' : True,
+ 'download_notfound' : True,
+ 'download_new' : True,
+ 'download_nothing' : False,
+ 'download_create_index' : True,
+ 'download_run_after' : False,
+ 'download_run_after_string' : '',
+ 'download_output_dir' : os.path.expanduser('~/caches/'),
+ 'map_position_lat' : 49.7540,
+ 'map_position_lon' : 6.66135,
+ 'map_zoom' : 7,
+ 'download_resize' : True,
+ 'download_resize_pixel' : 400,
+ 'options_show_name' : True,
+ 'options_username' : "Username",
+ 'options_password' : "Pass",
+ 'last_target_lat' : 50,
+ 'last_target_lon' : 10,
+ 'last_target_name' : 'default',
+ 'download_noimages' : False,
+ 'download_map_path' : os.path.expanduser('~/Maps/OSM/')
+ }
+
+ def __init__(self, guitype):
+ if not os.path.exists(self.SETTINGS_DIR):
+ os.mkdir(self.SETTINGS_DIR)
+
+ self.standbypreventer = Standbypreventer()
+
+ self.read_config()
+
+ self.standbypreventer.set_status(Standbypreventer.STATUS_SCREEN_ON)
+
+ self.downloader = downloader.FileDownloader(self.settings['options_username'], self.settings['options_password'])
+
+ #pointprovider = LiveCacheProvider()
+ self.pointprovider = provider.PointProvider("%s/caches.db" % self.SETTINGS_DIR, self.downloader, geocaching.GeocacheCoordinate, 'geocaches')
+ self.userpointprovider = provider.PointProvider("%s/caches.db" % self.SETTINGS_DIR, self.downloader, geo.Coordinate, 'userpoints')
+ #pointprovider = PointProvider(':memory:', self.downloader)
+ #reader = GpxReader(pointprovider)
+ #reader.read_file('../../file.loc')
+
+
+ self.gui = guitype(self, self.pointprovider, self.userpointprovider)
+ self.gui.write_settings(self.settings)
+
+ self.gps_thread = gpsreader.GpsReader(self)
+ gobject.timeout_add(1000, self.read_gps)
+
+ self.gui.show()
+
+
+
+ def __del__(self):
+ self.settings = self.gui.read_settings()
+ self.write_config()
+
+ #def search_value_terrain_change(self, a):
+# #print a, b, c
+ #if self.search_elements['terrain']['upper'].get_adjustment().get_value() < self.search_elements['terrain']['lower'].get_adjustment().get_value():
+ # self.search_elements['terrain'][
+ #def search_value_diff_change(self, widget):
+ #pass
+
+
+
+
+
+
+ # called by gui
+ def on_cache_selected(self, cache):
+ self.gui.show_cache(cache)
+
+ # called by gui
+ def on_start_search_simple(self, text):
+ #m = re.search(r'/([NS]?)\s*(\d{1,2})\.(\d{1,2})\D+(\d+)\s*([WE]?)\s*(\d{1,3})\.(\d{1,2})\D+(\d+)', text, re.I)
+ #if m != None:
+ self.try_show_cache_by_search('%' + text + '%')
+
+ # called by gui
+ def on_start_search_advanced(self, found = None, owner_search = '', name_search = '', size = None, terrain = None, diff = None, ctype = None):
+
+
+ self.pointprovider.set_filter(found = found, owner_search = owner_search, name_search = name_search, size = size, terrain = terrain, diff = diff, ctype = ctype)
+ points = self.pointprovider.get_points_filter()
+ self.gui.display_results_advanced(points)
+
+
+ # called by gui
+ def on_destroy(self):
+ self.settings = self.gui.read_settings()
+ self.write_config()
+
+ # called by gui
+ def on_download(self, location):
+ cd = geocaching.CacheDownloader(self.downloader)
+ caches = cd.get_geocaches(location)
+ for c in caches:
+ self.pointprovider.add_point(c)
+ self.pointprovider.save()
+
+ # called by gui
+ def on_download_cache(self, cache):
+ cd = geocaching.CacheDownloader(self.downloader)
+ exporter = geocaching.HTMLExporter(self.downloader, self.settings['download_output_dir'])
+ full = cd.update_coordinate(cache)
+ self.pointprovider.add_point(full, True)
+ exporter.export(full)
+ self.pointprovider.save()
+
+
+
+
+ # called by gui
+ def on_download_descriptions(self, location):
+ cd = geocaching.CacheDownloader(self.downloader)
+ exporter = geocaching.HTMLExporter(self.downloader, self.settings['download_output_dir'])
+
+ self.pointprovider.push_filter()
+
+ if self.settings['download_notfound']:
+ found = False
+ else:
+ found = None
+
+ if self.settings['download_new']:
+ has_details = False
+ elif self.settings['download_nothing']:
+ has_details = True
+ else:
+ has_details = None
+
+
+ if self.settings['download_visible']:
+ self.pointprovider.set_filter(found = found, has_details = has_details, adapt_filter = True)
+ caches = self.pointprovider.get_points_filter(location)
+ else:
+ self.pointprovider.set_filter(found = found, has_details = has_details, adapt_filter = False)
+ caches = self.pointprovider.get_points_filter()
+
+
+
+ count = len(caches)
+ i = 0.0
+ try:
+ for cache in caches:
+ self.gui.set_download_progress(i/count, "Downloading %s..." % cache.name)
+ while gtk.events_pending():
+ gtk.main_iteration()
+ full = cd.update_coordinate(cache)
+ self.pointprovider.add_point(full, True)
+ exporter.export(full)
+ i += 1.0
+ self.gui.set_download_progress(0, 'Finished!')
+ except Exception as e:
+ self.gui.show_error(e)
+ self.pointprovider.save()
+
+ self.pointprovider.pop_filter()
+
+ #if self.settings['download_create_index']:
+ # all_caches = pointprovider.get_points_filter(None, None, True)
+ # exporter.write_index(all_caches)
+
+
+
+
+ # called by gui
+ def on_config_changed(self, new_settings):
+ self.settings = new_settings
+ self.downloader.update_userdata(self.settings['options_username'], self.settings['options_password'])
+ self.write_config()
+
+
+
+
+ def read_gps(self):
+ gps_data = self.gps_thread.get_data()
+ if (gps_data['position'] != None):
+ self.gui.on_good_fix(gps_data)
+ else:
+ self.gui.on_no_fix(gps_data, self.gps_thread.status)
+ return True
+
+ def read_config(self):
+ filename = os.path.join(self.SETTINGS_DIR, 'config')
+ if not os.path.exists(filename):
+ self.settings = self.DEFAULT_SETTINGS
+ return
+ f = file(filename, 'r')
+ string = f.read()
+ self.settings = {}
+ if string != '':
+ tmp_settings = json.loads(string)
+ for k, v in self.DEFAULT_SETTINGS.items():
+ if k in tmp_settings.keys() != None:
+ self.settings[k] = tmp_settings[k]
+ else:
+ self.settings[k] = self.DEFAULT_SETTINGS[k]
+ else:
+ self.settings = self.DEFAULT_SETTINGS
+
+
+
+ def try_show_cache_by_search(self, idstring):
+ cache = self.pointprovider.find_by_string(idstring)
+ if cache != None:
+ self.gui.show_cache(cache)
+ self.gui.set_center(cache)
+ return True
+ return False
+
+ def write_config(self):
+
+
+ filename = os.path.join(self.SETTINGS_DIR, 'config')
+ f = file(filename, 'w')
+ f.write(json.dumps(self.settings, sort_keys=True, indent=4))
+
+
+
+
+
+
+
+if __name__ == "__main__":
+ gtk.gdk.threads_init()
+ core = Core(gui)
+
+
+
Binary file not shown.
Oops, something went wrong.

0 comments on commit 33ad94c

Please sign in to comment.