mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
commit
57f0060bfa
@ -317,9 +317,7 @@ class Text(Base):
|
|||||||
if self.sep['ui_to_list'] == '&':
|
if self.sep['ui_to_list'] == '&':
|
||||||
w.set_space_before_sep(True)
|
w.set_space_before_sep(True)
|
||||||
w.set_add_separator(tweaks['authors_completer_append_separator'])
|
w.set_add_separator(tweaks['authors_completer_append_separator'])
|
||||||
w.get_editor_button().setVisible(False)
|
w.get_editor_button().clicked.connect(self.edit)
|
||||||
else:
|
|
||||||
w.get_editor_button().clicked.connect(self.edit)
|
|
||||||
w.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)
|
w.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Preferred)
|
||||||
else:
|
else:
|
||||||
w = EditWithComplete(parent)
|
w = EditWithComplete(parent)
|
||||||
|
@ -3,7 +3,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
|||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from PyQt5.Qt import Qt, QDialog
|
from PyQt5.Qt import Qt, QDialog, QAbstractItemView
|
||||||
|
|
||||||
from calibre.gui2.dialogs.tag_editor_ui import Ui_TagEditor
|
from calibre.gui2.dialogs.tag_editor_ui import Ui_TagEditor
|
||||||
from calibre.gui2 import question_dialog, error_dialog, gprefs
|
from calibre.gui2 import question_dialog, error_dialog, gprefs
|
||||||
@ -18,7 +18,15 @@ class TagEditor(QDialog, Ui_TagEditor):
|
|||||||
self.setupUi(self)
|
self.setupUi(self)
|
||||||
|
|
||||||
self.db = db
|
self.db = db
|
||||||
|
self.sep = ','
|
||||||
|
self.is_names = False
|
||||||
if key:
|
if key:
|
||||||
|
# Assume that if given a key then it is a custom column
|
||||||
|
try:
|
||||||
|
self.is_names = db.field_metadata[key]['display'].get('is_names', False)
|
||||||
|
self.sep = '&'
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
key = db.field_metadata.key_to_label(key)
|
key = db.field_metadata.key_to_label(key)
|
||||||
self.key = key
|
self.key = key
|
||||||
self.index = db.row(id_) if id_ is not None else None
|
self.index = db.row(id_) if id_ is not None else None
|
||||||
@ -32,13 +40,16 @@ class TagEditor(QDialog, Ui_TagEditor):
|
|||||||
else:
|
else:
|
||||||
tags = []
|
tags = []
|
||||||
if tags:
|
if tags:
|
||||||
tags.sort(key=sort_key)
|
if not self.is_names:
|
||||||
|
tags.sort(key=sort_key)
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
self.applied_tags.addItem(tag)
|
self.applied_tags.addItem(tag)
|
||||||
else:
|
else:
|
||||||
tags = []
|
tags = []
|
||||||
|
|
||||||
self.tags = tags
|
if self.is_names:
|
||||||
|
self.applied_tags.setDragDropMode(QAbstractItemView.InternalMove)
|
||||||
|
self.applied_tags.setSelectionMode(QAbstractItemView.ExtendedSelection)
|
||||||
|
|
||||||
if key:
|
if key:
|
||||||
all_tags = [tag for tag in self.db.all_custom(label=key)]
|
all_tags = [tag for tag in self.db.all_custom(label=key)]
|
||||||
@ -108,14 +119,16 @@ class TagEditor(QDialog, Ui_TagEditor):
|
|||||||
items = self.available_tags.selectedItems() if item is None else [item]
|
items = self.available_tags.selectedItems() if item is None else [item]
|
||||||
rows = [self.available_tags.row(i) for i in items]
|
rows = [self.available_tags.row(i) for i in items]
|
||||||
row = max(rows)
|
row = max(rows)
|
||||||
|
tags = self._get_applied_tags_box_contents()
|
||||||
for item in items:
|
for item in items:
|
||||||
tag = unicode(item.text())
|
tag = unicode(item.text())
|
||||||
self.tags.append(tag)
|
tags.append(tag)
|
||||||
self.available_tags.takeItem(self.available_tags.row(item))
|
self.available_tags.takeItem(self.available_tags.row(item))
|
||||||
|
|
||||||
self.tags.sort(key=sort_key)
|
if not self.is_names:
|
||||||
|
tags.sort(key=sort_key)
|
||||||
self.applied_tags.clear()
|
self.applied_tags.clear()
|
||||||
for tag in self.tags:
|
for tag in tags:
|
||||||
self.applied_tags.addItem(tag)
|
self.applied_tags.addItem(tag)
|
||||||
|
|
||||||
if row >= self.available_tags.count():
|
if row >= self.available_tags.count():
|
||||||
@ -128,16 +141,24 @@ class TagEditor(QDialog, Ui_TagEditor):
|
|||||||
# use the filter again when the applied tags were changed
|
# use the filter again when the applied tags were changed
|
||||||
self.filter_tags(self.applied_filter_input.text(), which='applied_tags')
|
self.filter_tags(self.applied_filter_input.text(), which='applied_tags')
|
||||||
|
|
||||||
|
def _get_applied_tags_box_contents(self):
|
||||||
|
tags = []
|
||||||
|
for i in range(0, self.applied_tags.count()):
|
||||||
|
tags.append(unicode(self.applied_tags.item(i).text()))
|
||||||
|
return tags
|
||||||
|
|
||||||
def unapply_tags(self, item=None):
|
def unapply_tags(self, item=None):
|
||||||
|
tags = self._get_applied_tags_box_contents()
|
||||||
items = self.applied_tags.selectedItems() if item is None else [item]
|
items = self.applied_tags.selectedItems() if item is None else [item]
|
||||||
for item in items:
|
for item in items:
|
||||||
tag = unicode(item.text())
|
tag = unicode(item.text())
|
||||||
self.tags.remove(tag)
|
tags.remove(tag)
|
||||||
self.available_tags.addItem(tag)
|
self.available_tags.addItem(tag)
|
||||||
|
|
||||||
self.tags.sort(key=sort_key)
|
if not self.is_names:
|
||||||
|
tags.sort(key=sort_key)
|
||||||
self.applied_tags.clear()
|
self.applied_tags.clear()
|
||||||
for tag in self.tags:
|
for tag in tags:
|
||||||
self.applied_tags.addItem(tag)
|
self.applied_tags.addItem(tag)
|
||||||
|
|
||||||
items = [unicode(self.available_tags.item(x).text()) for x in
|
items = [unicode(self.available_tags.item(x).text()) for x in
|
||||||
@ -152,19 +173,21 @@ class TagEditor(QDialog, Ui_TagEditor):
|
|||||||
self.filter_tags(self.available_filter_input.text())
|
self.filter_tags(self.available_filter_input.text())
|
||||||
|
|
||||||
def add_tag(self):
|
def add_tag(self):
|
||||||
tags = unicode(self.add_tag_input.text()).split(',')
|
tags = unicode(self.add_tag_input.text()).split(self.sep)
|
||||||
|
tags_in_box = self._get_applied_tags_box_contents()
|
||||||
for tag in tags:
|
for tag in tags:
|
||||||
tag = tag.strip()
|
tag = tag.strip()
|
||||||
if not tag:
|
if not tag:
|
||||||
continue
|
continue
|
||||||
for item in self.available_tags.findItems(tag, Qt.MatchFixedString):
|
for item in self.available_tags.findItems(tag, Qt.MatchFixedString):
|
||||||
self.available_tags.takeItem(self.available_tags.row(item))
|
self.available_tags.takeItem(self.available_tags.row(item))
|
||||||
if tag not in self.tags:
|
if tag not in tags_in_box:
|
||||||
self.tags.append(tag)
|
tags_in_box.append(tag)
|
||||||
|
|
||||||
self.tags.sort(key=sort_key)
|
if not self.is_names:
|
||||||
|
tags_in_box.sort(key=sort_key)
|
||||||
self.applied_tags.clear()
|
self.applied_tags.clear()
|
||||||
for tag in self.tags:
|
for tag in tags_in_box:
|
||||||
self.applied_tags.addItem(tag)
|
self.applied_tags.addItem(tag)
|
||||||
|
|
||||||
self.add_tag_input.setText('')
|
self.add_tag_input.setText('')
|
||||||
@ -180,6 +203,7 @@ class TagEditor(QDialog, Ui_TagEditor):
|
|||||||
item.setHidden(bool(q and not primary_contains(q, unicode(item.text()))))
|
item.setHidden(bool(q and not primary_contains(q, unicode(item.text()))))
|
||||||
|
|
||||||
def accept(self):
|
def accept(self):
|
||||||
|
self.tags = self._get_applied_tags_box_contents()
|
||||||
self.save_state()
|
self.save_state()
|
||||||
return QDialog.accept(self)
|
return QDialog.accept(self)
|
||||||
|
|
||||||
@ -189,3 +213,11 @@ class TagEditor(QDialog, Ui_TagEditor):
|
|||||||
|
|
||||||
def save_state(self):
|
def save_state(self):
|
||||||
gprefs['tag_editor_geometry'] = bytearray(self.saveGeometry())
|
gprefs['tag_editor_geometry'] = bytearray(self.saveGeometry())
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
from calibre.gui2 import Application
|
||||||
|
from calibre.library import db
|
||||||
|
db = db()
|
||||||
|
app = Application([])
|
||||||
|
d = TagEditor(None, db, key='#authors', id_=tuple(db.new_api.all_book_ids())[0])
|
||||||
|
d.exec_()
|
||||||
|
@ -2,8 +2,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
from PyQt5.Qt import (Qt, QDialog, QTableWidgetItem, QIcon, QByteArray, QSize,
|
from PyQt5.Qt import (Qt, QDialog, QTableWidgetItem, QIcon, QByteArray, QSize,
|
||||||
QDialogButtonBox, QTableWidget, QObject, pyqtSignal,
|
QDialogButtonBox, QTableWidget, QItemDelegate)
|
||||||
QEvent, QItemDelegate)
|
|
||||||
|
|
||||||
from calibre.gui2.dialogs.tag_list_editor_ui import Ui_TagListEditor
|
from calibre.gui2.dialogs.tag_list_editor_ui import Ui_TagListEditor
|
||||||
from calibre.gui2.dialogs.confirm_delete import confirm
|
from calibre.gui2.dialogs.confirm_delete import confirm
|
||||||
@ -89,7 +88,7 @@ class EditColumnDelegate(QItemDelegate):
|
|||||||
return QItemDelegate.createEditor(self, parent, option, index)
|
return QItemDelegate.createEditor(self, parent, option, index)
|
||||||
if not confirm(
|
if not confirm(
|
||||||
_('Do you want to undo your changes?'),
|
_('Do you want to undo your changes?'),
|
||||||
'tag_list_editor_undo'):
|
'tag_list_editor_undo'):
|
||||||
return
|
return
|
||||||
item.setText(item.initial_text())
|
item.setText(item.initial_text())
|
||||||
self.table.blockSignals(True)
|
self.table.blockSignals(True)
|
||||||
@ -274,7 +273,7 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
error_dialog(self, _('No item selected'),
|
error_dialog(self, _('No item selected'),
|
||||||
_('You must select one item from the list of Available items.')).exec_()
|
_('You must select one item from the list of Available items.')).exec_()
|
||||||
return
|
return
|
||||||
col_zero_item = self.table.item(item.row(), 0);
|
col_zero_item = self.table.item(item.row(), 0)
|
||||||
if col_zero_item.is_deleted:
|
if col_zero_item.is_deleted:
|
||||||
if not question_dialog(self, _('Undelete item?'),
|
if not question_dialog(self, _('Undelete item?'),
|
||||||
'<p>'+_('That item is deleted. Do you want to undelete it?')+'<br>'):
|
'<p>'+_('That item is deleted. Do you want to undelete it?')+'<br>'):
|
||||||
@ -306,13 +305,13 @@ class TagListEditor(QDialog, Ui_TagListEditor):
|
|||||||
ct = ', '.join([unicode(item.text()) for item in to_del])
|
ct = ', '.join([unicode(item.text()) for item in to_del])
|
||||||
if not confirm(
|
if not confirm(
|
||||||
'<p>'+_('Are you sure you want to delete the following items?')+'<br>'+ct,
|
'<p>'+_('Are you sure you want to delete the following items?')+'<br>'+ct,
|
||||||
'tag_list_editor_delete'):
|
'tag_list_editor_delete'):
|
||||||
return
|
return
|
||||||
if to_undel:
|
if to_undel:
|
||||||
ct = ', '.join([unicode(item.text()) for item in to_undel])
|
ct = ', '.join([unicode(item.text()) for item in to_undel])
|
||||||
if not confirm(
|
if not confirm(
|
||||||
'<p>'+_('Are you sure you want to undelete the following items?')+'<br>'+ct,
|
'<p>'+_('Are you sure you want to undelete the following items?')+'<br>'+ct,
|
||||||
'tag_list_editor_undelete'):
|
'tag_list_editor_undelete'):
|
||||||
return
|
return
|
||||||
row = self.table.row(deletes[0])
|
row = self.table.row(deletes[0])
|
||||||
for item in deletes:
|
for item in deletes:
|
||||||
|
@ -311,8 +311,7 @@ class CompleteDelegate(QStyledItemDelegate, UpdateEditorGeometry): # {{{
|
|||||||
m = index.model()
|
m = index.model()
|
||||||
col = m.column_map[index.column()]
|
col = m.column_map[index.column()]
|
||||||
# If shifted, bring up the tag editor instead of the line editor.
|
# If shifted, bring up the tag editor instead of the line editor.
|
||||||
# Don't do this for people-name columns because order will be lost
|
if QApplication.keyboardModifiers() == Qt.ShiftModifier and col != 'authors':
|
||||||
if QApplication.keyboardModifiers() == Qt.ShiftModifier and self.sep == ',':
|
|
||||||
key = col if m.is_custom_column(col) else None
|
key = col if m.is_custom_column(col) else None
|
||||||
d = TagEditor(parent, self.db, m.id(index.row()), key=key)
|
d = TagEditor(parent, self.db, m.id(index.row()), key=key)
|
||||||
if d.exec_() == TagEditor.Accepted:
|
if d.exec_() == TagEditor.Accepted:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user