11
POS_PROVIDER = 'Ubuntu GeoIP'
13
# self.osm = osmgpsmap.GpsMap()
16
# osmgpsmap.GpsMapOsd(
23
class QRCodeSize(object):
31
def __init__(self, output_size = QRCodeSize.MEDIUM):
32
self.output_size = output_size
36
self.cr_surface = None
38
def encode(self, text):
39
return self._encode_to_pil(text)
41
def encode_to_cairo(self, text):
42
self._encode_to_pil(text)
44
# Convert the Python PIL image to a Cairo surface.
45
# Notice the conversion to BGRA that Cairo expects
46
# See http://cairographics.org/pythoncairopil/ and
47
# http://mail.gnome.org/archives/gtkmm-list/2007-May/msg00111.html
48
bytearr = array.array('B', self.image.tostring("raw", "BGRA", 0, 1))
49
height, width = self.image.size
52
self.cr_surface = cairo.ImageSurface.create_for_data(bytearr,
57
return self.cr_surface
59
def _encode_to_pil(self, text):
60
version, self.qrcode_size, self.image = qrencode.encode(text)
61
self.image = self.image.convert('RGBA')
68
self._set_pixel_size(self.qrcode_size)
69
print self.pixel_size, self.qrcode_size
70
self.image = self.image.resize((self.pixel_size * self.qrcode_size,
71
self.pixel_size * self.qrcode_size),
74
def _set_pixel_size(self, barcode_orig_size):
77
print pixel_size * barcode_orig_size, self.output_size
78
while (pixel_size * barcode_orig_size < self.output_size):
81
while ((pixel_size * barcode_orig_size > self.output_size) or \
82
((pixel_size * barcode_orig_size) % 2 != 0) or \
83
(pixel_size * barcode_orig_size + 2 * pixel_size > \
87
# FIXME: it needs to automatically go up to the next size,
88
# rather than hardcoding it as now
90
self.output_size = QRCodeSize.MEDIUM
92
self.pixel_size = pixel_size
94
def _add_border(self):
96
border_size = (self.output_size - self.image.size[0]) / 2
97
self.image = ImageOps.expand(self.image, border=border_size,
101
def get_current_location():
102
location = Geoclue.DiscoverLocation()
104
location.set_position_provider(POS_PROVIDER)
105
position = location.get_location_info()
106
return position['latitude'], position['longitude']