From 91e6e0a1276186ad4d73078f3ac7b0f526b5bf09 Mon Sep 17 00:00:00 2001 From: Luke Murphy Date: Sun, 11 Oct 2020 14:06:58 +0200 Subject: [PATCH] Add a pending transfer to the transfer list This doesn't work yet... --- dropship/dropship.py | 17 ++++++----------- dropship/ui_templates.py | 2 +- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/dropship/dropship.py b/dropship/dropship.py index a691591..d5aef64 100644 --- a/dropship/dropship.py +++ b/dropship/dropship.py @@ -96,18 +96,7 @@ class DropShip: self.files_to_send = files if len(files) == 1: fpath = files[0].replace("file://", "") - fname = basename(fpath) - # TODO Luke can u make a callback that spawns pendingTransmissions after we got a code? self.nursery.start_soon(self.wormhole_send, fpath) - - # TODO Roel/Luke, move this somewhere logical in its own function? - status = PendingTransferRow(self, fname, self.transfer_code) - - # TODO Roel, find out how to add to a listbox - self.pending_transfers_list.insert( - status, -1 - ) # -1 is add at bottom - else: log.info("Multiple file sending coming soon ™") @@ -140,12 +129,18 @@ class DropShip: self.drop_spinner.set_vexpand(False) self.drop_spinner.set_visible(False) + def _create_pending_transfer(self, fpath): + """Create a new pending transfer.""" + pending = PendingTransferRow(basename(fpath), self.transfer_code) + self.pending_transfers_list.insert(pending, -1) + async def wormhole_send(self, fpath): """Run `wormhole send` on a local file path.""" self._send_spinner_on() process = await open_process(["wormhole", "send", fpath], stderr=PIPE) output = await process.stderr.receive_some() self.transfer_code = output.decode().split()[-1] + self._create_pending_transfer(fpath) self.clipboard.set_text(self.transfer_code, -1) self._send_spinner_off() await process.wait() diff --git a/dropship/ui_templates.py b/dropship/ui_templates.py index df5c803..2d309d9 100644 --- a/dropship/ui_templates.py +++ b/dropship/ui_templates.py @@ -18,7 +18,7 @@ class PendingTransferRow(Gtk.ListBoxRow): transferCodeButton = Gtk.Template.Child() cancelTransfer = Gtk.Template.Child() - def __init__(self, parent, fileName, transferCode): + def __init__(self, fileName, transferCode): super(PendingTransferRow, self).__init__() self.fileNameLabel.set_text(fileName) self.transferCodeButton.set_label(transferCode)