Skip to content
Snippets Groups Projects
Commit 2943011c authored by Jiří Kalvoda's avatar Jiří Kalvoda
Browse files

Qt util: Job cancel

parent 3a7e7f18
No related branches found
No related tags found
No related merge requests found
...@@ -3,6 +3,7 @@ from PyQt5.QtGui import * ...@@ -3,6 +3,7 @@ from PyQt5.QtGui import *
from PyQt5.QtWidgets import * from PyQt5.QtWidgets import *
from dataclasses import dataclass from dataclasses import dataclass
from enum import Enum
import re import re
import types import types
import traceback import traceback
...@@ -361,6 +362,13 @@ class QLabelOpeningBracket(QLabel): ...@@ -361,6 +362,13 @@ class QLabelOpeningBracket(QLabel):
_qt_jobs = set() _qt_jobs = set()
class QtJobState(Enum):
WAITING = 1
RUNNING = 2
DONE = 3
CANCELED = 4
class QtJob: class QtJob:
def __init__(self, f): def __init__(self, f):
_qt_jobs.add(self) _qt_jobs.add(self)
...@@ -369,11 +377,13 @@ class QtJob: ...@@ -369,11 +377,13 @@ class QtJob:
self.timer.setSingleShot(True) self.timer.setSingleShot(True)
self.timer.timeout.connect(self._run) self.timer.timeout.connect(self._run)
self.timer.start(0) self.timer.start(0)
self.state = QtJobState.WAITING
def _clean(self): def _clean(self):
_qt_jobs.remove(self) _qt_jobs.remove(self)
def _run(self): def _run(self):
if self.state == QtJobState.WAITING:
try: try:
r = self.f.send(None) r = self.f.send(None)
print(r) print(r)
...@@ -385,6 +395,13 @@ class QtJob: ...@@ -385,6 +395,13 @@ class QtJob:
else: else:
self.timer.start(r) self.timer.start(r)
def cancel(self):
if self.state == QtJobState.RUNNING:
raise NotImplementedError()
if self.state == QtJobState.WAITING:
self.state = QtJobState.CANCELED
self.f.close()
@types.coroutine @types.coroutine
def qt_job_wait_ms(time_ms): def qt_job_wait_ms(time_ms):
yield time_ms yield time_ms
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment