mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Basic metadata widgets layout complete
This commit is contained in:
parent
631bd5d63d
commit
96be6e9035
@ -7,11 +7,10 @@ __docformat__ = 'restructuredtext en'
|
||||
|
||||
import textwrap, re, os
|
||||
|
||||
from PyQt4.Qt import Qt, \
|
||||
from PyQt4.Qt import Qt, QDateEdit, QDate, \
|
||||
QIcon, QToolButton, QWidget, QLabel, QGridLayout, \
|
||||
QDoubleSpinBox, QListWidgetItem, QSize, QPixmap, \
|
||||
QPushButton, QSpinBox, \
|
||||
QMessageBox, QLineEdit
|
||||
QPushButton, QSpinBox, QMessageBox, QLineEdit
|
||||
|
||||
from calibre.gui2.widgets import EnLineEdit, CompleteComboBox, \
|
||||
EnComboBox, FormatList, ImageView, CompleteLineEdit
|
||||
@ -19,9 +18,9 @@ from calibre.utils.icu import sort_key
|
||||
from calibre.utils.config import tweaks
|
||||
from calibre.ebooks.metadata import title_sort, authors_to_string, \
|
||||
string_to_authors, check_isbn
|
||||
from calibre.gui2 import file_icon_provider, \
|
||||
from calibre.gui2 import file_icon_provider, UNDEFINED_QDATE, UNDEFINED_DATE, \
|
||||
choose_files, error_dialog, choose_images, question_dialog
|
||||
from calibre.utils.date import local_tz
|
||||
from calibre.utils.date import local_tz, qt_to_dt
|
||||
from calibre import strftime
|
||||
from calibre.ebooks import BOOK_EXTENSIONS
|
||||
from calibre.customize.ui import run_plugins_on_import
|
||||
@ -924,4 +923,62 @@ class PublisherEdit(EnComboBox): # {{{
|
||||
|
||||
# }}}
|
||||
|
||||
class DateEdit(QDateEdit): # {{{
|
||||
|
||||
TOOLTIP = ''
|
||||
LABEL = _('&Date:')
|
||||
FMT = 'd MMM yyyy'
|
||||
ATTR = 'timestamp'
|
||||
|
||||
def __init__(self, parent):
|
||||
QDateEdit.__init__(self, parent)
|
||||
self.setToolTip(self.TOOLTIP)
|
||||
self.setWhatsThis(self.TOOLTIP)
|
||||
fmt = self.FMT
|
||||
if fmt is None:
|
||||
fmt = tweaks['gui_pubdate_display_format']
|
||||
if fmt is None:
|
||||
fmt = 'MMM yyyy'
|
||||
self.setDisplayFormat(fmt)
|
||||
self.setCalendarPopup(True)
|
||||
self.setMinimumDate(UNDEFINED_QDATE)
|
||||
self.setSpecialValueText(_('Undefined'))
|
||||
self.clear_button = QToolButton(parent)
|
||||
self.clear_button.setIcon(QIcon(I('trash.png')))
|
||||
self.clear_button.setToolTip(_('Clear date'))
|
||||
self.clear_button.clicked.connect(self.reset_date)
|
||||
|
||||
def reset_date(self, *args):
|
||||
self.current_val = None
|
||||
|
||||
@dynamic_property
|
||||
def current_val(self):
|
||||
def fget(self):
|
||||
return qt_to_dt(self.date())
|
||||
def fset(self, val):
|
||||
if val is None:
|
||||
val = UNDEFINED_DATE
|
||||
self.setDate(QDate(val.year, val.month, val.day))
|
||||
return property(fget=fget, fset=fset)
|
||||
|
||||
def initialize(self, db, id_):
|
||||
self.current_val = getattr(db, self.ATTR)(id_, index_is_id=True)
|
||||
self.original_val = self.current_val
|
||||
|
||||
def commit(self, db, id_):
|
||||
if self.changed:
|
||||
getattr(db, 'set_'+self.ATTR)(id_, self.current_val, commit=False,
|
||||
notify=False)
|
||||
return True
|
||||
|
||||
@property
|
||||
def changed(self):
|
||||
o, c = self.original_val, self.current_val
|
||||
return o.year != c.year or o.month != c.month or o.day != c.day
|
||||
|
||||
class PubdateEdit(DateEdit):
|
||||
LABEL = _('Publishe&d:')
|
||||
FMT = None
|
||||
ATTR = 'pubdate'
|
||||
|
||||
# }}}
|
||||
|
@ -6,16 +6,17 @@ __copyright__ = '2011, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||
__docformat__ = 'restructuredtext en'
|
||||
|
||||
|
||||
from PyQt4.Qt import Qt, QVBoxLayout, QHBoxLayout, QWidget, \
|
||||
QGridLayout, pyqtSignal, QDialogButtonBox, QScrollArea, \
|
||||
QTabWidget, QIcon, QToolButton, QSplitter, QGroupBox
|
||||
from PyQt4.Qt import Qt, QVBoxLayout, QHBoxLayout, QWidget, QPushButton, \
|
||||
QGridLayout, pyqtSignal, QDialogButtonBox, QScrollArea, QFont, \
|
||||
QTabWidget, QIcon, QToolButton, QSplitter, QGroupBox, QSpacerItem, \
|
||||
QSizePolicy
|
||||
|
||||
from calibre.ebooks.metadata import authors_to_string, string_to_authors
|
||||
from calibre.gui2 import ResizableDialog
|
||||
from calibre.gui2.metadata.basic_widgets import TitleEdit, AuthorsEdit, \
|
||||
AuthorSortEdit, TitleSortEdit, SeriesEdit, SeriesIndexEdit, ISBNEdit, \
|
||||
RatingEdit, PublisherEdit, TagsEdit, FormatsManager, Cover, CommentsEdit, \
|
||||
BuddyLabel
|
||||
BuddyLabel, DateEdit, PubdateEdit
|
||||
|
||||
class MetadataSingleDialog(ResizableDialog):
|
||||
|
||||
@ -119,6 +120,17 @@ class MetadataSingleDialog(ResizableDialog):
|
||||
self.publisher = PublisherEdit(self)
|
||||
self.basic_metadata_widgets.append(self.publisher)
|
||||
|
||||
self.timestamp = DateEdit(self)
|
||||
self.pubdate = PubdateEdit(self)
|
||||
self.basic_metadata_widgets.extend([self.timestamp, self.pubdate])
|
||||
|
||||
self.fetch_metadata_button = QPushButton(
|
||||
_('&Fetch metadata from server'), self)
|
||||
self.fetch_metadata_button.clicked.connect(self.fetch_metadata)
|
||||
font = self.fmb_font = QFont()
|
||||
font.setBold(True)
|
||||
self.fetch_metadata_button.setFont(font)
|
||||
|
||||
# }}}
|
||||
|
||||
def do_layout(self): # {{{
|
||||
@ -172,6 +184,7 @@ class MetadataSingleDialog(ResizableDialog):
|
||||
l.setMargin(0)
|
||||
self.splitter.addWidget(w)
|
||||
def create_row2(row, widget, button=None):
|
||||
row += 1
|
||||
ql = BuddyLabel(widget)
|
||||
l.addWidget(ql, row, 0, 1, 1)
|
||||
l.addWidget(widget, row, 1, 1, 2 if button is None else 1)
|
||||
@ -179,10 +192,19 @@ class MetadataSingleDialog(ResizableDialog):
|
||||
l.addWidget(button, row, 2, 1, 1)
|
||||
|
||||
l.addWidget(gb, 0, 0, 1, 3)
|
||||
self.tabs[0].spc_one = QSpacerItem(10, 10, QSizePolicy.Expanding,
|
||||
QSizePolicy.Expanding)
|
||||
l.addItem(self.tabs[0].spc_one, 1, 0, 1, 3)
|
||||
create_row2(1, self.rating)
|
||||
create_row2(2, self.tags, self.tags_editor_button)
|
||||
create_row2(3, self.isbn)
|
||||
create_row2(4, self.publisher)
|
||||
create_row2(4, self.timestamp, self.timestamp.clear_button)
|
||||
create_row2(5, self.pubdate, self.pubdate.clear_button)
|
||||
create_row2(6, self.publisher)
|
||||
self.tabs[0].spc_two = QSpacerItem(10, 10, QSizePolicy.Expanding,
|
||||
QSizePolicy.Expanding)
|
||||
l.addItem(self.tabs[0].spc_two, 8, 0, 1, 3)
|
||||
l.addWidget(self.fetch_metadata_button, 9, 0, 1, 3)
|
||||
|
||||
self.tabs[0].gb2 = gb = QGroupBox(_('&Comments'), self)
|
||||
gb.l = l = QVBoxLayout()
|
||||
@ -219,6 +241,9 @@ class MetadataSingleDialog(ResizableDialog):
|
||||
def tags_editor(self, *args):
|
||||
self.tags.edit(self.db, self.book_id)
|
||||
|
||||
def fetch_metadata(self, *args):
|
||||
pass # TODO: fetch metadata
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
from PyQt4.Qt import QApplication
|
||||
|
Loading…
x
Reference in New Issue
Block a user