mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Improved editing of dates for custom columns
This commit is contained in:
commit
5b0719dbcf
@ -10,9 +10,10 @@ from functools import partial
|
|||||||
|
|
||||||
from PyQt4.Qt import QComboBox, QLabel, QSpinBox, QDoubleSpinBox, QDateEdit, \
|
from PyQt4.Qt import QComboBox, QLabel, QSpinBox, QDoubleSpinBox, QDateEdit, \
|
||||||
QDate, QGroupBox, QVBoxLayout, QPlainTextEdit, QSizePolicy, \
|
QDate, QGroupBox, QVBoxLayout, QPlainTextEdit, QSizePolicy, \
|
||||||
QSpacerItem, QIcon, QCheckBox, QWidget, QHBoxLayout, SIGNAL
|
QSpacerItem, QIcon, QCheckBox, QWidget, QHBoxLayout, SIGNAL, \
|
||||||
|
QPushButton
|
||||||
|
|
||||||
from calibre.utils.date import qt_to_dt
|
from calibre.utils.date import qt_to_dt, now
|
||||||
from calibre.gui2.widgets import TagsLineEdit, EnComboBox
|
from calibre.gui2.widgets import TagsLineEdit, EnComboBox
|
||||||
from calibre.gui2 import UNDEFINED_QDATE
|
from calibre.gui2 import UNDEFINED_QDATE
|
||||||
from calibre.utils.config import tweaks
|
from calibre.utils.config import tweaks
|
||||||
@ -132,20 +133,30 @@ class DateEdit(QDateEdit):
|
|||||||
|
|
||||||
def focusInEvent(self, x):
|
def focusInEvent(self, x):
|
||||||
self.setSpecialValueText('')
|
self.setSpecialValueText('')
|
||||||
|
QDateEdit.focusInEvent(self, x)
|
||||||
|
|
||||||
def focusOutEvent(self, x):
|
def focusOutEvent(self, x):
|
||||||
self.setSpecialValueText(_('Undefined'))
|
self.setSpecialValueText(_('Undefined'))
|
||||||
|
QDateEdit.focusOutEvent(self, x)
|
||||||
|
|
||||||
|
def set_to_today(self):
|
||||||
|
self.setDate(now())
|
||||||
|
|
||||||
class DateTime(Base):
|
class DateTime(Base):
|
||||||
|
|
||||||
def setup_ui(self, parent):
|
def setup_ui(self, parent):
|
||||||
self.widgets = [QLabel('&'+self.col_metadata['name']+':', parent),
|
cm = self.col_metadata
|
||||||
DateEdit(parent)]
|
self.widgets = [QLabel('&'+cm['name']+':', parent), DateEdit(parent),
|
||||||
|
QLabel(''), QPushButton(_('Set \'%s\' to today')%cm['name'], parent)]
|
||||||
w = self.widgets[1]
|
w = self.widgets[1]
|
||||||
w.setDisplayFormat('dd MMM yyyy')
|
format = cm['display'].get('date_format','')
|
||||||
|
if not format:
|
||||||
|
format = 'dd MMM yyyy'
|
||||||
|
w.setDisplayFormat(format)
|
||||||
w.setCalendarPopup(True)
|
w.setCalendarPopup(True)
|
||||||
w.setMinimumDate(UNDEFINED_QDATE)
|
w.setMinimumDate(UNDEFINED_QDATE)
|
||||||
w.setSpecialValueText(_('Undefined'))
|
w.setSpecialValueText(_('Undefined'))
|
||||||
|
self.widgets[3].clicked.connect(w.set_to_today)
|
||||||
|
|
||||||
def setter(self, val):
|
def setter(self, val):
|
||||||
if val is None:
|
if val is None:
|
||||||
@ -156,7 +167,7 @@ class DateTime(Base):
|
|||||||
|
|
||||||
def getter(self):
|
def getter(self):
|
||||||
val = self.widgets[1].date()
|
val = self.widgets[1].date()
|
||||||
if val == UNDEFINED_QDATE:
|
if val <= UNDEFINED_QDATE:
|
||||||
val = None
|
val = None
|
||||||
else:
|
else:
|
||||||
val = qt_to_dt(val)
|
val = qt_to_dt(val)
|
||||||
|
@ -96,7 +96,7 @@ class DateDelegate(QStyledItemDelegate): # {{{
|
|||||||
|
|
||||||
def displayText(self, val, locale):
|
def displayText(self, val, locale):
|
||||||
d = val.toDate()
|
d = val.toDate()
|
||||||
if d == UNDEFINED_QDATE:
|
if d <= UNDEFINED_QDATE:
|
||||||
return ''
|
return ''
|
||||||
return format_date(d.toPyDate(), 'dd MMM yyyy')
|
return format_date(d.toPyDate(), 'dd MMM yyyy')
|
||||||
|
|
||||||
@ -116,7 +116,7 @@ class PubDateDelegate(QStyledItemDelegate): # {{{
|
|||||||
|
|
||||||
def displayText(self, val, locale):
|
def displayText(self, val, locale):
|
||||||
d = val.toDate()
|
d = val.toDate()
|
||||||
if d == UNDEFINED_QDATE:
|
if d <= UNDEFINED_QDATE:
|
||||||
return ''
|
return ''
|
||||||
format = tweaks['gui_pubdate_display_format']
|
format = tweaks['gui_pubdate_display_format']
|
||||||
if format is None:
|
if format is None:
|
||||||
@ -194,7 +194,7 @@ class CcDateDelegate(QStyledItemDelegate): # {{{
|
|||||||
|
|
||||||
def displayText(self, val, locale):
|
def displayText(self, val, locale):
|
||||||
d = val.toDate()
|
d = val.toDate()
|
||||||
if d == UNDEFINED_QDATE:
|
if d <= UNDEFINED_QDATE:
|
||||||
return ''
|
return ''
|
||||||
return format_date(d.toPyDate(), self.format)
|
return format_date(d.toPyDate(), self.format)
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ class CcDateDelegate(QStyledItemDelegate): # {{{
|
|||||||
|
|
||||||
def setModelData(self, editor, model, index):
|
def setModelData(self, editor, model, index):
|
||||||
val = editor.date()
|
val = editor.date()
|
||||||
if val == UNDEFINED_QDATE:
|
if val <= UNDEFINED_QDATE:
|
||||||
val = None
|
val = None
|
||||||
model.setData(index, QVariant(val), Qt.EditRole)
|
model.setData(index, QVariant(val), Qt.EditRole)
|
||||||
|
|
||||||
|
@ -1216,7 +1216,9 @@ class DeviceBooksModel(BooksModel): # {{{
|
|||||||
return done
|
return done
|
||||||
|
|
||||||
def set_editable(self, editable):
|
def set_editable(self, editable):
|
||||||
self.editable = editable
|
# Cannot edit if metadata is sent on connect. Reason: changes will
|
||||||
|
# revert to what is in the library on next connect.
|
||||||
|
self.editable = editable and prefs['manage_device_metadata']!='on_connect'
|
||||||
|
|
||||||
def set_search_restriction(self, s):
|
def set_search_restriction(self, s):
|
||||||
pass
|
pass
|
||||||
|
@ -209,13 +209,13 @@ class ResultCache(SearchQueryParser):
|
|||||||
if query == 'false':
|
if query == 'false':
|
||||||
for item in self._data:
|
for item in self._data:
|
||||||
if item is None: continue
|
if item is None: continue
|
||||||
if item[loc] is None or item[loc] == UNDEFINED_DATE:
|
if item[loc] is None or item[loc] <= UNDEFINED_DATE:
|
||||||
matches.add(item[0])
|
matches.add(item[0])
|
||||||
return matches
|
return matches
|
||||||
if query == 'true':
|
if query == 'true':
|
||||||
for item in self._data:
|
for item in self._data:
|
||||||
if item is None: continue
|
if item is None: continue
|
||||||
if item[loc] is not None and item[loc] != UNDEFINED_DATE:
|
if item[loc] is not None and item[loc] > UNDEFINED_DATE:
|
||||||
matches.add(item[0])
|
matches.add(item[0])
|
||||||
return matches
|
return matches
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user