mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Search dialog: properly stop thread pools. Restore window sizes.
This commit is contained in:
parent
d931ac2fe2
commit
e10b066b03
@ -13,11 +13,12 @@ from Queue import Queue
|
|||||||
|
|
||||||
from PyQt4.Qt import Qt, QAbstractItemModel, QDialog, QTimer, QVariant, \
|
from PyQt4.Qt import Qt, QAbstractItemModel, QDialog, QTimer, QVariant, \
|
||||||
QModelIndex, QPixmap, QSize, QCheckBox, QVBoxLayout, QHBoxLayout, \
|
QModelIndex, QPixmap, QSize, QCheckBox, QVBoxLayout, QHBoxLayout, \
|
||||||
QPushButton
|
QPushButton, QString, QByteArray
|
||||||
|
|
||||||
from calibre import browser
|
from calibre import browser
|
||||||
from calibre.gui2 import NONE
|
from calibre.gui2 import NONE
|
||||||
from calibre.gui2.store.search_ui import Ui_Dialog
|
from calibre.gui2.store.search_ui import Ui_Dialog
|
||||||
|
from calibre.utils.config import DynamicConfig
|
||||||
from calibre.utils.icu import sort_key
|
from calibre.utils.icu import sort_key
|
||||||
from calibre.utils.magick.draw import thumbnail
|
from calibre.utils.magick.draw import thumbnail
|
||||||
|
|
||||||
@ -31,6 +32,8 @@ class SearchDialog(QDialog, Ui_Dialog):
|
|||||||
def __init__(self, istores, *args):
|
def __init__(self, istores, *args):
|
||||||
QDialog.__init__(self, *args)
|
QDialog.__init__(self, *args)
|
||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
|
self.config = DynamicConfig('store_search')
|
||||||
|
|
||||||
# We keep a cache of store plugins and reference them by name.
|
# We keep a cache of store plugins and reference them by name.
|
||||||
self.store_plugins = istores
|
self.store_plugins = istores
|
||||||
@ -60,8 +63,9 @@ class SearchDialog(QDialog, Ui_Dialog):
|
|||||||
self.select_all_stores.clicked.connect(self.stores_select_all)
|
self.select_all_stores.clicked.connect(self.stores_select_all)
|
||||||
self.select_invert_stores.clicked.connect(self.stores_select_invert)
|
self.select_invert_stores.clicked.connect(self.stores_select_invert)
|
||||||
self.select_none_stores.clicked.connect(self.stores_select_none)
|
self.select_none_stores.clicked.connect(self.stores_select_none)
|
||||||
|
self.finished.connect(self.dialog_closed)
|
||||||
|
|
||||||
self.resize_columns()
|
self.restore_state()
|
||||||
|
|
||||||
def resize_columns(self):
|
def resize_columns(self):
|
||||||
total = 600
|
total = 600
|
||||||
@ -105,7 +109,30 @@ class SearchDialog(QDialog, Ui_Dialog):
|
|||||||
self.hang_check = 0
|
self.hang_check = 0
|
||||||
self.checker.start(100)
|
self.checker.start(100)
|
||||||
self.search_pool.start_threads()
|
self.search_pool.start_threads()
|
||||||
|
|
||||||
|
def save_state(self):
|
||||||
|
self.config['store_search_geometry'] = self.saveGeometry()
|
||||||
|
self.config['store_search_store_splitter_state'] = self.store_splitter.saveState()
|
||||||
|
self.config['store_search_results_view_column_width'] = [self.results_view.columnWidth(i) for i in range(self.model.columnCount())]
|
||||||
|
|
||||||
|
def restore_state(self):
|
||||||
|
geometry = self.config['store_search_geometry']
|
||||||
|
if geometry:
|
||||||
|
self.restoreGeometry(geometry)
|
||||||
|
|
||||||
|
splitter_state = self.config['store_search_store_splitter_state']
|
||||||
|
if splitter_state:
|
||||||
|
self.store_splitter.restoreState(splitter_state)
|
||||||
|
|
||||||
|
results_cwidth = self.config['store_search_results_view_column_width']
|
||||||
|
if results_cwidth:
|
||||||
|
for i, x in enumerate(results_cwidth):
|
||||||
|
if i >= self.model.columnCount():
|
||||||
|
break
|
||||||
|
self.results_view.setColumnWidth(i, x)
|
||||||
|
else:
|
||||||
|
self.resize_columns()
|
||||||
|
|
||||||
def get_results(self):
|
def get_results(self):
|
||||||
# We only want the search plugins to run
|
# We only want the search plugins to run
|
||||||
# a maximum set amount of time before giving up.
|
# a maximum set amount of time before giving up.
|
||||||
@ -149,11 +176,11 @@ class SearchDialog(QDialog, Ui_Dialog):
|
|||||||
def stores_select_none(self):
|
def stores_select_none(self):
|
||||||
for check in self.get_store_checks():
|
for check in self.get_store_checks():
|
||||||
check.setChecked(False)
|
check.setChecked(False)
|
||||||
|
|
||||||
def closeEvent(self, e):
|
def dialog_closed(self, result):
|
||||||
self.model.closing()
|
self.model.closing()
|
||||||
self.search_pool.abort()
|
self.search_pool.abort()
|
||||||
QDialog.closeEvent(self, e)
|
self.save_state()
|
||||||
|
|
||||||
|
|
||||||
class GenericDownloadThreadPool(object):
|
class GenericDownloadThreadPool(object):
|
||||||
|
@ -39,7 +39,7 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QSplitter" name="splitter_3">
|
<widget class="QSplitter" name="store_splitter">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user