reorganize files and bring code inline with current master
Conflicts: lib/simple_config.py
This commit is contained in:
@@ -7,69 +7,23 @@ from collections import namedtuple
|
||||
|
||||
from kivy.uix.anchorlayout import AnchorLayout
|
||||
from kivy.core import core_select_lib
|
||||
from kivy.metrics import dp
|
||||
from kivy.properties import ListProperty, BooleanProperty
|
||||
from kivy.factory import Factory
|
||||
|
||||
|
||||
def encode_uri(addr, amount=0, label='', message='', size='',
|
||||
currency='btc'):
|
||||
''' Convert to BIP0021 compatible URI
|
||||
'''
|
||||
uri = 'bitcoin:{}'.format(addr)
|
||||
first = True
|
||||
if amount:
|
||||
uri += '{}amount={}'.format('?' if first else '&', amount)
|
||||
first = False
|
||||
if label:
|
||||
uri += '{}label={}'.format('?' if first else '&', label)
|
||||
first = False
|
||||
if message:
|
||||
uri += '{}?message={}'.format('?' if first else '&', message)
|
||||
first = False
|
||||
if size:
|
||||
uri += '{}size={}'.format('?' if not first else '&', size)
|
||||
return uri
|
||||
|
||||
def decode_uri(uri):
|
||||
if ':' not in uri:
|
||||
# It's just an address (not BIP21)
|
||||
return {'address': uri}
|
||||
|
||||
if '//' not in uri:
|
||||
# Workaround for urlparse, it don't handle bitcoin: URI properly
|
||||
uri = uri.replace(':', '://')
|
||||
|
||||
try:
|
||||
uri = urlparse(uri)
|
||||
except NameError:
|
||||
# delayed import
|
||||
from urlparse import urlparse, parse_qs
|
||||
uri = urlparse(uri)
|
||||
|
||||
result = {'address': uri.netloc}
|
||||
|
||||
if uri.path.startswith('?'):
|
||||
params = parse_qs(uri.path[1:])
|
||||
else:
|
||||
params = parse_qs(uri.path)
|
||||
|
||||
for k,v in params.items():
|
||||
if k in ('amount', 'label', 'message', 'size'):
|
||||
result[k] = v[0]
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class ScannerBase(AnchorLayout):
|
||||
''' Base implementation for camera based scanner
|
||||
'''
|
||||
camera_size = ListProperty([320, 240])
|
||||
camera_size = ListProperty([320, 240] if dp(1) < 2 else [640, 480])
|
||||
|
||||
symbols = ListProperty([])
|
||||
|
||||
# XXX can't work now, due to overlay.
|
||||
show_bounds = BooleanProperty(False)
|
||||
|
||||
running = BooleanProperty(False)
|
||||
|
||||
Qrcode = namedtuple('Qrcode',
|
||||
['type', 'data', 'bounds', 'quality', 'count'])
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class SurfaceHolderCallback(PythonJavaClass):
|
||||
def __init__(self, callback):
|
||||
super(SurfaceHolderCallback, self).__init__()
|
||||
self.callback = callback
|
||||
|
||||
|
||||
@java_method('(Landroid/view/SurfaceHolder;III)V')
|
||||
def surfaceChanged(self, surface, fmt, width, height):
|
||||
self.callback(fmt, width, height)
|
||||
@@ -96,7 +96,7 @@ class SurfaceHolderCallback(PythonJavaClass):
|
||||
@java_method('(Landroid/view/SurfaceHolder;)V')
|
||||
def surfaceCreated(self, surface):
|
||||
pass
|
||||
|
||||
|
||||
@java_method('(Landroid/view/SurfaceHolder;)V')
|
||||
def surfaceDestroyed(self, surface):
|
||||
pass
|
||||
@@ -170,6 +170,7 @@ class AndroidCamera(Widget):
|
||||
|
||||
@run_on_ui_thread
|
||||
def stop(self):
|
||||
self.running = False
|
||||
if self._android_camera is None:
|
||||
return
|
||||
self._android_camera.setPreviewCallback(None)
|
||||
@@ -179,6 +180,7 @@ class AndroidCamera(Widget):
|
||||
|
||||
@run_on_ui_thread
|
||||
def start(self):
|
||||
self.running = True
|
||||
if self._android_camera is not None:
|
||||
return
|
||||
|
||||
@@ -196,6 +198,9 @@ class AndroidCamera(Widget):
|
||||
# attach the android surfaceview to our android widget holder
|
||||
self._holder.view = self._android_surface
|
||||
|
||||
# set orientation
|
||||
self._android_camera.setDisplayOrientation(90)
|
||||
|
||||
def _on_surface_changed(self, fmt, width, height):
|
||||
# internal, called when the android SurfaceView is ready
|
||||
# FIXME if the size is not handled by the camera, it will failed.
|
||||
|
||||
Reference in New Issue
Block a user