diff --git a/src/calibre/__init__.py b/src/calibre/__init__.py index 737fa0b383..e44f8d8ec6 100644 --- a/src/calibre/__init__.py +++ b/src/calibre/__init__.py @@ -141,7 +141,10 @@ def prints(*args, **kwargs): raise arg = repr(arg) - file.write(arg) + try: + file.write(arg) + except: + file.write(repr(arg)) if i != len(args)-1: file.write(sep) file.write(end) diff --git a/src/calibre/devices/prs505/sony_cache.py b/src/calibre/devices/prs505/sony_cache.py index f4d1889d64..a0057d8ec9 100644 --- a/src/calibre/devices/prs505/sony_cache.py +++ b/src/calibre/devices/prs505/sony_cache.py @@ -16,7 +16,8 @@ from calibre import prints, guess_type from calibre.devices.errors import DeviceError from calibre.constants import DEBUG from calibre.ebooks.chardet import xml_to_unicode -from calibre.ebooks.metadata import string_to_authors, authors_to_string +from calibre.ebooks.metadata import string_to_authors, authors_to_string, \ + title_sort # Utility functions {{{ EMPTY_CARD_CACHE = '''\ @@ -325,6 +326,7 @@ class XMLCache(object): if record is None: record = self.create_text_record(root, i, book.lpath) self.update_text_record(record, book, path, i) + bl_pmap = playlist_map[i] self.update_playlists(i, root, booklist, bl_pmap, collections_attributes) @@ -339,15 +341,12 @@ class XMLCache(object): collections_attributes): collections = booklist.get_collections(collections_attributes) for category, books in collections.items(): - for b in books: - if self.book_by_lpath(b.lpath, root) is None: - print b.lpath records = [self.book_by_lpath(b.lpath, root) for b in books] # Remove any books that were not found, although this # *should* never happen if DEBUG and None in records: prints('WARNING: Some elements in the JSON cache were not' - 'found in the XML cache') + ' found in the XML cache') records = [x for x in records if x is not None] for rec in records: if rec.get('id', None) is None: @@ -416,6 +415,10 @@ class XMLCache(object): record.set('date', date) record.set('size', str(os.stat(path).st_size)) record.set('title', book.title) + ts = book.title_sort + if not ts: + ts = title_sort(book.title) + record.set('titleSorter', ts) record.set('author', authors_to_string(book.authors)) ext = os.path.splitext(path)[1] if ext: diff --git a/src/calibre/gui2/library/views.py b/src/calibre/gui2/library/views.py index e5c6ffd5f7..d2c3839466 100644 --- a/src/calibre/gui2/library/views.py +++ b/src/calibre/gui2/library/views.py @@ -8,7 +8,8 @@ __docformat__ = 'restructuredtext en' import os from functools import partial -from PyQt4.Qt import QTableView, Qt, QAbstractItemView, QMenu, pyqtSignal +from PyQt4.Qt import QTableView, Qt, QAbstractItemView, QMenu, pyqtSignal, \ + QModelIndex from calibre.gui2.library.delegates import RatingDelegate, PubDateDelegate, \ TextDelegate, DateDelegate, TagsDelegate, CcTextDelegate, \ @@ -110,17 +111,21 @@ class BooksView(QTableView): # {{{ ac = a if self._model.sorted_on[1] == Qt.AscendingOrder else d ac.setCheckable(True) ac.setChecked(True) - m = self.column_header_context_menu.addMenu( - _('Change text alignment for %s') % name) - al = self._model.alignment_map.get(col, 'left') - for x, t in (('left', _('Left')), ('right', _('Right')), ('center', - _('Center'))): - a = m.addAction(t, - partial(self.column_header_context_handler, - action='align_'+x, column=col)) - if al == x: - a.setCheckable(True) - a.setChecked(True) + if col not in ('ondevice', 'rating', 'inlibrary') and \ + (not self.model().is_custom_column(col) or \ + self.model().custom_columns[col]['datatype'] not in ('bool', + 'rating')): + m = self.column_header_context_menu.addMenu( + _('Change text alignment for %s') % name) + al = self._model.alignment_map.get(col, 'left') + for x, t in (('left', _('Left')), ('right', _('Right')), ('center', + _('Center'))): + a = m.addAction(t, + partial(self.column_header_context_handler, + action='align_'+x, column=col)) + if al == x: + a.setCheckable(True) + a.setChecked(True) @@ -288,6 +293,12 @@ class BooksView(QTableView): # {{{ old_state['sort_history'] = tweaks['sort_columns_at_startup'] self.apply_state(old_state) + + # Resize all rows to have the correct height + if self.model().rowCount(QModelIndex()) > 0: + self.resizeRowToContents(0) + self.verticalHeader().setDefaultSectionSize(self.rowHeight(0)) + self.was_restored = True # }}} diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 8f30e5a9c4..6ed51d3eff 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -636,16 +636,9 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI): self.download_scheduled_recipe, Qt.QueuedConnection) self.library_view.verticalHeader().sectionClicked.connect(self.view_specific_book) - if self.library_view.model().rowCount(None) > 1: - self.library_view.resizeRowToContents(0) - height = self.library_view.rowHeight(0) - else: - height = None for view in ('library', 'memory', 'card_a', 'card_b'): view = getattr(self, view+'_view') view.verticalHeader().sectionDoubleClicked.connect(self.view_specific_book) - if height is not None: - view.verticalHeader().setDefaultSectionSize(height) self.location_view.setCurrentIndex(self.location_view.model().index(0))