mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #63.
This commit is contained in:
parent
a1c8fcff51
commit
6c909065c4
@ -22,7 +22,8 @@ from PyQt4.QtGui import QTableView, QProgressDialog, QAbstractItemView, QColor,
|
||||
QPen, QStyle, QPainter, QLineEdit, QApplication, \
|
||||
QPalette
|
||||
from PyQt4.QtCore import QAbstractTableModel, QVariant, Qt, QString, \
|
||||
QCoreApplication, SIGNAL, QObject, QSize, QModelIndex
|
||||
QCoreApplication, SIGNAL, QObject, QSize, QModelIndex, \
|
||||
QSettings
|
||||
|
||||
from libprs500.ptempfile import PersistentTemporaryFile
|
||||
from libprs500.library.database import LibraryDatabase
|
||||
@ -355,10 +356,26 @@ class BooksView(QTableView):
|
||||
QObject.connect(self.model(), SIGNAL('rowsInserted(QModelIndex, int, int)'), self.resizeRowsToContents)
|
||||
# Resetting the model should resize rows (model is reset after search and sort operations)
|
||||
QObject.connect(self.model(), SIGNAL('modelReset()'), self.resizeRowsToContents)
|
||||
self.cw = str(QSettings().value(self.__class__.__name__ + ' column widths', QVariant('')).toString())
|
||||
self.cw = tuple(int(i) for i in self.cw.split(','))
|
||||
|
||||
def write_settings(self):
|
||||
settings = QSettings()
|
||||
settings.setValue(self.__class__.__name__ + ' column widths',
|
||||
QVariant(','.join(str(self.columnWidth(i))
|
||||
for i in range(self.model().columnCount(None)))))
|
||||
|
||||
def restore_column_widths(self):
|
||||
if self.cw and len(self.cw):
|
||||
for i in range(len(self.cw)):
|
||||
self.setColumnWidth(i, self.cw[i])
|
||||
return True
|
||||
return False
|
||||
|
||||
def set_database(self, db):
|
||||
self._model.set_database(db)
|
||||
|
||||
|
||||
def migrate_database(self):
|
||||
if self._model.database_needs_migration():
|
||||
print 'Migrating database from pre 0.4.0 version'
|
||||
|
@ -119,6 +119,7 @@ class Main(QObject, Ui_MainWindow):
|
||||
self.stack.setCurrentIndex(0)
|
||||
self.library_view.migrate_database()
|
||||
self.library_view.sortByColumn(3, Qt.DescendingOrder)
|
||||
if not self.library_view.restore_column_widths():
|
||||
self.library_view.resizeColumnsToContents()
|
||||
self.library_view.resizeRowsToContents()
|
||||
self.search.setFocus(Qt.OtherFocusReason)
|
||||
@ -193,10 +194,10 @@ class Main(QObject, Ui_MainWindow):
|
||||
self.card_view.set_database(cardlist)
|
||||
for view in (self.memory_view, self.card_view):
|
||||
view.sortByColumn(3, Qt.DescendingOrder)
|
||||
if not view.restore_column_widths():
|
||||
view.resizeColumnsToContents()
|
||||
view.resizeRowsToContents()
|
||||
view.resize_on_select = not view.isVisible()
|
||||
#self.location_selected('main')
|
||||
############################################################################
|
||||
|
||||
|
||||
@ -456,6 +457,7 @@ class Main(QObject, Ui_MainWindow):
|
||||
if view:
|
||||
if view.resize_on_select:
|
||||
view.resizeRowsToContents()
|
||||
if not view.restore_column_widths():
|
||||
view.resizeColumnsToContents()
|
||||
view.resize_on_select = False
|
||||
self.status_bar.reset_info()
|
||||
@ -505,6 +507,10 @@ class Main(QObject, Ui_MainWindow):
|
||||
settings.beginGroup("Main Window")
|
||||
settings.setValue("size", QVariant(self.window.size()))
|
||||
settings.endGroup()
|
||||
settings.beginGroup('Book Views')
|
||||
for view in (self.library_view, self.memory_view):
|
||||
view.write_settings()
|
||||
settings.endGroup()
|
||||
|
||||
def close_event(self, e):
|
||||
msg = 'There are active jobs. Are you sure you want to quit?'
|
||||
@ -517,11 +523,12 @@ class Main(QObject, Ui_MainWindow):
|
||||
QMessageBox.Yes|QMessageBox.No, self.window)
|
||||
d.setIconPixmap(QPixmap(':/images/dialog_warning.svg'))
|
||||
d.setDefaultButton(QMessageBox.No)
|
||||
if d.exec_() == QMessageBox.Yes:
|
||||
if d.exec_() != QMessageBox.Yes:
|
||||
e.ignore()
|
||||
return
|
||||
self.write_settings()
|
||||
e.accept()
|
||||
else:
|
||||
e.ignore()
|
||||
|
||||
|
||||
def unhandled_exception(self, type, value, tb):
|
||||
sio = StringIO.StringIO()
|
||||
|
Loading…
x
Reference in New Issue
Block a user