Browse Source

Abstract and enable qrscanner dialog for send screen.

283
akshayaurora 11 years ago
committed by ThomasV
parent
commit
f442cc31e4
  1. 8
      gui/kivy/main_window.py
  2. 1
      gui/kivy/qr_scanner/__init__.py
  3. 19
      gui/kivy/qr_scanner/scanner_camera.py
  4. 7
      gui/kivy/uix/dialogs/new_contact.py
  5. 11
      gui/kivy/uix/dialogs/qr_scanner.py
  6. 11
      gui/kivy/uix/screens.py
  7. 2
      gui/kivy/uix/ui_screens/mainscreen.kv

8
gui/kivy/main_window.py

@ -200,6 +200,14 @@ class ElectrumWindow(App):
def set_url(self, instance, url): def set_url(self, instance, url):
self.gui_object.set_url(url) self.gui_object.set_url(url)
def scan_qr(self, on_complete):
dlg = Cache.get('electrum_widgets', 'QrScannerDialog')
if not dlg:
dlg = Factory.QrScannerDialog()
Cache.append('electrum_widgets', 'QrScannerDialog', dlg)
dlg.bind(on_complete=on_complete)
dlg.open()
def build(self): def build(self):
global Builder global Builder
if not Builder: if not Builder:

1
gui/kivy/qr_scanner/__init__.py

@ -56,4 +56,5 @@ class ScannerBase(AnchorLayout):
QRScanner = core_select_lib('qr_scanner', ( QRScanner = core_select_lib('qr_scanner', (
('android', 'scanner_android', 'ScannerAndroid'), ('android', 'scanner_android', 'ScannerAndroid'),
('camera', 'scanner_camera', 'ScannerCamera')), False, 'electrum_gui.kivy') ('camera', 'scanner_camera', 'ScannerCamera')), False, 'electrum_gui.kivy')
Factory.register('QRScanner', cls=QRScanner) Factory.register('QRScanner', cls=QRScanner)

19
gui/kivy/qr_scanner/scanner_camera.py

@ -1,22 +1,28 @@
from kivy.uix.camera import Camera from kivy.uix.camera import Camera
from kivy.clock import Clock from kivy.clock import Clock
from kivy.utils import platform
import iconv
from electrum_gui.kivy.qr_scanner import ScannerBase from electrum_gui.kivy.qr_scanner import ScannerBase
import iconv
try: try:
from zbar import ImageScanner, Config, Image, Symbol from zbar import ImageScanner, Config, Image, Symbol
except ImportError: except ImportError:
raise SystemError('unable to import zbar please make sure you have it installed') raise SystemError('unable to import zbar please make sure you have'
' it installed.\nFor mac osx: `brew install zbar then\n`'
'`pip install https://github.com/npinchot/zbar/archive/d3c1611ad2411fbdc3e79eb96ca704a63d30ae69.zip`')
try: try:
import Image as PILImage from PIL import Image as PILImage
except ImportError: except ImportError:
raise SystemError('unable to import Pil/pillow please install one of the two.') raise SystemError('unable to import Pil/pillow'
' please install one of the two.')
__all__ = ('ScannerCamera', ) __all__ = ('ScannerCamera', )
class ScannerCamera(ScannerBase): class ScannerCamera(ScannerBase):
'''Widget that use the kivy.uix.camera.Camera and zbar to detect qrcode. '''Widget that use the kivy.uix.camera.Camera and zbar to detect
When found, the `symbols` will be updated qrcode. When found, the `symbols` will be updated
''' '''
def __init__(self, **kwargs): def __init__(self, **kwargs):
@ -48,6 +54,7 @@ class ScannerCamera(ScannerBase):
self._camera.play = False self._camera.play = False
Clock.unschedule(self._detect_qrcode_frame) Clock.unschedule(self._detect_qrcode_frame)
# TODO: testing for various platforms(windows, mac) # TODO: testing for various platforms(windows, mac)
if platform == 'linux':
self._camera._camera._pipeline.set_state(1) self._camera._camera._pipeline.set_state(1)
#self._camera = None #self._camera = None

7
gui/kivy/uix/dialogs/new_contact.py

@ -9,12 +9,7 @@ class NewContactDialog(Factory.AnimatedPopup):
def load_qr_scanner(self): def load_qr_scanner(self):
self.dismiss() self.dismiss()
dlg = Cache.get('electrum_widgets', 'QrScannerDialog') App.get_running_app().scan_qr(on_complete=self.on_complete)
if not dlg:
dlg = Factory.QrScannerDialog()
Cache.append('electrum_widgets', 'QrScannerDialog', dlg)
dlg.bind(on_complete=self.on_complete)
dlg.open()
def on_complete(self, instance, uri): def on_complete(self, instance, uri):
self.new_contact(uri=uri) self.new_contact(uri=uri)

11
gui/kivy/uix/dialogs/qr_scanner.py

@ -4,9 +4,9 @@ from kivy.lang import Builder
Factory.register('QRScanner', module='electrum_gui.kivy.qr_scanner') Factory.register('QRScanner', module='electrum_gui.kivy.qr_scanner')
class QrScannerDialog(Factory.AnimaterPopup): class QrScannerDialog(Factory.AnimatedPopup):
__events__('on_complete', ) __events__ = ('on_complete', )
def on_symbols(self, instance, value): def on_symbols(self, instance, value):
instance.stop() instance.stop()
@ -18,6 +18,11 @@ class QrScannerDialog(Factory.AnimaterPopup):
#message = uir.get('message', '') #message = uir.get('message', '')
self.dispatch('on_omplete', uri) self.dispatch('on_omplete', uri)
def on_complete(self):
''' Default Handler for on_complete event.
'''
pass
Builder.load_string(''' Builder.load_string('''
<QrScannerDialog> <QrScannerDialog>
@ -27,7 +32,7 @@ Builder.load_string('''
title_size: '24sp' title_size: '24sp'
border: 7, 7, 7, 7 border: 7, 7, 7, 7
size_hint: None, None size_hint: None, None
size: '320dp', '270dp' size: '340dp', '290dp'
pos_hint: {'center_y': .53} pos_hint: {'center_y': .53}
separator_color: .89, .89, .89, 1 separator_color: .89, .89, .89, 1
separator_height: '1.2dp' separator_height: '1.2dp'

11
gui/kivy/uix/screens.py

@ -101,12 +101,13 @@ class MainScreen(Factory.Screen):
class ScreenSend(CScreen): class ScreenSend(CScreen):
def scan_qr(self):
pop = Factory.QrScannerDialog(on_complete=self.set_qr_data)
pop.open()
def set_qr_data(self, uri): def set_qr_data(self, uri):
self.ids.payto_e self.ids.payto_e.text = uri.get('address')
self.ids.message_e.text = uri.get('message')
self.ids.amount_e.text = uri.get('amount')
#label = uri.get('label')
#if label:
# TODO: update label, add to contacts
class ScreenReceive(CScreen): class ScreenReceive(CScreen):

2
gui/kivy/uix/ui_screens/mainscreen.kv

@ -336,7 +336,7 @@
pos_hint: {'center_y': .5} pos_hint: {'center_y': .5}
size_hint: None, None size_hint: None, None
size: '22dp', '22dp' size: '22dp', '22dp'
on_release: root.scan_qr() on_release: app.scan_qr(on_complete=root.set_qr_data)
CardSeparator CardSeparator
opacity: message_selection.opacity opacity: message_selection.opacity
color: blue_bottom.foreground_color color: blue_bottom.foreground_color

Loading…
Cancel
Save