1from kivy.app import App
2from kivy.factory import Factory
3from kivy.lang import Builder
4
5Factory.register('QRScanner', module='electrum.gui.kivy.qr_scanner')
6
7class QrScannerDialog(Factory.AnimatedPopup):
8
9    __events__ = ('on_complete',)
10
11    def on_symbols(self, instance, value):
12        instance.stop()
13        self.dismiss()
14        data = value[0].data
15        self.dispatch('on_complete', data)
16
17    def on_complete(self, x):
18        ''' Default Handler for on_complete event.
19        '''
20        print(x)
21
22
23Builder.load_string('''
24#:import KIVY_GUI_PATH electrum.gui.kivy.KIVY_GUI_PATH
25
26<QrScannerDialog>
27    title:
28        _(\
29        '[size=18dp]Hold your QRCode up to the camera[/size][size=7dp]\\n[/size]')
30    title_size: '24sp'
31    border: 7, 7, 7, 7
32    size_hint: None, None
33    size: '340dp', '290dp'
34    pos_hint: {'center_y': .53}
35    #separator_color: .89, .89, .89, 1
36    #separator_height: '1.2dp'
37    #title_color: .437, .437, .437, 1
38    #background: f'atlas://{KIVY_GUI_PATH}/theming/atlas/light/dialog'
39    on_activate:
40        qrscr.start()
41        qrscr.size = self.size
42    on_deactivate: qrscr.stop()
43    QRScanner:
44        id: qrscr
45        on_symbols: root.on_symbols(*args)
46''')
47