|
|
#1 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,291
Karma: 1428263
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
|
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? |
|
|
|
|
|
#2 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,604
Karma: 28548974
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.
|
|
|
|
|
|
#3 | |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,291
Karma: 1428263
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
|
Quote:
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()
Now, how would I call them from main.py? |
|
|
|
|
|
|
#4 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,604
Karma: 28548974
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
self.add_to_skoob.trigger()
|
|
|
|
|
|
#5 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,291
Karma: 1428263
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
|
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 |
|
|
|
|
|
#6 |
|
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,604
Karma: 28548974
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
iactions['action name].add_to_skoob.trigger()
|
|
|
|
|
|
#7 |
|
Wizard
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,291
Karma: 1428263
Join Date: Dec 2016
Location: Goiânia - Brazil
Device: iPad, Kindle Paperwhite, Kindle Oasis
|
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() 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' ________________________________ 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() Last edited by thiago.eec; 01-09-2023 at 09:14 AM. |
|
|
|
![]() |
|
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 |