def is_category(field): from calibre.db.categories import find_categories from calibre.gui2.ui import get_gui gui = get_gui() fm = gui.current_db.field_metadata return field in { x[0] for x in find_categories(fm) if fm.is_custom_field(x[0]) }
def populate_tb_manage_menu(self, db): from calibre.db.categories import find_categories m = self.alter_tb.manage_menu m.clear() for text, func, args, cat_name in ((_('Manage Authors'), self.do_author_sort_edit, (self, None), 'authors'), (_('Manage Series'), self.do_tags_list_edit, (None, 'series'), 'series'), (_('Manage Publishers'), self.do_tags_list_edit, (None, 'publisher'), 'publisher'), (_('Manage Tags'), self.do_tags_list_edit, (None, 'tags'), 'tags'), (_('Manage User Categories'), self.do_edit_user_categories, (None, ), 'user:'******'Manage Saved Searches'), self.do_saved_search_edit, (None, ), 'search')): m.addAction(QIcon(I(category_icon_map[cat_name])), text, partial(func, *args)) fm = db.new_api.field_metadata categories = [ x[0] for x in find_categories(fm) if fm.is_custom_field(x[0]) ] if categories: if len(categories) > 5: m = m.addMenu(_('Custom columns')) else: m.addSeparator() def cat_key(x): try: return fm[x]['name'] except Exception: return '' for cat in sorted(categories, key=cat_key): name = cat_key(cat) if name: m.addAction( _('Manage {}').format(name), partial(self.do_tags_list_edit, None, cat))
def populate_tb_manage_menu(self, db): from calibre.db.categories import find_categories m = self.alter_tb.manage_menu m.clear() for text, func, args, cat_name in ( (_('Manage Authors'), self.do_author_sort_edit, (self, None), 'authors'), (_('Manage Series'), self.do_tags_list_edit, (None, 'series'), 'series'), (_('Manage Publishers'), self.do_tags_list_edit, (None, 'publisher'), 'publisher'), (_('Manage Tags'), self.do_tags_list_edit, (None, 'tags'), 'tags'), (_('Manage User Categories'), self.do_edit_user_categories, (None,), 'user:'******'Manage Saved Searches'), self.do_saved_search_edit, (None,), 'search') ): m.addAction(QIcon(I(category_icon_map[cat_name])), text, partial(func, *args)) fm = db.new_api.field_metadata categories = [x[0] for x in find_categories(fm) if fm.is_custom_field(x[0])] if categories: if len(categories) > 5: m = m.addMenu(_('Custom columns')) else: m.addSeparator() def cat_key(x): try: return fm[x]['name'] except Exception: return '' for cat in sorted(categories, key=cat_key): name = cat_key(cat) if name: m.addAction(_('Manage {}').format(name), partial(self.do_tags_list_edit, None, cat))
def is_category(field): from calibre.db.categories import find_categories from calibre.gui2.ui import get_gui gui = get_gui() fm = gui.current_db.field_metadata return field in {x[0] for x in find_categories(fm) if fm.is_custom_field(x[0])}
def genesis(self, gui): self.gui = gui db = gui.library_view.model().db self.db = db r = self.register r('search_as_you_type', config) r('highlight_search_matches', config) r('show_highlight_toggle_button', gprefs) r('limit_search_columns', prefs) r('use_primary_find_in_search', prefs) r('case_sensitive', prefs) fl = db.field_metadata.get_search_terms() r('limit_search_columns_to', prefs, setting=CommaSeparatedList, choices=fl) self.clear_history_button.clicked.connect(self.clear_histories) self.gst_explanation.setText('<p>' + _( "<b>Grouped search terms</b> are search names that permit a query to automatically " "search across more than one column. For example, if you create a grouped " "search term <code>allseries</code> with the value " "<code>series, #myseries, #myseries2</code>, then " "the query <code>allseries:adhoc</code> will find 'adhoc' in any of the " "columns <code>series</code>, <code>#myseries</code>, and " "<code>#myseries2</code>.<p> Enter the name of the " "grouped search term in the drop-down box, enter the list of columns " "to search in the value box, then push the Save button. " "<p>Note: Search terms are forced to lower case; <code>MySearch</code> " "and <code>mysearch</code> are the same term." "<p>You can have your grouped search term show up as User categories in " " the Tag browser. Just add the grouped search term names to the Make User " "categories from box. You can add multiple terms separated by commas. " "The new User category will be automatically " "populated with all the items in the categories included in the grouped " "search term. <p>Automatic User categories permit you to see easily " "all the category items that " "are in the columns contained in the grouped search term. Using the above " "<code>allseries</code> example, the automatically-generated User category " "will contain all the series mentioned in <code>series</code>, " "<code>#myseries</code>, and <code>#myseries2</code>. This " "can be useful to check for duplicates, to find which column contains " "a particular item, or to have hierarchical categories (categories " "that contain categories).")) self.gst = db.prefs.get('grouped_search_terms', {}).copy() self.orig_gst_keys = list(self.gst.keys()) fm = db.new_api.field_metadata categories = [ x[0] for x in find_categories(fm) if fm[x[0]]['search_terms'] ] self.gst_value.update_items_cache(categories) QTimer.singleShot(0, self.fill_gst_box) self.user_category_layout.setContentsMargins(0, 30, 0, 0) self.gst_names.lineEdit().setPlaceholderText( _('Enter new or select existing name')) self.gst_value.lineEdit().setPlaceholderText( _('Enter list of column lookup names to search')) self.category_fields = fl ml = [(_('Match any'), 'match_any'), (_('Match all'), 'match_all')] r('similar_authors_match_kind', db.prefs, choices=ml) r('similar_tags_match_kind', db.prefs, choices=ml) r('similar_series_match_kind', db.prefs, choices=ml) r('similar_publisher_match_kind', db.prefs, choices=ml) self.set_similar_fields(initial=True) self.similar_authors_search_key.currentIndexChanged[int].connect( self.something_changed) self.similar_tags_search_key.currentIndexChanged[int].connect( self.something_changed) self.similar_series_search_key.currentIndexChanged[int].connect( self.something_changed) self.similar_publisher_search_key.currentIndexChanged[int].connect( self.something_changed) self.gst_delete_button.setEnabled(False) self.gst_save_button.setEnabled(False) self.gst_names.currentIndexChanged[int].connect(self.gst_index_changed) self.gst_names.editTextChanged.connect(self.gst_text_changed) self.gst_value.textChanged.connect(self.gst_text_changed) self.gst_save_button.clicked.connect(self.gst_save_clicked) self.gst_delete_button.clicked.connect(self.gst_delete_clicked) self.gst_changed = False if db.prefs.get('grouped_search_make_user_categories', None) is None: db.new_api.set_pref('grouped_search_make_user_categories', []) r('grouped_search_make_user_categories', db.prefs, setting=CommaSeparatedList) self.muc_changed = False self.opt_grouped_search_make_user_categories.lineEdit( ).editingFinished.connect(self.muc_box_changed)