mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement #7711 (Add "Previous" Button to edit metadata form)
This commit is contained in:
parent
e6db8b13a6
commit
2633b89d63
@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en'
|
|||||||
import os
|
import os
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from PyQt4.Qt import Qt, QMenu
|
from PyQt4.Qt import Qt, QMenu, QModelIndex
|
||||||
|
|
||||||
from calibre.gui2 import error_dialog, config
|
from calibre.gui2 import error_dialog, config
|
||||||
from calibre.gui2.dialogs.metadata_single import MetadataSingleDialog
|
from calibre.gui2.dialogs.metadata_single import MetadataSingleDialog
|
||||||
@ -126,20 +126,35 @@ class EditMetadataAction(InterfaceAction):
|
|||||||
if bulk or (bulk is None and len(rows) > 1):
|
if bulk or (bulk is None and len(rows) > 1):
|
||||||
return self.edit_bulk_metadata(checked)
|
return self.edit_bulk_metadata(checked)
|
||||||
|
|
||||||
def accepted(id):
|
row_list = [r.row() for r in rows]
|
||||||
self.gui.library_view.model().refresh_ids([id])
|
current_row = 0
|
||||||
|
changed = set([])
|
||||||
|
db = self.gui.library_view.model().db
|
||||||
|
|
||||||
for row in rows:
|
if len(row_list) == 1:
|
||||||
self.gui.iactions['View'].metadata_view_id = self.gui.library_view.model().db.id(row.row())
|
cr = row_list[0]
|
||||||
d = MetadataSingleDialog(self.gui, row.row(),
|
row_list = \
|
||||||
self.gui.library_view.model().db,
|
list(range(self.gui.library_view.model().rowCount(QModelIndex())))
|
||||||
accepted_callback=accepted,
|
current_row = row_list.index(cr)
|
||||||
cancel_all=rows.index(row) < len(rows)-1)
|
|
||||||
d.view_format.connect(self.gui.iactions['View'].metadata_view_format)
|
while True:
|
||||||
d.exec_()
|
prev = next_ = None
|
||||||
if d.cancel_all:
|
if current_row > 0:
|
||||||
|
prev = db.title(row_list[current_row-1])
|
||||||
|
if current_row < len(row_list) - 1:
|
||||||
|
next_ = db.title(row_list[current_row+1])
|
||||||
|
|
||||||
|
d = MetadataSingleDialog(self.gui, row_list[current_row], db,
|
||||||
|
prev=prev, next_=next_)
|
||||||
|
if d.exec_() != d.Accepted:
|
||||||
break
|
break
|
||||||
if rows:
|
changed.add(d.id)
|
||||||
|
if d.row_delta == 0:
|
||||||
|
break
|
||||||
|
current_row += d.row_delta
|
||||||
|
|
||||||
|
if changed:
|
||||||
|
self.gui.library_view.model().refresh_ids(list(changed))
|
||||||
current = self.gui.library_view.currentIndex()
|
current = self.gui.library_view.currentIndex()
|
||||||
m = self.gui.library_view.model()
|
m = self.gui.library_view.model()
|
||||||
if self.gui.cover_flow:
|
if self.gui.cover_flow:
|
||||||
|
@ -7,9 +7,11 @@ add/remove formats
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import os, re, time, traceback, textwrap
|
import os, re, time, traceback, textwrap
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
from PyQt4.Qt import SIGNAL, QObject, Qt, QTimer, QThread, QDate, \
|
from PyQt4.Qt import SIGNAL, QObject, Qt, QTimer, QThread, QDate, \
|
||||||
QPixmap, QListWidgetItem, QDialog, pyqtSignal, QMessageBox
|
QPixmap, QListWidgetItem, QDialog, pyqtSignal, QMessageBox, QIcon, \
|
||||||
|
QPushButton
|
||||||
|
|
||||||
from calibre.gui2 import error_dialog, file_icon_provider, dynamic, \
|
from calibre.gui2 import error_dialog, file_icon_provider, dynamic, \
|
||||||
choose_files, choose_images, ResizableDialog, \
|
choose_files, choose_images, ResizableDialog, \
|
||||||
@ -429,11 +431,8 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
def do_cancel_all(self):
|
def __init__(self, window, row, db, prev=None,
|
||||||
self.cancel_all = True
|
next_=None):
|
||||||
self.reject()
|
|
||||||
|
|
||||||
def __init__(self, window, row, db, accepted_callback=None, cancel_all=False):
|
|
||||||
ResizableDialog.__init__(self, window)
|
ResizableDialog.__init__(self, window)
|
||||||
self.bc_box.layout().setAlignment(self.cover, Qt.AlignCenter|Qt.AlignHCenter)
|
self.bc_box.layout().setAlignment(self.cover, Qt.AlignCenter|Qt.AlignHCenter)
|
||||||
self.cancel_all = False
|
self.cancel_all = False
|
||||||
@ -445,16 +444,27 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
_(' The red color indicates that the current '
|
_(' The red color indicates that the current '
|
||||||
'author sort does not match the current author'))
|
'author sort does not match the current author'))
|
||||||
|
|
||||||
if cancel_all:
|
self.row_delta = 0
|
||||||
self.__abort_button = self.button_box.addButton(self.button_box.Abort)
|
if prev:
|
||||||
self.__abort_button.setToolTip(_('Abort the editing of all remaining books'))
|
self.prev_button = QPushButton(QIcon(I('back.png')), _('Previous'),
|
||||||
self.connect(self.__abort_button, SIGNAL('clicked()'),
|
self)
|
||||||
self.do_cancel_all)
|
self.button_box.addButton(self.prev_button, self.button_box.ActionRole)
|
||||||
|
tip = _('Edit the metadata of %s')%prev
|
||||||
|
self.prev_button.setToolTip(tip)
|
||||||
|
self.prev_button.clicked.connect(partial(self.next_triggered,
|
||||||
|
-1))
|
||||||
|
if next_:
|
||||||
|
self.next_button = QPushButton(QIcon(I('forward.png')), _('Next'),
|
||||||
|
self)
|
||||||
|
self.button_box.addButton(self.next_button, self.button_box.ActionRole)
|
||||||
|
tip = _('Edit the metadata of %s')%next_
|
||||||
|
self.next_button.setToolTip(tip)
|
||||||
|
self.next_button.clicked.connect(partial(self.next_triggered, 1))
|
||||||
|
|
||||||
self.splitter.setStretchFactor(100, 1)
|
self.splitter.setStretchFactor(100, 1)
|
||||||
self.read_state()
|
self.read_state()
|
||||||
self.db = db
|
self.db = db
|
||||||
self.pi = ProgressIndicator(self)
|
self.pi = ProgressIndicator(self)
|
||||||
self.accepted_callback = accepted_callback
|
|
||||||
self.id = db.id(row)
|
self.id = db.id(row)
|
||||||
self.row = row
|
self.row = row
|
||||||
self.cover_data = None
|
self.cover_data = None
|
||||||
@ -801,6 +811,10 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
unicode(self.tags.text()).split(',')],
|
unicode(self.tags.text()).split(',')],
|
||||||
notify=notify, commit=commit)
|
notify=notify, commit=commit)
|
||||||
|
|
||||||
|
def next_triggered(self, row_delta, *args):
|
||||||
|
self.row_delta = row_delta
|
||||||
|
self.accept()
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
cf = getattr(self, 'cover_fetcher', None)
|
cf = getattr(self, 'cover_fetcher', None)
|
||||||
if cf is not None and hasattr(cf, 'terminate'):
|
if cf is not None and hasattr(cf, 'terminate'):
|
||||||
@ -862,8 +876,6 @@ class MetadataSingleDialog(ResizableDialog, Ui_MetadataSingleDialog):
|
|||||||
raise
|
raise
|
||||||
self.save_state()
|
self.save_state()
|
||||||
QDialog.accept(self)
|
QDialog.accept(self)
|
||||||
if callable(self.accepted_callback):
|
|
||||||
self.accepted_callback(self.id)
|
|
||||||
|
|
||||||
def reject(self, *args):
|
def reject(self, *args):
|
||||||
cf = getattr(self, 'cover_fetcher', None)
|
cf = getattr(self, 'cover_fetcher', None)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user