URI: 
       tAbstract and enable qrscanner dialog for send screen. - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit f442cc31e4e6bc5abbdadf06738e5ee33da7511b
   DIR parent 33c89b47d8d4222df812603959463affa7ca4a3e
  HTML Author: akshayaurora <akshayaurora@gmail.com>
       Date:   Tue, 24 Jun 2014 22:09:11 +0530
       
       Abstract and enable qrscanner dialog for send screen.
       
       Diffstat:
         M gui/kivy/main_window.py             |       8 ++++++++
         M gui/kivy/qr_scanner/__init__.py     |       1 +
         M gui/kivy/qr_scanner/scanner_camera… |      21 ++++++++++++++-------
         M gui/kivy/uix/dialogs/new_contact.py |       7 +------
         M gui/kivy/uix/dialogs/qr_scanner.py  |      11 ++++++++---
         M gui/kivy/uix/screens.py             |      11 ++++++-----
         M gui/kivy/uix/ui_screens/mainscreen… |       2 +-
       
       7 files changed, 39 insertions(+), 22 deletions(-)
       ---
   DIR diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py
       t@@ -200,6 +200,14 @@ class ElectrumWindow(App):
            def set_url(self, instance, 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):
                global Builder
                if not Builder:
   DIR diff --git a/gui/kivy/qr_scanner/__init__.py b/gui/kivy/qr_scanner/__init__.py
       t@@ -56,4 +56,5 @@ class ScannerBase(AnchorLayout):
        QRScanner = core_select_lib('qr_scanner', (
            ('android', 'scanner_android', 'ScannerAndroid'),
            ('camera', 'scanner_camera', 'ScannerCamera')), False, 'electrum_gui.kivy')
       +
        Factory.register('QRScanner', cls=QRScanner)
   DIR diff --git a/gui/kivy/qr_scanner/scanner_camera.py b/gui/kivy/qr_scanner/scanner_camera.py
       t@@ -1,22 +1,28 @@
        from kivy.uix.camera import Camera
        from kivy.clock import Clock
       +from kivy.utils import platform
        
       -import iconv
        from electrum_gui.kivy.qr_scanner import ScannerBase
       +
       +import iconv 
       +
        try:
            from zbar import ImageScanner, Config, Image, Symbol
        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:
       -    import Image as PILImage
       +    from PIL import Image as PILImage
        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', )
        
        class ScannerCamera(ScannerBase):
       -    '''Widget that use the kivy.uix.camera.Camera and zbar to detect qrcode.
       -    When found, the `symbols` will be updated
       +    '''Widget that use the kivy.uix.camera.Camera and zbar to detect
       +    qrcode. When found, the `symbols` will be updated
            '''
        
            def __init__(self, **kwargs):
       t@@ -48,7 +54,8 @@ class ScannerCamera(ScannerBase):
                self._camera.play = False
                Clock.unschedule(self._detect_qrcode_frame)
                # TODO: testing for various platforms(windows, mac)
       -        self._camera._camera._pipeline.set_state(1)
       +        if platform == 'linux':
       +            self._camera._camera._pipeline.set_state(1)
                #self._camera = None
        
            def _detect_qrcode_frame(self, *args):
   DIR diff --git a/gui/kivy/uix/dialogs/new_contact.py b/gui/kivy/uix/dialogs/new_contact.py
       t@@ -9,12 +9,7 @@ class NewContactDialog(Factory.AnimatedPopup):
        
            def load_qr_scanner(self):
                self.dismiss()
       -        dlg = Cache.get('electrum_widgets', 'QrScannerDialog')
       -        if not dlg:
       -            dlg = Factory.QrScannerDialog()
       -            Cache.append('electrum_widgets', 'QrScannerDialog', dlg)
       -            dlg.bind(on_complete=self.on_complete)
       -        dlg.open()
       +        App.get_running_app().scan_qr(on_complete=self.on_complete)
        
            def on_complete(self, instance, uri):
                self.new_contact(uri=uri)
   DIR diff --git a/gui/kivy/uix/dialogs/qr_scanner.py b/gui/kivy/uix/dialogs/qr_scanner.py
       t@@ -4,9 +4,9 @@ from kivy.lang import Builder
        
        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):
                instance.stop()
       t@@ -18,6 +18,11 @@ class QrScannerDialog(Factory.AnimaterPopup):
                #message = uir.get('message', '')
                self.dispatch('on_omplete', uri)
        
       +    def on_complete(self):
       +        ''' Default Handler for on_complete event.
       +        '''
       +        pass
       +
        
        Builder.load_string('''
        <QrScannerDialog>
       t@@ -27,7 +32,7 @@ Builder.load_string('''
            title_size: '24sp'
            border: 7, 7, 7, 7
            size_hint: None, None
       -    size: '320dp', '270dp'
       +    size: '340dp', '290dp'
            pos_hint: {'center_y': .53}
            separator_color: .89, .89, .89, 1
            separator_height: '1.2dp'
   DIR diff --git a/gui/kivy/uix/screens.py b/gui/kivy/uix/screens.py
       t@@ -101,12 +101,13 @@ class MainScreen(Factory.Screen):
        
        class ScreenSend(CScreen):
        
       -    def scan_qr(self):
       -        pop = Factory.QrScannerDialog(on_complete=self.set_qr_data)
       -        pop.open()
       -
            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):
   DIR diff --git a/gui/kivy/uix/ui_screens/mainscreen.kv b/gui/kivy/uix/ui_screens/mainscreen.kv
       t@@ -336,7 +336,7 @@
                                pos_hint: {'center_y': .5}
                                size_hint: None, None
                                size: '22dp', '22dp'
       -                        on_release: root.scan_qr()
       +                        on_release: app.scan_qr(on_complete=root.set_qr_data)
                        CardSeparator
                            opacity: message_selection.opacity
                            color: blue_bottom.foreground_color