Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

moved methods into Map class

  • Loading branch information...
commit 4d0ed242be61687cbcf9b1790ecf62457e6568f9 1 parent 7a804e1
Albert Sun authored
Showing with 42 additions and 22 deletions.
  1. +38 −21 simpyl_tiles.py
  2. +4 −1 test.py
59 simpyl_tiles.py
View
@@ -1,44 +1,61 @@
import ctypes
from ctypes import *
-from ctypes.util import find_lib
+from ctypes.util import find_library
+# Make sure ctypes can find simple tiles
+lib = ctypes.CDLL(find_library("simple-tiles"))
def bind_function(func, restype=None, argtypes=[]):
if restype:
func.restype = restype
if argtypes:
func.argtypes = argtypes
- return func
+
+ def wrapper(*args):
+ print args
+ return func(*args[1:])
+ return wrapper
def status_output(func, argtypes=[]):
return bind_function(func, c_void_p, argtypes)
-# Make sure ctypes can find simple tiles
-lib = ctypes.CDLL(find_lib("simple-tiles"))
-
-map_new = bind_function(lib.simplet_map_new, c_void_p)
-map_free = bind_function(lib.simplet_map_free, None, [c_void_p])
+def str_ptr_output(func, restype=None, argtypes=[]):
+ argtypes.append(POINTER(c_char_p))
+ inner_func = bind_function(func, restype, argtypes)
+ def wrapper(*args):
+ a = c_char_p("")
+ args += (a,)
+ inner_func(*args)
+ str_value = a.value
+ lib.free(a)
+ return str_value
+ return wrapper
+
-set_srs = status_output(lib.simplet_map_set_srs, [c_void_p, c_char_p])
-get_srs = bind_function(lib.simplet_map_get_srs, None, [c_void_p, POINTER(c_char_p)])
+class Map:
-set_size = status_output(lib.simplet_map_set_size, [c_void_p, c_uint, c_uint])
-get_width = bind_function(lib.simplet_map_get_width, c_uint, [c_void_p])
-get_height = bind_function(lib.simplet_map_get_height, c_uint, [c_void_p])
-set_width = status_output(lib.simplet_map_set_width, [c_void_p, c_uint])
-set_height = status_output(lib.simplet_map_set_height, [c_void_p, c_uint])
-set_bounds = status_output(lib.simplet_map_set_bounds, [c_void_p, c_double, c_double, c_double, c_double])
-set_slippy = status_output(lib.simplet_map_set_slippy, [c_void_p, c_uint, c_uint, c_uint])
+ map_new = bind_function(lib.simplet_map_new, c_void_p)
+ map_free = bind_function(lib.simplet_map_free, None, [c_void_p])
-set_bgcolor = status_output(lib.simplet_map_set_bgcolor, [c_void_p, c_char_p])
-get_bgcolor = bind_function(lib.simplet_map_get_bgcolor, None, [c_void_p, POINTER(c_char_p)])
+ set_srs = status_output(lib.simplet_map_set_srs, [c_void_p, c_char_p])
+ get_srs = str_ptr_output(lib.simplet_map_get_srs, None, [c_void_p])
-status_to_string = bind_function(lib.simplet_map_status_to_string, c_char_p, [c_void_p])
+ set_size = status_output(lib.simplet_map_set_size, [c_void_p, c_uint, c_uint])
+ get_width = bind_function(lib.simplet_map_get_width, c_uint, [c_void_p])
+ get_height = bind_function(lib.simplet_map_get_height, c_uint, [c_void_p])
+ set_width = status_output(lib.simplet_map_set_width, [c_void_p, c_uint])
+ set_height = status_output(lib.simplet_map_set_height, [c_void_p, c_uint])
+ set_bounds = status_output(lib.simplet_map_set_bounds, [c_void_p, c_double, c_double, c_double, c_double])
+ set_slippy = status_output(lib.simplet_map_set_slippy, [c_void_p, c_uint, c_uint, c_uint])
+ set_bgcolor = status_output(lib.simplet_map_set_bgcolor, [c_void_p, c_char_p])
+ get_bgcolor = str_ptr_output(lib.simplet_map_get_bgcolor, None, [c_void_p])
-class Map:
+ status_to_string = bind_function(lib.simplet_map_status_to_string, c_char_p, [c_void_p])
def __init__(self):
- self._map = c_void_p(map_new())
+ self._map = c_void_p(self.map_new())
+ def __del__(self):
+ self.map_free(self._map)
5 test.py
View
@@ -1,5 +1,8 @@
from simpyl_tiles import *
map = Map()
-
+print map.set_srs(map._map, "WGS84")
+print map.status_to_string(map._map)
+print map.get_srs(map._map)
+del map
Please sign in to comment.
Something went wrong with that request. Please try again.