Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 04-03-2023, 12:57 PM   #556
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Out of curiosity, is Action Chains single-field edit the only method for updating a non-composite field from a template?
ownedbycats is online now   Reply With Quote
Old 04-03-2023, 01:37 PM   #557
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,459
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Out of curiosity, is Action Chains single-field edit the only method for updating a non-composite field from a template?
No, although it might be the best option depending on what sort of changes you are making. You can use Edit Metadata Bulk S&R with the source as a template. If you are brave you can the template tester with Python templates, although you will need to tell the GUI about the changes -- reseting the tag browser, cleaning up user categories, and refreshing the book list.
chaley is offline   Reply With Quote
Old 04-03-2023, 03:32 PM   #558
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Search & Replace sounds more useful for one-off edits, and Action Chains for using it on a semi-regular basis
ownedbycats is online now   Reply With Quote
Old 04-04-2023, 07:01 PM   #559
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Quote:
Originally Posted by ownedbycats View Post
Search & Replace sounds more useful for one-off edits, and Action Chains for using it on a semi-regular basis
Well, unless the field (series_index) isn't available for editing with the SFE.

When using an if-then in S&R should I need to add an 'else $columnname' to return the original value to prevent nulling it out?

EDIT: It looks so.

Last edited by ownedbycats; 04-05-2023 at 12:29 AM.
ownedbycats is online now   Reply With Quote
Old 04-05-2023, 07:49 AM   #560
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,459
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
When using an if-then in S&R should I need to add an 'else $columnname' to return the original value to prevent nulling it out?

EDIT: It looks so.
The field will be replaced with whatever the template returns. Even if it is replacing it with itself.
chaley is offline   Reply With Quote
Old 04-05-2023, 08:34 AM   #561
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,459
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Well, unless the field (series_index) isn't available for editing with the SFE.
This stored template sets the series index to whatever the argument is:
Code:
python:
def evaluate(book, context):
	args = context.arguments
	if args is None or len(args) != 1:
		return 'Invalid arguments'
	try:
		sidx = float(args[0])
	except:
		return 'Bad series index'
	db = context.db
	from calibre.gui2.ui import get_gui
	gui = get_gui()

	bids = gui.current_view().get_selected_ids()
	results = []
	for bid in bids:
		db.set_series_index(bid, sidx)
		results.append(db.title(bid, index_is_id=True))
	db.refresh_ids(bids)
	gui.current_view().model().refresh_ids(bids)
	return 'Done: ' + ', '.join(results)
You call it by selecting books and running this template in the template tester:
Code:
program: change_series_index(0)
where the 0 is whatever you want.

You can also use it in an Action Chains formula action.

You can't use it in bulk edit search & replace.
chaley is offline   Reply With Quote
Old 04-05-2023, 01:08 PM   #562
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I just put program: columnupdate_seriesindex(0) in the template tester and it worked. The downside is I was testing with a book I hadn't wanted to change to 0. Oh well.

For future reference, can other called python templates update columns directly without the action chain?

Additionally: Other than the formulas action, would it work if called in a SFE template mode? That way I could do an if-then.

Last edited by ownedbycats; 04-05-2023 at 01:25 PM.
ownedbycats is online now   Reply With Quote
Old 04-05-2023, 02:07 PM   #563
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,459
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
I just put program: columnupdate_seriesindex(0) in the template tester and it worked. The downside is I was testing with a book I hadn't wanted to change to 0. Oh well.
Yea, that is what the template does. I didn't add a "test" mode.
Quote:
For future reference, can other called python templates update columns directly without the action chain?
Yes. However, depending on what you do you might need to do more work to update the GUI. For example, if you change a tag's name then you must update the tag browser and all the books affected by the rename. This isn't hard but it must be done.
Quote:
Additionally: Other than the formulas action, would it work if called in a SFE template mode? That way I could do an if-then.
Not as written because it operates on the entire selection. IIRC SFE is called per book, so if the template was changed to work on the current book then it should work. Two possible problems:
  • The GUI will be updated on every call so there might be some screen flashing. If SFE takes care of updating the GUI then those bits can be removed from the template.
  • SFE doesn't know how to update the series_index, so the template would do that behind its back. I don't know whether that will work reliably.
You could of course put the if/then in the Formula template that calls the python template. It would evaluate whether or not to call the stored template.
chaley is offline   Reply With Quote
Old 04-05-2023, 02:12 PM   #564
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
Oh yeah, my brain skipped a few steps "wait, that's why I wasn't using SFE in the first place...". Formulas I'll try that, not as familiar with using them.
ownedbycats is online now   Reply With Quote
Old 04-09-2023, 02:45 PM   #565
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I have this template for a composite column used for sorting in one VL/view manager view.

Code:
program:
## This one checks that #kobostatus has a value. If it does, return 'no' if it matches two specific criteria, and 'yes' otherwise.
	if 
		$#kobostatus
	then 
		switch_if(
			'\[(Add|Send) to Device\]' in $#kobostatus, 'No',
			$#kobostatus=='[Kobo Store]' && !$#kobodate, 'No',
		 	'Yes'
		)		
	fi
Functionally, this should do the same thing:

Code:
program: 
## This returns an empty if #kobostatus doesn't have a value. Other lines are unaffected.
	switch_if(
		!$#kobostatus, '',
## Alternate: $#kobostatus=='',
		'\[(Add|Send) to Device\]' in $#kobostatus, 'No',
		$#kobostatus=='[Kobo Store]' && !$#kobodate, 'No',
	 	'Yes'
	)
Would either of them be particularly faster?

Last edited by ownedbycats; 04-09-2023 at 02:59 PM.
ownedbycats is online now   Reply With Quote
Old 04-09-2023, 03:26 PM   #566
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,459
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
Would either of them be particularly faster?
No. Both need to do the test of $#kobostatus. Whether that is in an if or a switch_if might make a difference of nanoseconds one way or the other, which is way below what I worry about.
chaley is offline   Reply With Quote
Old 04-09-2023, 03:35 PM   #567
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
I'll keep the original, then, as it makes a bit more sense to me. Thanks
ownedbycats is online now   Reply With Quote
Old 04-11-2023, 09:41 AM   #568
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
For a formula for various book statistics: is there a function similar to round, but rounding to a certain number of decimal points instead of a whole number?

EDIT: format_number works. New question: How do I add a line break? This returns as one long line.

Code:
program:
strcat(
	'Chapter Count:', $#chaptercount,
	'Page Count:', $#pagecount,
	'Average Pages per Chapter:', format_number((divide($#pagecount, $#chaptercount)), '{0:5.2f}')
	)

Last edited by ownedbycats; 04-11-2023 at 09:52 AM.
ownedbycats is online now   Reply With Quote
Old 04-11-2023, 10:35 AM   #569
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,459
Karma: 8025600
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by ownedbycats View Post
For a formula for various book statistics: is there a function similar to round, but rounding to a certain number of decimal points instead of a whole number?

EDIT: format_number works. New question: How do I add a line break? This returns as one long line.

Code:
program:
strcat(
	'Chapter Count:', $#chaptercount,
	'Page Count:', $#pagecount,
	'Average Pages per Chapter:', format_number((divide($#pagecount, $#chaptercount)), '{0:5.2f}')
	)
Use the character() function, specifically character('newline')
chaley is offline   Reply With Quote
Old 04-11-2023, 10:58 AM   #570
ownedbycats
Custom User Title
ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.ownedbycats ought to be getting tired of karma fortunes by now.
 
ownedbycats's Avatar
 
Posts: 11,050
Karma: 75568269
Join Date: Oct 2018
Location: Canada
Device: Kobo Libra H2O, formerly Aura HD
That works, thanks
Attached Thumbnails
Click image for larger version

Name:	2023-04-11 11_57_57-Formulas.png
Views:	558
Size:	8.4 KB
ID:	200979  
ownedbycats is online now   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Library Management: various questions not worth their own thread ownedbycats Library Management 227 Yesterday 05:28 PM
[Metadata Source Plugin] Questions regarding parse select, docs and ref templates Boilerplate4U Development 13 07-07-2020 02:35 AM
Questions on Kobo [Interfered with another thread topic] spdavies Kobo Reader 8 10-12-2014 11:37 AM
[OLD Thread] Some questions before buying the fire. darthreader13 Kindle Fire 7 05-10-2013 09:19 PM
Thread management questions meme Feedback 6 01-31-2011 05:07 PM


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


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