示例#1
0
 def createEditor(self, parent, option, index):
     if self.db and hasattr(self.db, self.items_func_name):
         m = index.model()
         col = m.column_map[index.column()]
         # If shifted, bring up the tag editor instead of the line editor.
         if check_key_modifier(
                 Qt.KeyboardModifier.ShiftModifier) and col != 'authors':
             key = col if m.is_custom_column(col) else None
             d = TagEditor(parent, self.db, m.id(index.row()), key=key)
             if d.exec() == QDialog.DialogCode.Accepted:
                 m.setData(index, self.sep.join(d.tags),
                           Qt.ItemDataRole.EditRole)
             return None
         editor = EditWithComplete(parent)
         if col == 'tags':
             editor.set_elide_mode(Qt.TextElideMode.ElideMiddle)
         editor.set_separator(self.sep)
         editor.set_clear_button_enabled(False)
         editor.set_space_before_sep(self.space_before_sep)
         if self.sep == '&':
             editor.set_add_separator(
                 tweaks['authors_completer_append_separator'])
         if not m.is_custom_column(col):
             all_items = getattr(self.db, self.items_func_name)()
         else:
             all_items = list(
                 self.db.all_custom(
                     label=self.db.field_metadata.key_to_label(col)))
         editor.update_items_cache(all_items)
     else:
         editor = EnLineEdit(parent)
     return editor
示例#2
0
 def edit_tags(self):
     from calibre.gui2.dialogs.tag_editor import TagEditor
     d = TagEditor(
         self,
         get_gui().current_db,
         current_tags=list(
             filter(None,
                    [x.strip() for x in self.query.text().split(',')])))
     if d.exec() == QDialog.DialogCode.Accepted:
         self.query.setText(', '.join(d.tags))