mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
...
This commit is contained in:
commit
0376c0a6ef
@ -326,9 +326,10 @@ class XMLCache(object):
|
|||||||
if record is None:
|
if record is None:
|
||||||
record = self.create_text_record(root, i, book.lpath)
|
record = self.create_text_record(root, i, book.lpath)
|
||||||
self.update_text_record(record, book, path, i)
|
self.update_text_record(record, book, path, i)
|
||||||
bl_pmap = playlist_map[i]
|
|
||||||
self.update_playlists(i, root, booklist, bl_pmap,
|
bl_pmap = playlist_map[i]
|
||||||
collections_attributes)
|
self.update_playlists(i, root, booklist, bl_pmap,
|
||||||
|
collections_attributes)
|
||||||
|
|
||||||
self.fix_ids()
|
self.fix_ids()
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ from PyQt4.Qt import QColor, Qt, QModelIndex, QSize, \
|
|||||||
|
|
||||||
from calibre.gui2 import UNDEFINED_QDATE
|
from calibre.gui2 import UNDEFINED_QDATE
|
||||||
from calibre.gui2.widgets import EnLineEdit, TagsLineEdit
|
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.utils.config import tweaks
|
||||||
from calibre.gui2.dialogs.comments_dialog import CommentsDialog
|
from calibre.gui2.dialogs.comments_dialog import CommentsDialog
|
||||||
|
|
||||||
@ -98,7 +98,7 @@ class DateDelegate(QStyledItemDelegate): # {{{
|
|||||||
d = val.toDate()
|
d = val.toDate()
|
||||||
if d == UNDEFINED_QDATE:
|
if d == UNDEFINED_QDATE:
|
||||||
return ''
|
return ''
|
||||||
return d.toString('dd MMM yyyy')
|
return format_date(d.toPyDate(), 'dd MMM yyyy')
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
qde = QStyledItemDelegate.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']
|
format = tweaks['gui_pubdate_display_format']
|
||||||
if format is None:
|
if format is None:
|
||||||
format = 'MMM yyyy'
|
format = 'MMM yyyy'
|
||||||
return d.toString(format)
|
return format_date(d.toPyDate(), format)
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
qde = QStyledItemDelegate.createEditor(self, parent, option, index)
|
qde = QStyledItemDelegate.createEditor(self, parent, option, index)
|
||||||
@ -195,7 +195,7 @@ class CcDateDelegate(QStyledItemDelegate): # {{{
|
|||||||
d = val.toDate()
|
d = val.toDate()
|
||||||
if d == UNDEFINED_QDATE:
|
if d == UNDEFINED_QDATE:
|
||||||
return ''
|
return ''
|
||||||
return d.toString(self.format)
|
return format_date(d.toPyDate(), self.format)
|
||||||
|
|
||||||
def createEditor(self, parent, option, index):
|
def createEditor(self, parent, option, index):
|
||||||
qde = QStyledItemDelegate.createEditor(self, parent, option, index)
|
qde = QStyledItemDelegate.createEditor(self, parent, option, index)
|
||||||
|
@ -8,7 +8,8 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os
|
import os
|
||||||
from functools import partial
|
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, \
|
from calibre.gui2.library.delegates import RatingDelegate, PubDateDelegate, \
|
||||||
TextDelegate, DateDelegate, TagsDelegate, CcTextDelegate, \
|
TextDelegate, DateDelegate, TagsDelegate, CcTextDelegate, \
|
||||||
@ -288,6 +289,12 @@ class BooksView(QTableView): # {{{
|
|||||||
old_state['sort_history'] = tweaks['sort_columns_at_startup']
|
old_state['sort_history'] = tweaks['sort_columns_at_startup']
|
||||||
|
|
||||||
self.apply_state(old_state)
|
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
|
self.was_restored = True
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
@ -642,13 +642,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
|||||||
|
|
||||||
self.location_view.setCurrentIndex(self.location_view.model().index(0))
|
self.location_view.setCurrentIndex(self.location_view.model().index(0))
|
||||||
|
|
||||||
|
|
||||||
self._add_filesystem_book = Dispatcher(self.__add_filesystem_book)
|
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)
|
self.keyboard_interrupt.connect(self.quit, type=Qt.QueuedConnection)
|
||||||
|
|
||||||
def do_edit_categories(self):
|
def do_edit_categories(self):
|
||||||
|
@ -6,6 +6,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
@ -113,3 +114,27 @@ def utcnow():
|
|||||||
|
|
||||||
def utcfromtimestamp(stamp):
|
def utcfromtimestamp(stamp):
|
||||||
return datetime.utcfromtimestamp(stamp).replace(tzinfo=_utc_tz)
|
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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user