mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Prevent key presses from acting during a long job
This commit is contained in:
parent
9854cef7b6
commit
ef20239be6
@ -10,7 +10,7 @@ import time
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from PyQt4.Qt import (QWidget, QVBoxLayout, QLabel, Qt, QPainter, QBrush, QColor)
|
from PyQt4.Qt import (QWidget, QVBoxLayout, QLabel, Qt, QPainter, QBrush, QColor, QAction)
|
||||||
|
|
||||||
from calibre.gui2 import Dispatcher
|
from calibre.gui2 import Dispatcher
|
||||||
from calibre.gui2.progress_indicator import ProgressIndicator
|
from calibre.gui2.progress_indicator import ProgressIndicator
|
||||||
@ -59,12 +59,17 @@ class BlockingJob(QWidget):
|
|||||||
def start(self):
|
def start(self):
|
||||||
self.setGeometry(0, 0, self.parent().width(), self.parent().height())
|
self.setGeometry(0, 0, self.parent().width(), self.parent().height())
|
||||||
self.setVisible(True)
|
self.setVisible(True)
|
||||||
|
# Prevent any actions from being triggerred by key presses
|
||||||
|
for child in self.parent().findChildren(QAction):
|
||||||
|
child.blockSignals(True)
|
||||||
self.raise_()
|
self.raise_()
|
||||||
self.pi.startAnimation()
|
self.pi.startAnimation()
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.pi.stopAnimation()
|
self.pi.stopAnimation()
|
||||||
self.setVisible(False)
|
self.setVisible(False)
|
||||||
|
for child in self.parent().findChildren(QAction):
|
||||||
|
child.blockSignals(False)
|
||||||
|
|
||||||
def job_done(self, callback, job):
|
def job_done(self, callback, job):
|
||||||
del job.callback
|
del job.callback
|
||||||
@ -77,8 +82,17 @@ class BlockingJob(QWidget):
|
|||||||
p.end()
|
p.end()
|
||||||
QWidget.paintEvent(self, ev)
|
QWidget.paintEvent(self, ev)
|
||||||
|
|
||||||
|
def eventFilter(self, obj, ev):
|
||||||
|
if ev.type() in (ev.KeyPress, ev.KeyRelease):
|
||||||
|
return True
|
||||||
|
return QWidget.eventFilter(self, obj, ev)
|
||||||
|
|
||||||
|
def set_msg(self, text):
|
||||||
|
self.msg.setText('<h2>%s</h2>' % text)
|
||||||
|
|
||||||
def __call__(self, name, user_text, callback, function, *args, **kwargs):
|
def __call__(self, name, user_text, callback, function, *args, **kwargs):
|
||||||
self.msg.setText('<h2>%s</h2>' % user_text)
|
' Run a job that blocks the GUI providing some feedback to the user '
|
||||||
|
self.set_msg(user_text)
|
||||||
job = LongJob(name, user_text, Dispatcher(partial(self.job_done, callback)), function, *args, **kwargs)
|
job = LongJob(name, user_text, Dispatcher(partial(self.job_done, callback)), function, *args, **kwargs)
|
||||||
job.start()
|
job.start()
|
||||||
self.start()
|
self.start()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user