From 8ae4bbb6cf989c6463a2119cd31992a00951732b Mon Sep 17 00:00:00 2001 From: miruka Date: Fri, 6 Dec 2019 08:59:35 -0400 Subject: [PATCH] Fix uplaod item delete, pause and cancel bugs --- src/python/matrix_client.py | 5 +++-- src/python/models/items.py | 2 ++ src/qml/Chat/UploadsBar.qml | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/python/matrix_client.py b/src/python/matrix_client.py index ee5f0fac..df22a1e3 100644 --- a/src/python/matrix_client.py +++ b/src/python/matrix_client.py @@ -234,8 +234,9 @@ class MatrixClient(nio.AsyncClient): # This error will be caught again by the try block later below size = 0 + task = asyncio.Task.current_task() monitor = nio.TransferMonitor(size) - upload_item = Upload(item_uuid, monitor, path, total_size=size) + upload_item = Upload(item_uuid, task, monitor, path, total_size=size) self.models[Upload, room_id][str(item_uuid)] = upload_item def on_transfered(transfered: int) -> None: @@ -370,7 +371,7 @@ class MatrixClient(nio.AsyncClient): content["msgtype"] = "m.file" content["filename"] = path.name - del self.models[Upload, room_id][upload_item.uuid] + del self.models[Upload, room_id][str(upload_item.uuid)] uuid = str(uuid4()) diff --git a/src/python/models/items.py b/src/python/models/items.py index 10452fc2..9eafe58b 100644 --- a/src/python/models/items.py +++ b/src/python/models/items.py @@ -1,3 +1,4 @@ +import asyncio import re from dataclasses import dataclass, field from datetime import datetime, timedelta @@ -114,6 +115,7 @@ class UploadStatus(AutoStrEnum): @dataclass class Upload(ModelItem): uuid: UUID = field() + task: asyncio.Task = field() monitor: nio.TransferMonitor = field() filepath: Path = field() diff --git a/src/qml/Chat/UploadsBar.qml b/src/qml/Chat/UploadsBar.qml index 350a3c9f..ce9cc43a 100644 --- a/src/qml/Chat/UploadsBar.qml +++ b/src/qml/Chat/UploadsBar.qml @@ -61,7 +61,7 @@ Rectangle { // immediate visual feedback hideBind.when = true // Python will delete this model item on cancel - py.setattr(model.monitor, "cancel", true) + py.call(py.getattr(model.task, "cancel")) } Layout.preferredWidth: theme.baseElementsHeight @@ -188,7 +188,7 @@ Rectangle { onClicked: { delegate.guiPaused = ! delegate.guiPaused py.setattr( - model.monitor, "pause", model.status !== "Paused", + model.monitor, "pause", delegate.guiPaused, ) }