mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Cleanup DBCheck dialog
This commit is contained in:
parent
7938c4667f
commit
df2db001ba
@ -657,12 +657,15 @@ class ChooseLibraryAction(InterfaceAction):
|
|||||||
library_path = db.library_path
|
library_path = db.library_path
|
||||||
|
|
||||||
d = DBCheck(self.gui, db)
|
d = DBCheck(self.gui, db)
|
||||||
d.start()
|
|
||||||
try:
|
try:
|
||||||
m.close()
|
d.start()
|
||||||
except:
|
d.exec()
|
||||||
pass
|
try:
|
||||||
d.break_cycles()
|
m.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
finally:
|
||||||
|
d.break_cycles()
|
||||||
self.gui.library_moved(library_path)
|
self.gui.library_moved(library_path)
|
||||||
if d.rejected:
|
if d.rejected:
|
||||||
return
|
return
|
||||||
|
@ -11,7 +11,7 @@ from threading import Thread
|
|||||||
from qt.core import (
|
from qt.core import (
|
||||||
QDialog, QVBoxLayout, QHBoxLayout, QTreeWidget, QLabel, QPushButton,
|
QDialog, QVBoxLayout, QHBoxLayout, QTreeWidget, QLabel, QPushButton,
|
||||||
QApplication, QTreeWidgetItem, QLineEdit, Qt, QSize,
|
QApplication, QTreeWidgetItem, QLineEdit, Qt, QSize,
|
||||||
QTimer, QIcon, QTextEdit, QSplitter, QWidget, QGridLayout, pyqtSignal)
|
QIcon, QTextEdit, QSplitter, QWidget, QGridLayout, pyqtSignal)
|
||||||
|
|
||||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
from calibre.library.check_library import CheckLibrary, CHECKS
|
from calibre.library.check_library import CheckLibrary, CHECKS
|
||||||
@ -22,6 +22,7 @@ from calibre import prints, as_unicode
|
|||||||
class DBCheck(QDialog): # {{{
|
class DBCheck(QDialog): # {{{
|
||||||
|
|
||||||
update_msg = pyqtSignal(object)
|
update_msg = pyqtSignal(object)
|
||||||
|
finished_vacuum = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent, db):
|
def __init__(self, parent, db):
|
||||||
QDialog.__init__(self, parent)
|
QDialog.__init__(self, parent)
|
||||||
@ -34,6 +35,7 @@ class DBCheck(QDialog): # {{{
|
|||||||
self.l.addWidget(self.l1)
|
self.l.addWidget(self.l1)
|
||||||
self.msg = QLabel('')
|
self.msg = QLabel('')
|
||||||
self.update_msg.connect(self.msg.setText, type=Qt.ConnectionType.QueuedConnection)
|
self.update_msg.connect(self.msg.setText, type=Qt.ConnectionType.QueuedConnection)
|
||||||
|
self.finished_vacuum.connect(self.accept, type=Qt.ConnectionType.QueuedConnection)
|
||||||
self.l.addWidget(self.msg)
|
self.l.addWidget(self.msg)
|
||||||
self.msg.setWordWrap(True)
|
self.msg.setWordWrap(True)
|
||||||
self.resize(self.sizeHint() + QSize(100, 50))
|
self.resize(self.sizeHint() + QSize(100, 50))
|
||||||
@ -42,11 +44,8 @@ class DBCheck(QDialog): # {{{
|
|||||||
self.rejected = False
|
self.rejected = False
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
t = self.thread = Thread(target=self.vacuum)
|
t = self.thread = Thread(target=self.vacuum, daemon=True)
|
||||||
t.daemon = True
|
|
||||||
t.start()
|
t.start()
|
||||||
QTimer.singleShot(100, self.check)
|
|
||||||
self.exec()
|
|
||||||
|
|
||||||
def vacuum(self):
|
def vacuum(self):
|
||||||
try:
|
try:
|
||||||
@ -54,19 +53,12 @@ class DBCheck(QDialog): # {{{
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
import traceback
|
import traceback
|
||||||
self.error = (as_unicode(e), traceback.format_exc())
|
self.error = (as_unicode(e), traceback.format_exc())
|
||||||
|
self.finished_vacuum.emit()
|
||||||
|
|
||||||
def reject(self):
|
def reject(self):
|
||||||
self.rejected = True
|
self.rejected = True
|
||||||
return QDialog.reject(self)
|
return QDialog.reject(self)
|
||||||
|
|
||||||
def check(self):
|
|
||||||
if self.rejected:
|
|
||||||
return
|
|
||||||
if self.thread.is_alive():
|
|
||||||
QTimer.singleShot(100, self.check)
|
|
||||||
else:
|
|
||||||
self.accept()
|
|
||||||
|
|
||||||
def break_cycles(self):
|
def break_cycles(self):
|
||||||
self.db = self.thread = None
|
self.db = self.thread = None
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user