Register Guidelines E-Books Today's Posts Search

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

Notices

Reply
 
Thread Tools Search this Thread
Old 01-08-2023, 06:56 PM   #1
thiago.eec
Guru
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: 942
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Call actions by their unique_name

Hi everyone.

Scenario:
On a given plugin all the Menu actions are registered with a unique name. They all appear on Shortcuts Manager.

Now, I want to call this actions from inside the plugin (presumably by their unique name), simulating a click on the menu. Is this possible?
thiago.eec is offline   Reply With Quote
Old 01-08-2023, 09:26 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,960
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Easiest way is to store your actions in a dict in your plugin keyed by the unique name.
kovidgoyal is offline   Reply With Quote
Old 01-09-2023, 06:04 AM   #3
thiago.eec
Guru
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: 942
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
Easiest way is to store your actions in a dict in your plugin keyed by the unique name.
Hi, Kovid.

Thanks for the reply.
But how would I call them? I don't see anything callable.
Here is a real example:

Plugin name: Skoob Sync
Modules: main.py, ui.py.

In the ui.py, we have a lot of actions created. Like this:

Code:
# Add/remove books
        self.add_to_skoob = cm(self.m, _('&Add book'),
           image='add_to_skoob.png',
           tooltip=_('Add book to Skoob, on Reading shelf'),
           triggered=partial(self.tools.update_status, sync_option='add_to_skoob', shelf=None),
           unique_name='SkoobSync_Add')
        self.remove_from_skoob = cm(self.m, _('&Remove book'),
           image='remove_from_skoob.png',
           tooltip=_('Remove book from your shelves on Skoob'),
           triggered=partial(self.tools.update_status, sync_option='remove_from_skoob', shelf=None),
           unique_name='SkoobSync_Remove')
        self.m.addSeparator()
Their unique names are: 'SkoobSync_Add' and 'SkoobSync_Remove'.
Now, how would I call them from main.py?
thiago.eec is offline   Reply With Quote
Old 01-09-2023, 07:18 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,960
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
self.add_to_skoob.trigger()
kovidgoyal is offline   Reply With Quote
Old 01-09-2023, 07:55 AM   #5
thiago.eec
Guru
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: 942
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
self.add_to_skoob.trigger()
I thought that there would be some way to call them using iactions, or something (based on their unique names*).
The problem is my ui.py is already importing a class from main.py, so I don't see how I could call 'add_to_skoob.trigger()' from there (it would be a circular reference).

*P.S.: The unique names ares used only to create shortcuts?

Last edited by thiago.eec; 01-09-2023 at 09:05 AM. Reason: typo
thiago.eec is offline   Reply With Quote
Old 01-09-2023, 08:37 AM   #6
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 43,960
Karma: 22669822
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
iactions['action name].add_to_skoob.trigger()
kovidgoyal is offline   Reply With Quote
Old 01-09-2023, 09:05 AM   #7
thiago.eec
Guru
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: 942
Karma: 1177583
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite
Quote:
Originally Posted by kovidgoyal View Post
iactions['action name].add_to_skoob.trigger()
That's exactly what I was expecting!
I've tried some combinations of this but nothing worked.

For example, I can use this:
Code:
gui.iactions.['Skoob Sync'].rebuild_menus()
'Skoob Sync' referes to the IntefacePlugin.

But when I try to call other actions, it gives me a KeyError:

Code:
gui.iactions['SkoobSync_Add'].add_to_skoob.trigger()

KeyError: 'SkoobSync_Add'
'SkoobSync_Add' is the unique name for the action.

________________________________
Edit


Never mind, I got it. I was trying to use the actions unique name, when I should use the plugin's combined with the actions.

This works perfectly:
Code:
gui.iactions['Skoob Sync'].add_to_skoob.trigger()
Thank you for the help!

Last edited by thiago.eec; 01-09-2023 at 09:14 AM.
thiago.eec is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Actions and Column Fynjisx Library Management 10 11-19-2022 08:57 AM
Any way to automate Calibre actions? bob.f Library Management 4 08-16-2021 08:07 AM
V. 3.2.1: Actions toolbar incomplete Leonatus Calibre 14 07-03-2017 02:38 PM
actions toolbar Seadevil Library Management 1 10-04-2016 06:03 PM
Actions Interface amfera Library Management 2 05-04-2012 09:05 AM


All times are GMT -4. The time now is 10:02 PM.


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