View Single Post
Old 05-06-2025, 12:17 PM   #3
thiago.eec
Wizard
thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.thiago.eec ought to be getting tired of karma fortunes by now.
 
Posts: 1,220
Karma: 1419583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
Quote:
Originally Posted by moriabbey View Post
I'm looking to make a plugin that seems fairly simple, but I can't figure out how to go about it. I want it to, every time a specific custom metadata field is changed, change the "Title sort" metadata field to be identical to that custom metadata field. Reading and changing metadata fields seems straightforward enough from the API documentation, but I don't see how I would get it to trigger on a metadata field being changed. I have some very basic Python experience, enough to fumble my way through the API docs, but zero experience with calibre plugins or any kind of real development. Is something like this at all possible?
Here is how I did in my GUI plugin (Reading Goal):

In the __init__ method of your main class, set up the listener:
Code:
self.gui.add_db_listener(self.metadata_changed_event)
Then, create the 'metadata_changed_event' method:
Code:
    def metadata_changed_event(self, db, event_type, event_data):    
        if event_type is EventType.metadata_changed:
            if event_data[0] == self.prefs['your_column_name']:
                self.ids = event_data[1]
        return
event_data[0] is the name of the column changed, so you compare it with your custom column. In my case, it was saved in the json prefs. But you could hardcode it:
Code:
 if event_data[0] == 'your_column_name':
Now, you can perform the operations you want, using 'self.ids'. This a list of ids that have their metadata changed. Like @Kovid said, this must be done outside of the ' metadata_changed_event' method.

Last edited by thiago.eec; 05-06-2025 at 02:47 PM.
thiago.eec is offline   Reply With Quote