![]() |
#1 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,718
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Giving users menu/toolbars option when adding plugin
Kovid mentioned on another thread the idea of popping up a list of possible menu/toolbar locations a user could display a GUI plugin in when adding a plugin. This would be great to stop the almost daily posts from users who cannot figure out how to add or only put it on the toolbar.
I said I would have go at adding this, but have hit a snag. The "dont_add_to" set of locations resides on the InterfaceAction class. At the point this code will reside in plugins.py you only have "plugin" which is a subclass of InterfaceActionBase. The gui actions are not instantiated until after a Calibre restart. So how can I get to the "dont_add_to" set? Is it "safe" to call load_actual_plugin and then query that object? Presumably that means there are two instance instantiated temporarily for when you are upgrading plugins, is that ok? Last edited by kiwidude; 03-09-2011 at 07:25 AM. |
![]() |
![]() |
![]() |
#2 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,313
Karma: 7957679
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Those attributes are class-level, so you don't need to instantiate the class to see them. All you need is a handle to the class. For example, the following program works:
Code:
class Foo(object): dont = frozenset(['toolbar-device', 'context-menu-device']) def bar(self): pass print Foo.dont |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,718
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
I went ahead and instantiated the action. I needed to get the name attribute as well add to the menus/toolbar anyway which is the same issue.
I have made the behaviour that the dialog only appears if (a) it is a plugin inheriting from InterfaceActionBase, and (b) you have not previously added the plugin to a menu or toolbar. The latter is because I figure users upgrading will not want to get nagged by the dialog. Edit - just saw chaley's post. The problem is I don't have a handle to the class without instantiating it since it is "unknown"? Last edited by kiwidude; 03-09-2011 at 08:47 AM. |
![]() |
![]() |
![]() |
#4 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,313
Karma: 7957679
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
|
![]() |
![]() |
![]() |
#5 |
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,313
Karma: 7957679
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Ahhh... I see. You need to call load_actual_plugin, because only that knows what class it is using.
I imagine that Kovid would consider an API extension that can return the class instance, if that would avoid some problems. |
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,718
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Yeah, you see my problem
![]() What I have done "works" but I just don't know if it is the right thing to do. I guess I can just give it to Kovid as is and he can tweak his API if he wants to try to avoid the issue. Though I am not sure how easy that will be and what about the proxy type approach we are using in most of the plugins etc. |
![]() |
![]() |
![]() |
#7 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,718
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Actually while doing this I found what I wonder is a bug. Bear in mind I have commented out any modification by my code.
To replicate (I am sure there are easier ways) paste this at line 284 of gui2/preferences/plugins.py: from calibre.gui2 import gprefs print gprefs['action-layout-toolbar'] Then add a plugin (debug output will display value as a list), click cancel and go to "Customize the toolbar", add or remove an item from the main toolbar, click apply, go back to plugins and choose add again. The prefs will display as a tuple! Is that expected? My code is normally expecting to append to a list and suddenly it has a tuple to deal with? |
![]() |
![]() |
![]() |
#8 |
Sigil developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,274
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
So which plugin is using this code? Sounds like a good idea. I'd like to be able to do a pop-up as well. Although since I know it has to go on one specific menu toolbar, maybe I can even automatically add it to the toolbar at the end and let the user use Preferences to move it around later if they want.
|
![]() |
![]() |
![]() |
#9 | |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,718
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Quote:
|
|
![]() |
![]() |
![]() |
#10 |
Sigil developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,274
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Can't get easier than that
![]() |
![]() |
![]() |
![]() |
#11 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,144
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Assume the sequence of actions is always a tuple, a make a copy like this
actions = list(actions) The fact that it is occasionally a list is a side effect of JSON not supporting tuples. And when you commit it use gprefs[whatever] = tuple(actions) And dont worry about instantiating the plugin. If things need to change there, I'll fix them when you submit the code. |
![]() |
![]() |
![]() |
#12 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,718
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
Thanks Kovid. The patch I had just emailed you was before your response, so if you can make that list/tuple change along with whatever else you do with it that would be great. Let me know if you need anything else from me with it.
|
![]() |
![]() |
![]() |
#13 |
Sigil developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,274
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Using 0.7.49 with the update to automatically add the icon partly works for me - its a bit overzealous and adds my icon to the main toolbar without device even though I have:
class KindleCollectionsAction(InterfaceAction): name = PLUGIN_NAME action_spec = (_(PLUGIN_NAME), None, None, None) popup_type = QToolButton.InstantPopup action_type = 'current' dont_add_to = frozenset(['toolbar', 'context-menu']) I remove my old plugin, restart, then use the GUI to add the plugin, restart, and the icon appears in both places. By the way, in preferences->customize the toolbar how do I put my custom icon next to the text name of the icon like the built-in entries? |
![]() |
![]() |
![]() |
#14 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,718
Karma: 2197770
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
meme, I don't get that behaviour. Are you sure you hadn't added it to the main toolbar in some other way in the past before you did the dont_add_to?
I just now did these steps: Preferences->Plugins->Uninstall Create Kindle Collections Without closing dialog, Add new plugin of KindleCollections. That gave me the dialog in the screenshot attached. I chose the top option of "The main toolbar when the device is connected". Clicked OK. Restarted Calibre. As you can see from the second screenshot your plugin is not present. But when I plugin my Kindle, the plugin appears as expected? Your other question about the icons for the Preferences->Customize the toolbar is something that has been bugging me for a while. I did look at the code once and found the reason why it would not display them - there is nothing we as plugin developers can do, it needs Calibre code changes. |
![]() |
![]() |
![]() |
#15 |
Sigil developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,274
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Ok, this is a bit odd. Will need to test it on my other system.
On this one I'm not getting the dialog - but the icon is correctly being added only to the connected device toolbar. I'm sure I've added the toolbar to both menus at some point in order to test it, etc. Is there some way to completely remove Calibre's memory of the toolbar position if its keeping it after a delete? At this point I start Calibre, delete the plugin, exit. Check plugin is deleted from command line. Restart. Check in Preferences->Customize toolbar that the entry for the plugin is not in either connected/not connected menu, then add the plugin. I don't get a dialog, but when I restart I get the plugin icon on the connected device toolbar ok, and its correctly not on the not-connected toolbar. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Troubleshooting Menu option for "Create New Collection" is greyed out, why? | geekgeek | Amazon Kindle | 19 | 10-10-2016 09:38 PM |
Possible new feature: Adding a r/c menu option to add to user category items | kiwidude | Calibre | 29 | 11-30-2010 09:14 AM |
Error Adding Plugin | modkindle | Plugins | 14 | 05-16-2010 12:14 PM |
Power Mode option in diagnostics menu? | scarab1 | Ectaco jetBook | 0 | 02-28-2010 10:59 PM |
Microsoft to Offer Downgrade Option for Vista Business Users | Azayzel | Deals and Resources (No Self-Promotion or Affiliate Links) | 22 | 09-27-2007 10:26 PM |