tqr_dialog.py - electrum - Electrum Bitcoin wallet
HTML git clone https://git.parazyd.org/electrum
DIR Log
DIR Files
DIR Refs
DIR Submodules
---
tqr_dialog.py (2706B)
---
1 from typing import TYPE_CHECKING
2
3 from kivy.factory import Factory
4 from kivy.lang import Builder
5 from kivy.core.clipboard import Clipboard
6 from kivy.app import App
7 from kivy.clock import Clock
8
9 from electrum.gui.kivy.i18n import _
10
11 if TYPE_CHECKING:
12 from ...main_window import ElectrumWindow
13
14
15 Builder.load_string('''
16 #:import KIVY_GUI_PATH electrum.gui.kivy.KIVY_GUI_PATH
17
18 <QRDialog@Popup>
19 id: popup
20 title: ''
21 data: ''
22 shaded: False
23 help_text: ''
24 AnchorLayout:
25 anchor_x: 'center'
26 BoxLayout:
27 orientation: 'vertical'
28 size_hint: 1, 1
29 padding: '10dp'
30 spacing: '10dp'
31 QRCodeWidget:
32 id: qr
33 shaded: False
34 foreground_color: (0, 0, 0, 0.5) if self.shaded else (0, 0, 0, 0)
35 on_touch_down:
36 touch = args[1]
37 if self.collide_point(*touch.pos): self.shaded = not self.shaded
38 TopLabel:
39 text: root.help_text
40 Widget:
41 size_hint: 1, 0.2
42 BoxLayout:
43 size_hint: 1, None
44 height: '48dp'
45 Button:
46 size_hint: 1, None
47 height: '48dp'
48 text: _('Copy')
49 on_release:
50 root.copy_to_clipboard()
51 IconButton:
52 icon: f'atlas://{KIVY_GUI_PATH}/theming/light/share'
53 size_hint: 0.6, None
54 height: '48dp'
55 on_release: root.do_share()
56 Button:
57 size_hint: 1, None
58 height: '48dp'
59 text: _('Close')
60 on_release:
61 popup.dismiss()
62 ''')
63
64 class QRDialog(Factory.Popup):
65 def __init__(self, title, data, show_text, *,
66 failure_cb=None, text_for_clipboard=None, help_text=None):
67 Factory.Popup.__init__(self)
68 self.app = App.get_running_app() # type: ElectrumWindow
69 self.title = title
70 self.data = data
71 self.help_text = (data if show_text else help_text) or ''
72 self.failure_cb = failure_cb
73 self.text_for_clipboard = text_for_clipboard if text_for_clipboard else data
74
75 def on_open(self):
76 self.ids.qr.set_data(self.data, self.failure_cb)
77
78 def copy_to_clipboard(self):
79 Clipboard.copy(self.text_for_clipboard)
80 msg = _('Text copied to clipboard.')
81 Clock.schedule_once(lambda dt: self.app.show_info(msg))
82
83 def do_share(self):
84 self.app.do_share(self.text_for_clipboard, self.title)
85 self.dismiss()