From e7c666d60fe4b1c9907f9f142c72f0e1042acf57 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 20 May 2010 10:57:31 +0100 Subject: [PATCH 1/2] Suggested changes after working with new sony driver --- src/calibre/devices/prs505/sony_cache.py | 9 ++++++--- src/calibre/gui2/ui.py | 13 +++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/calibre/devices/prs505/sony_cache.py b/src/calibre/devices/prs505/sony_cache.py index 262d1a3f64..f4d1889d64 100644 --- a/src/calibre/devices/prs505/sony_cache.py +++ b/src/calibre/devices/prs505/sony_cache.py @@ -325,9 +325,9 @@ 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) + bl_pmap = playlist_map[i] + self.update_playlists(i, root, booklist, bl_pmap, + collections_attributes) self.fix_ids() @@ -339,6 +339,9 @@ 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 diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 3f67e4184c..8f30e5a9c4 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -636,19 +636,20 @@ 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)) - self._add_filesystem_book = Dispatcher(self.__add_filesystem_book) - v = self.library_view - if v.model().rowCount(None) > 1: - v.resizeRowToContents(0) - height = v.rowHeight(0) - self.library_view.verticalHeader().setDefaultSectionSize(height) self.keyboard_interrupt.connect(self.quit, type=Qt.QueuedConnection) def do_edit_categories(self): From 210d81c626e13370f3a474a3a9851625703a08a2 Mon Sep 17 00:00:00 2001 From: Charles Haley <> Date: Thu, 20 May 2010 12:54:06 +0100 Subject: [PATCH 2/2] Add internal date formatter --- src/calibre/gui2/library/delegates.py | 8 ++++---- src/calibre/utils/date.py | 25 +++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/calibre/gui2/library/delegates.py b/src/calibre/gui2/library/delegates.py index c1e4915db1..d908ed01b4 100644 --- a/src/calibre/gui2/library/delegates.py +++ b/src/calibre/gui2/library/delegates.py @@ -17,7 +17,7 @@ from PyQt4.Qt import QColor, Qt, QModelIndex, QSize, \ from calibre.gui2 import UNDEFINED_QDATE from calibre.gui2.widgets import EnLineEdit, TagsLineEdit -from calibre.utils.date import now +from calibre.utils.date import now, format_date from calibre.utils.config import tweaks from calibre.gui2.dialogs.comments_dialog import CommentsDialog @@ -98,7 +98,7 @@ class DateDelegate(QStyledItemDelegate): # {{{ d = val.toDate() if d == UNDEFINED_QDATE: return '' - return d.toString('dd MMM yyyy') + return format_date(d.toPyDate(), 'dd MMM yyyy') def createEditor(self, parent, option, index): qde = QStyledItemDelegate.createEditor(self, parent, option, index) @@ -121,7 +121,7 @@ class PubDateDelegate(QStyledItemDelegate): # {{{ format = tweaks['gui_pubdate_display_format'] if format is None: format = 'MMM yyyy' - return d.toString(format) + return format_date(d.toPyDate(), format) def createEditor(self, parent, option, index): qde = QStyledItemDelegate.createEditor(self, parent, option, index) @@ -195,7 +195,7 @@ class CcDateDelegate(QStyledItemDelegate): # {{{ d = val.toDate() if d == UNDEFINED_QDATE: return '' - return d.toString(self.format) + return format_date(d.toPyDate(), self.format) def createEditor(self, parent, option, index): qde = QStyledItemDelegate.createEditor(self, parent, option, index) diff --git a/src/calibre/utils/date.py b/src/calibre/utils/date.py index a43927c9c5..dc84e6acf4 100644 --- a/src/calibre/utils/date.py +++ b/src/calibre/utils/date.py @@ -6,6 +6,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' +import re from datetime import datetime from dateutil.parser import parse @@ -113,3 +114,27 @@ def utcnow(): def utcfromtimestamp(stamp): return datetime.utcfromtimestamp(stamp).replace(tzinfo=_utc_tz) + +def format_date(dt, format): + ''' Return a date formatted as a string using a subset of Qt's formatting codes ''' + def format_day(mo): + l = len(mo.group(0)) + if l == 1: return '%d'%dt.day + if l == 2: return '%02d'%dt.day + if l == 3: return dt.strftime('%a') + return dt.strftime('%A') + + def format_month(mo): + l = len(mo.group(0)) + if l == 1: return '%d'%dt.month + if l == 2: return '%02d'%dt.month + if l == 3: return dt.strftime('%b') + return dt.strftime('%B') + + def format_year(mo): + if len(mo.group(0)) == 2: return '%02d'%(dt.year % 100) + return '%04d'%dt.year + + format = re.sub('d{1,4}', format_day, format) + format = re.sub('M{1,4}', format_month, format) + return re.sub('yyyy|yy', format_year, format)