Refactor spinner logic to on/off methods

This commit is contained in:
Luke Murphy 2020-10-11 13:28:18 +02:00
parent 1c520b11bc
commit 0578b3d117
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC

View File

@ -122,32 +122,32 @@ class DropShip:
self.nursery.start_soon(self.wormhole_send, fpath) self.nursery.start_soon(self.wormhole_send, fpath)
self.file_chooser.hide() self.file_chooser.hide()
async def wormhole_send(self, fpath): def _send_spinner_on(self):
"""Run `wormhole send` on a local file path.""" """Turn spinner on for sending interaction."""
command = ["wormhole", "send", fpath]
process = await open_process(command, stderr=PIPE)
self.drop_label.set_visible(False) self.drop_label.set_visible(False)
self.drop_label.set_vexpand(False) self.drop_label.set_vexpand(False)
self.drop_spinner.set_vexpand(True) self.drop_spinner.set_vexpand(True)
self.drop_spinner.set_visible(True) self.drop_spinner.set_visible(True)
self.drop_spinner.start() self.drop_spinner.start()
output = await process.stderr.receive_some() def _send_spinner_off(self, code):
code = output.decode().split()[-1] """Turn spinner off for sending interaction."""
self.clipboard.set_text(code, -1)
self.transfer_code = code
self.drop_label.set_text(code) self.drop_label.set_text(code)
self.drop_label.set_visible(True) self.drop_label.set_visible(True)
self.drop_label.set_selectable(True) self.drop_label.set_selectable(True)
self.drop_spinner.stop() self.drop_spinner.stop()
self.drop_spinner.set_vexpand(False) self.drop_spinner.set_vexpand(False)
self.drop_spinner.set_visible(False) self.drop_spinner.set_visible(False)
async def wormhole_send(self, fpath):
"""Run `wormhole send` on a local file path."""
command = ["wormhole", "send", fpath]
process = await open_process(command, stderr=PIPE)
self._send_spinner_on()
output = await process.stderr.receive_some()
self.transfer_code = output.decode().split()[-1]
self.clipboard.set_text(self.transfer_code, -1)
self._send_spinner_off(self.transfer_code)
await process.wait() await process.wait()
async def wormhole_recv(self, code): async def wormhole_recv(self, code):