Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Plugins

Notices

Reply
 
Thread Tools Search this Thread
Old Today, 03:39 AM   #1531
un_pogaz
Chalut o/
un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.
 
un_pogaz's Avatar
 
Posts: 451
Karma: 678910
Join Date: Dec 2017
Device: Kobo
Quote:
Originally Posted by ownedbycats View Post
Some of the actions have conditionals (for example, run Extract ISBN only if book has no existing ISBN identifier). It doesn't quite work right when some book matches conditionals and others don't.
Yeah, I enconter the same problem. It's really confusing to see that the condition depends exclusively on the exact book wich on you open the Action Chains context menu (or the last/first selected) to check the execution conditions, instead of acting as a filter.
If this book matches the condition, the action will be performed on all selected books, even those that do not match and on which you did not want to perform this action.

And I don't think a real filter feature would be possible, because Action Chains often uses the selected books to retrive the id to perform their own action, so it real not depending of Action Chains that the Calibre actions are all or nothing. A real filter feature would involve deselecting and selecting dynamically wich rows is needed before run the Calibre actions, then redo that at each step of the chain.
... I think it's possible (Calibre is powerfull like that), but it would be terribly complicated, so I will give it no hope.

Last edited by un_pogaz; Today at 05:38 AM.
un_pogaz is offline   Reply With Quote
Old Today, 04:29 AM   #1532
un_pogaz
Chalut o/
un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.
 
un_pogaz's Avatar
 
Posts: 451
Karma: 678910
Join Date: Dec 2017
Device: Kobo
Okay. By checking the code, I found a possible way.

`gui.current_view().get_selected_ids()` allow to retrive the book id of the selected row, and `gui.current_view().select_rows()` allow to select the book base on their id `class calibre.gui2.library.views.BooksView. Additionaly, using this two function allow to mimic and preserve the selection order.

Beside @capink, get_selected_ids() it probably a better ways to retrive the book id than you current way.
Damn it, if you had GitHub or similiar, I could work on proposing a patch, to either transform the condition on a true filter, or add a new filter feature.
I'll see what I can do, but it won't be as clean to share you the full files like that.

Last edited by un_pogaz; Today at 05:40 AM.
un_pogaz is offline   Reply With Quote
Old Today, 07:26 AM   #1533
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,205
Karma: 1995558
Join Date: Aug 2015
Device: Kindle
Quote:
Originally Posted by ownedbycats View Post
Some of the actions have conditionals (for example, run Extract ISBN only if book has no existing ISBN identifier). It doesn't quite work right when some book matches conditionals and others don't.


Quote:
Originally Posted by un_pogaz View Post
I could work on proposing a patch, to either transform the condition on a true filter, or add a new filter feature.
I'll see what I can do, but it won't be as clean to share you the full files like that.
This issue and the solution for it has been addressed before. As you can see in the linked post, you can easily modify the selection (into a subset of the already selected books) based on whatever criteria you want. Conditions were intended as a quick way to determine whether a chain/action will run based on simple criteria that does not take much time to run, because chain conditions are executed every time the Action Chains menu is dynamically created. Any more additional criteria can be done as illustrated in the linked post.

The solution in the post even allows for saving the initial selection into a variable, so that you can restore them mid-chain if you want, and allow for more flexible control.
capink is offline   Reply With Quote
Old Today, 09:59 AM   #1534
un_pogaz
Chalut o/
un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.
 
un_pogaz's Avatar
 
Posts: 451
Karma: 678910
Join Date: Dec 2017
Device: Kobo
Interesing, but I think that a formal implementation of a filter system would be a big plus, certainly with its own column/settings.
Also, if I understand your idea of wanting to dynamically display the menu entry based on simple condition criteria and so limit this to a single metadata object for performance reason, I think that inside the chains themselves, this is too confusive. It's certainly too late to replace this column with a proper filter setting, but in any case, I really encourage the addition of such thing.

Else, I worked of the idea and so here my proposal:
Spoiler:

in class chains.Chain._run_loop()

somewhere at the start
Code:
# store selected books at the start of the chains
self.chain_selected_ids = self.gui.current_view().get_selected_ids()
self.previous_selected_ids = self.chain_selected_ids
after
Code:
do_run = self.check_action_conditions(chain_link.get('condition_settings', {}))
append
Code:
# filtre the book for running action
filter_settings = chain_link.get('filter_settings', {})
if not filter_settings.get('template'):
    # No conditions set, use all selected ids
    action_selected_ids = self.chain_selected_ids
else:
    action_selected_ids = []
    for book_id in self.chain_selected_ids:
        mi = self.db.new_api.get_proxy_metadata(book_id)
        if self.check_conditions(filter_settings, mi=mi):
            action_selected_ids.append(book_id)

# action_selected_ids can only contain a subset of chain_selected_ids
# don't perform a new select_rows() if the previous seletion was the same than chain_selected_ids
if len(action_selected_ids) != len(self.chain_selected_ids) or len(self.previous_selected_ids) != len(self.chain_selected_ids):
    # change_current=True because the previous current_row can probaly not match the conditions
    # and so the validate() function can fail and abort the action
    self.gui.current_view().select_rows(action_selected_ids, change_current=True, scroll=False)
self.previous_selected_ids = action_selected_ids
and to insert in the finaly block
Code:
# full reset seleted books
if len(self.previous_selected_ids) != len(self.chain_selected_ids):
    self.gui.current_view().select_rows(self.chain_selected_ids, change_current=True, scroll=False)
un_pogaz is offline   Reply With Quote
Old Today, 10:13 AM   #1535
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,501
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by un_pogaz View Post
Else, I worked of the idea and so here my proposal:
[/SPOILER]
FWIW: I'm currently implementing these changes to the base formatter.
  • ids = selected_books()
  • name = selected_cell(). Returns the lookup name.
  • A 'with' statement that changes the book the template is using for the statement's block. The same local variables are available to the inner and outer block.
Example:
Code:
program: 
	ids = selected_books();
	col = selected_column();
	res = '';
	for id in ids:
		with id:
			# prints information from the book with identifier 'id'
			print($title, field(col));
			res = (if res then res & ',' fi) & field(col);
			template('program: print("inside template", $title)')
		htiw
	rof;
	list_remove_duplicates(res, ',')
Internal template functions and stored templates called from inside the 'with' block use the book with id 'id'.

EDIT: I'm also going to implement "show_in_dialog()" that renders an html string.

Last edited by chaley; Today at 10:17 AM.
chaley is offline   Reply With Quote
Old Today, 02:45 PM   #1536
un_pogaz
Chalut o/
un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.un_pogaz ought to be getting tired of karma fortunes by now.
 
un_pogaz's Avatar
 
Posts: 451
Karma: 678910
Join Date: Dec 2017
Device: Kobo
Quote:
Originally Posted by chaley View Post
FWIW: I'm currently implementing these changes to the base formatter.
  • ids = selected_books()
  • name = selected_cell(). Returns the lookup name.
  • A 'with' statement that changes the book the template is using for the statement's block. The same local variables are available to the inner and outer block.

EDIT: I'm also going to implement "show_in_dialog()" that renders an html string.
Oh, it would be inded quite usefull to test all the selected books inside the singular Template call of the condition settings. But that dosn't solve the issue to perform some actions only on a specific subset on seleted books.

Else, if retrive the seleted book ids is good, I think it would be much more useful to have a function 'search_books()' that use the search syntax.
Code:
ids = search_books('series:"='&field('series')&'"')

rlst = ''
for id in ids:
	with id:
		rlst = rlst & character('newline') & $title
	htiw;
rof;
show_in_dialog(rlst) # show all the books in a series
And let's even be bold, adding a 'all_ids_books()', that way, we can run the entire library.
(this two function would also greatly benefit to have a optional argument virtual libray)

Damn, it will make the GPM incredible powerfull, able to execute an return big data for a one of execution. Python template are great, but GPM is much simpler and enough for 90% of case, and the 'with' statement will make it a "complet" language in a some way.
But now that I think about it, I don't think the template editor is designed for that kind use, since it executes the code at each edit... it would become a hell to creat such things. So in addition, I think it would be useful to add a new mode that only executes code on demand.
Nevermind, their is the Breakpoints mode that already do that, Yes.
(however, you must not select such stored template without the Breakpoints mode enable, else your cooked)

Last edited by un_pogaz; Today at 02:50 PM.
un_pogaz is offline   Reply With Quote
Old Today, 06:35 PM   #1537
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,501
Karma: 8065348
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by un_pogaz View Post
Else, if retrive the seleted book ids is good, I think it would be much more useful to have a function 'search_books()' that use the search syntax.
Code:
ids = search_books('series:"='&field('series')&'"')

rlst = ''
for id in ids:
	with id:
		rlst = rlst & character('newline') & $title
	htiw;
rof;
show_in_dialog(rlst) # show all the books in a series
Use the function book_values(), as in
Code:
ids = book_values('id', 'series:"=' & field('series') & '"', ',', '0')
Quote:
And let's even be bold, adding a 'all_ids_books()', that way, we can run the entire library.
Use this. The null search expression matches everything.
Code:
ids = book_values('id', '', ',', '0')
Quote:
(this two function would also greatly benefit to have a optional argument virtual libray)
The fourth parameter tells book_values() whether or not to use the current VL. If you want to use an arbitrary VL then put it in the search expression. For example, this expression returns the ids of all the books in the 'foo' VL:
Code:
ids = book_values(id, 'vl:foo', ',', '0')
Quote:
But now that I think about it, I don't think the template editor is designed for that kind use, since it executes the code at each edit... it would become a hell to creat such things. So in addition, I think it would be useful to add a new mode that only executes code on demand.
Nevermind, their is the Breakpoints mode that already do that, Yes.
(however, you must not select such stored template without the Breakpoints mode enable, else your cooked)
Yes, editing a template without breakpoints enabled is painful. I always have it on even when I'm not actually using breakpoints.

NB: I'm also adding a way to execute the template tester where it doesn't run the template for all the selected books, ignoring all but the first book. This helps develop and use templates that iterate over selected ids, generating reports.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Action Chains Resources capink Plugins 78 08-05-2025 04:01 AM
[Editor Plugin] Editor Chains capink Plugins 106 06-17-2025 05:36 PM
[GUI Plugin] Noosfere_util, a companion plugin to noosfere DB lrpirlet Plugins 2 08-18-2022 03:15 PM
[GUI Plugin] Save Virtual Libraries To Column (GUI) chaley Plugins 14 04-04-2021 05:25 AM


All times are GMT -4. The time now is 07:28 PM.


MobileRead.com is a privately owned, operated and funded community.