Quickview: Add a checkbox to lock the quickview window so that it does
not change while moving around in the main book list

Quickview: Auto-close the quickview window when changing libraries
This commit is contained in:
Kovid Goyal 2013-11-07 20:14:48 +05:30
commit e1f23c9352
3 changed files with 46 additions and 19 deletions

View File

@ -47,4 +47,4 @@ class ShowQuickviewAction(InterfaceAction):
def library_changed(self, db): def library_changed(self, db):
if self.current_instance and not self.current_instance.is_closed: if self.current_instance and not self.current_instance.is_closed:
self.current_instance.set_database(db) self.current_instance.reject()

View File

@ -6,7 +6,7 @@ __docformat__ = 'restructuredtext en'
from PyQt4.Qt import (Qt, QDialog, QAbstractItemView, QTableWidgetItem, from PyQt4.Qt import (Qt, QDialog, QAbstractItemView, QTableWidgetItem,
QListWidgetItem, QByteArray, QCoreApplication, QListWidgetItem, QByteArray, QCoreApplication,
QApplication, pyqtSignal) QApplication, pyqtSignal, QDialogButtonBox)
from calibre.customize.ui import find_plugin from calibre.customize.ui import find_plugin
from calibre.gui2 import gprefs from calibre.gui2 import gprefs
@ -112,14 +112,8 @@ class Quickview(QDialog, Ui_Quickview):
self.search_button.clicked.connect(self.do_search) self.search_button.clicked.connect(self.do_search)
view.model().new_bookdisplay_data.connect(self.book_was_changed) view.model().new_bookdisplay_data.connect(self.book_was_changed)
def set_database(self, db): close_button = self.buttonBox.button(QDialogButtonBox.Close)
self.db = db close_button.setAutoDefault(False)
self.items.blockSignals(True)
self.books_table.blockSignals(True)
self.items.clear()
self.books_table.setRowCount(0)
self.books_table.blockSignals(False)
self.items.blockSignals(False)
# search button # search button
def do_search(self): def do_search(self):
@ -138,7 +132,7 @@ class Quickview(QDialog, Ui_Quickview):
# view is changed, triggering a book_was_changed signal. Unfortunately # view is changed, triggering a book_was_changed signal. Unfortunately
# this happens before the library_changed actions are run, meaning we # this happens before the library_changed actions are run, meaning we
# still have the old database. To avoid the problem we just ignore the # still have the old database. To avoid the problem we just ignore the
# operation if we get an exception. The set_database will come # operation if we get an exception. The "close" will come
# eventually. # eventually.
try: try:
self.refresh(self.view.model().index(self.db.row(mi.id), self.current_column)) self.refresh(self.view.model().index(self.db.row(mi.id), self.current_column))
@ -153,6 +147,9 @@ class Quickview(QDialog, Ui_Quickview):
# Given a cell in the library view, display the information # Given a cell in the library view, display the information
def refresh(self, idx): def refresh(self, idx):
if self.lock_qv.isChecked():
return
bv_row = idx.row() bv_row = idx.row()
self.current_column = idx.column() self.current_column = idx.column()
key = self.view.model().column_map[self.current_column] key = self.view.model().column_map[self.current_column]
@ -167,7 +164,7 @@ class Quickview(QDialog, Ui_Quickview):
self.indicate_no_items() self.indicate_no_items()
return return
key = self.current_key key = self.current_key
self.items_label.setText('{0} ({1})'.format( self.items_label.setText(_('&Item: {0} ({1})').format(
self.db.field_metadata[key]['name'], key)) self.db.field_metadata[key]['name'], key))
self.items.blockSignals(True) self.items.blockSignals(True)
@ -219,7 +216,7 @@ class Quickview(QDialog, Ui_Quickview):
sort_results=False) sort_results=False)
self.books_table.setRowCount(len(books)) self.books_table.setRowCount(len(books))
self.books_label.setText(_('Books with selected item "{0}": {1}'). self.books_label.setText(_('&Books with selected item "{0}": {1}').
format(selected_item, len(books))) format(selected_item, len(books)))
select_item = None select_item = None
@ -296,7 +293,7 @@ class Quickview(QDialog, Ui_Quickview):
gprefs['quickview_dialog_books_table_widths'] = self.books_table_column_widths gprefs['quickview_dialog_books_table_widths'] = self.books_table_column_widths
gprefs['quickview_dialog_geometry'] = bytearray(self.saveGeometry()) gprefs['quickview_dialog_geometry'] = bytearray(self.saveGeometry())
def close(self): def _close(self):
self.save_state() self.save_state()
# clean up to prevent memory leaks # clean up to prevent memory leaks
self.db = self.view = self.gui = None self.db = self.view = self.gui = None
@ -304,10 +301,10 @@ class Quickview(QDialog, Ui_Quickview):
# called by the window system # called by the window system
def closeEvent(self, *args): def closeEvent(self, *args):
self.close() self._close()
QDialog.closeEvent(self, *args) QDialog.closeEvent(self, *args)
# called by the close button # called by the close button
def reject(self): def reject(self):
self.close() self._close()
QDialog.reject(self) QDialog.reject(self)

View File

@ -22,8 +22,8 @@
<layout class="QGridLayout"> <layout class="QGridLayout">
<item row="0" column="0"> <item row="0" column="0">
<widget class="QLabel" name="items_label"> <widget class="QLabel" name="items_label">
<property name="text"> <property name="buddy">
<string>Items</string> <cstring>items</cstring>
</property> </property>
</widget> </widget>
</item> </item>
@ -39,6 +39,9 @@
</item> </item>
<item row="0" column="1"> <item row="0" column="1">
<widget class="QLabel" name="books_label"> <widget class="QLabel" name="books_label">
<property name="buddy">
<cstring>books_table</cstring>
</property>
</widget> </widget>
</item> </item>
<item row="1" column="1"> <item row="1" column="1">
@ -59,14 +62,41 @@
</item> </item>
<item row="3" column="0" colspan="2"> <item row="3" column="0" colspan="2">
<layout class="QHBoxLayout"> <layout class="QHBoxLayout">
<item>
<widget class="QCheckBox" name="lock_qv">
<property name="text">
<string>&amp;Lock Quickview contents</string>
</property>
<property name="toolTip">
<string>Select to prevent Quickview from changing content when the
selection on the library view is changed</string>
</property>
</widget>
</item>
<item>
<spacer>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
<item> <item>
<widget class="QPushButton" name="search_button"> <widget class="QPushButton" name="search_button">
<property name="text"> <property name="text">
<string>Search</string> <string>&amp;Search</string>
</property> </property>
<property name="toolTip"> <property name="toolTip">
<string>Search in the library view for the selected item</string> <string>Search in the library view for the selected item</string>
</property> </property>
<property name="autoDefault">
<bool>false</bool>
</property>
</widget> </widget>
</item> </item>
<item> <item>