mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Metadata review dialog: Automatically insert series number when selecting a series from the completion dropdown. Also if the user does not specify a series number, use 1 as the default, instead of not setting the series. See #1404692 (Allow to create new series via 'Review downloaded metadata' dialog)
This commit is contained in:
parent
cd333e17dd
commit
8ba9e10afa
@ -290,6 +290,7 @@ class LineEdit(QLineEdit, LineEditECM):
|
||||
A call to self.set_separator(None) will allow this widget to be used
|
||||
to complete non multiple fields as well.
|
||||
'''
|
||||
item_selected = pyqtSignal(object)
|
||||
|
||||
def __init__(self, parent=None, completer_widget=None, sort_func=sort_key):
|
||||
QLineEdit.__init__(self, parent)
|
||||
@ -407,12 +408,16 @@ class LineEdit(QLineEdit, LineEditECM):
|
||||
before_text, after_text = self.get_completed_text(unicode(text))
|
||||
self.setText(before_text + after_text)
|
||||
self.setCursorPosition(len(before_text))
|
||||
self.item_selected.emit(text)
|
||||
|
||||
class EditWithComplete(EnComboBox):
|
||||
|
||||
item_selected = pyqtSignal(object)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
EnComboBox.__init__(self, *args)
|
||||
self.setLineEdit(LineEdit(self, completer_widget=self, sort_func=kwargs.get('sort_func', sort_key)))
|
||||
self.lineEdit().item_selected.connect(self.item_selected)
|
||||
self.setCompleter(None)
|
||||
self.eat_focus_out = True
|
||||
self.installEventFilter(self)
|
||||
|
@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
|
||||
__license__ = 'GPL v3'
|
||||
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||
|
||||
import os
|
||||
import os, weakref
|
||||
from collections import OrderedDict, namedtuple
|
||||
from functools import partial
|
||||
from future_builtins import zip
|
||||
@ -18,7 +18,7 @@ from PyQt5.Qt import (
|
||||
QKeySequence, QAction, QMenu)
|
||||
|
||||
from calibre import fit_image
|
||||
from calibre.ebooks.metadata import title_sort, authors_to_sort_string
|
||||
from calibre.ebooks.metadata import title_sort, authors_to_sort_string, fmt_sidx
|
||||
from calibre.gui2 import pixmap_to_data, gprefs
|
||||
from calibre.gui2.complete2 import LineEdit as EditWithComplete
|
||||
from calibre.gui2.comments_editor import Editor
|
||||
@ -193,6 +193,11 @@ class DateEdit(PubdateEdit):
|
||||
|
||||
class SeriesEdit(LineEdit):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
LineEdit.__init__(self, *args, **kwargs)
|
||||
self.dbref = None
|
||||
self.item_selected.connect(self.insert_series_index)
|
||||
|
||||
def from_mi(self, mi):
|
||||
series = mi.get(self.field, default='')
|
||||
series_index = mi.get(self.field + '_index', default=1.0)
|
||||
@ -208,10 +213,21 @@ class SeriesEdit(LineEdit):
|
||||
series_index = float(val.rpartition('[')[-1].rstrip(']').strip())
|
||||
except:
|
||||
series_index = 1.0
|
||||
series = val.rpartition('[')[0].strip() or None
|
||||
series = val.rpartition('[')[0].strip() or val.rpartition('[')[-1].strip() or None
|
||||
mi.set(self.field, series)
|
||||
mi.set(self.field + '_index', series_index)
|
||||
|
||||
def set_db(self, db):
|
||||
self.dbref = weakref.ref(db)
|
||||
|
||||
def insert_series_index(self, series):
|
||||
db = self.dbref()
|
||||
if db is None or not series:
|
||||
return
|
||||
num = db.get_next_series_num_for(series)
|
||||
sidx = fmt_sidx(num)
|
||||
self.setText(self.text() + ' [%s]' % sidx)
|
||||
|
||||
class IdentifiersEdit(LineEdit):
|
||||
|
||||
def from_mi(self, mi):
|
||||
@ -410,6 +426,8 @@ class CompareSingle(QWidget):
|
||||
neww.update_items_cache(db.new_api.all_field_names(field))
|
||||
except ValueError:
|
||||
pass # A one-one field like title
|
||||
if isinstance(neww, SeriesEdit):
|
||||
neww.set_db(db.new_api)
|
||||
oldw = cls(field, False, self, m, extra)
|
||||
newl = QLabel('&%s:' % m['name'])
|
||||
newl.setBuddy(neww)
|
||||
|
Loading…
x
Reference in New Issue
Block a user