Clean up WaitingDialog
Prevent GC so callers don't have to.
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
from functools import partial
|
||||
import traceback
|
||||
import zlib
|
||||
import json
|
||||
from io import BytesIO
|
||||
@@ -75,24 +74,20 @@ class Plugin(BasePlugin):
|
||||
|
||||
def handler():
|
||||
blob = json.dumps(dialog.tx.as_dict())
|
||||
self.sender = self._send(parent=dialog, blob=blob)
|
||||
self.sender.start()
|
||||
self._send(parent=dialog, blob=blob)
|
||||
b.clicked.connect(handler)
|
||||
dialog.sharing_buttons.insert(-1, b)
|
||||
|
||||
@hook
|
||||
def scan_text_edit(self, parent):
|
||||
def handler():
|
||||
self.receiver = self._recv(parent=parent)
|
||||
self.receiver.start()
|
||||
parent.addButton(':icons/microphone.png', handler, _("Read from microphone"))
|
||||
parent.addButton(':icons/microphone.png', partial(self._recv, parent),
|
||||
_("Read from microphone"))
|
||||
|
||||
@hook
|
||||
def show_text_edit(self, parent):
|
||||
def handler():
|
||||
blob = str(parent.toPlainText())
|
||||
self.sender = self._send(parent=parent, blob=blob)
|
||||
self.sender.start()
|
||||
self._send(parent=parent, blob=blob)
|
||||
parent.addButton(':icons/speaker.png', handler, _("Send to speaker"))
|
||||
|
||||
def _audio_interface(self):
|
||||
@@ -101,31 +96,25 @@ class Plugin(BasePlugin):
|
||||
|
||||
def _send(self, parent, blob):
|
||||
def sender_thread():
|
||||
try:
|
||||
with self._audio_interface() as interface:
|
||||
src = BytesIO(blob)
|
||||
dst = interface.player()
|
||||
amodem.main.send(config=self.modem_config, src=src, dst=dst)
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
with self._audio_interface() as interface:
|
||||
src = BytesIO(blob)
|
||||
dst = interface.player()
|
||||
amodem.main.send(config=self.modem_config, src=src, dst=dst)
|
||||
|
||||
print_msg('Sending:', repr(blob))
|
||||
blob = zlib.compress(blob)
|
||||
|
||||
kbps = self.modem_config.modem_bps / 1e3
|
||||
msg = 'Sending to Audio MODEM ({0:.1f} kbps)...'.format(kbps)
|
||||
return WaitingDialog(parent=parent, message=msg, run_task=sender_thread)
|
||||
WaitingDialog(parent, msg, sender_thread)
|
||||
|
||||
def _recv(self, parent):
|
||||
def receiver_thread():
|
||||
try:
|
||||
with self._audio_interface() as interface:
|
||||
src = interface.recorder()
|
||||
dst = BytesIO()
|
||||
amodem.main.recv(config=self.modem_config, src=src, dst=dst)
|
||||
return dst.getvalue()
|
||||
except Exception:
|
||||
traceback.print_exc()
|
||||
with self._audio_interface() as interface:
|
||||
src = interface.recorder()
|
||||
dst = BytesIO()
|
||||
amodem.main.recv(config=self.modem_config, src=src, dst=dst)
|
||||
return dst.getvalue()
|
||||
|
||||
def on_success(blob):
|
||||
if blob:
|
||||
@@ -135,5 +124,4 @@ class Plugin(BasePlugin):
|
||||
|
||||
kbps = self.modem_config.modem_bps / 1e3
|
||||
msg = 'Receiving from Audio MODEM ({0:.1f} kbps)...'.format(kbps)
|
||||
return WaitingDialog(parent=parent, message=msg,
|
||||
run_task=receiver_thread, on_success=on_success)
|
||||
WaitingDialog(parent, msg, receiver_thread, on_success=on_success)
|
||||
|
||||
@@ -92,9 +92,8 @@ class Plugin(TrustedCoinPlugin):
|
||||
if wallet.billing_info is None:
|
||||
# request billing info before forming the transaction
|
||||
task = partial(self.request_billing_info, wallet)
|
||||
waiting_dialog = WaitingDialog(window, 'please wait...', task)
|
||||
waiting_dialog.start()
|
||||
waiting_dialog.wait()
|
||||
dialog = WaitingDialog(window, 'please wait...', task)
|
||||
dialog.wait()
|
||||
if wallet.billing_info is None:
|
||||
window.show_message('Could not contact server')
|
||||
return True
|
||||
@@ -103,8 +102,8 @@ class Plugin(TrustedCoinPlugin):
|
||||
|
||||
def settings_dialog(self, window):
|
||||
task = partial(self.request_billing_info, window.wallet)
|
||||
self.waiting_dialog = WaitingDialog(window, 'please wait...', task, partial(self.show_settings_dialog, window))
|
||||
self.waiting_dialog.start()
|
||||
WaitingDialog(window, 'please wait...', task,
|
||||
on_success=partial(self.show_settings_dialog, window))
|
||||
|
||||
def show_settings_dialog(self, window, success):
|
||||
if not success:
|
||||
|
||||
Reference in New Issue
Block a user