View Single Post
Old 02-13-2022, 12:09 PM   #829
capink
Wizard
capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.capink ought to be getting tired of karma fortunes by now.
 
Posts: 1,203
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
I don't totally get what you want to do. but if you want to get the number of books resulting from search, you can utilize the from_search function in a template as follows:

Code:
program:
	book_ids = from_search('id', 'enter_you_search_here');
	number_of_books = count(book_ids, ',')
If, for some reason, you want to get the search string from calibre's search box, you have to define a new custom template function, by copying the code below (Action Chains > Manage Modules > Create Module > copy/paste):

Code:
from calibre_plugins.action_chains.templates import TemplateFunction

class CurrentSearch(TemplateFunction):
    name = 'current_search'
    arg_count = 0

    def evaluate(self, formatter, kwargs, mi, locals):
        from calibre.gui2.ui import get_gui
        gui = get_gui()
        if gui:
            return gui.search.text()
        return _('This function can be used only in the GUI')
Now, you can use the above template function to get the search string as follows:

Code:
program:
    search_string = current_search()
capink is offline   Reply With Quote