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 03-09-2011, 07:17 AM   #1
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
Karma: 2162064
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.
kiwidude is offline   Reply With Quote
Old 03-09-2011, 08:37 AM   #2
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: 11,733
Karma: 6690881
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
If the class Foo were in a separate file, then importing the class is sufficient.
chaley is offline   Reply With Quote
Advert
Old 03-09-2011, 08:43 AM   #3
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
Karma: 2162064
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"?
Attached Thumbnails
Click image for larger version

Name:	PluginMenuPatch.png
Views:	440
Size:	18.1 KB
ID:	68037  

Last edited by kiwidude; 03-09-2011 at 08:47 AM.
kiwidude is offline   Reply With Quote
Old 03-09-2011, 08:48 AM   #4
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: 11,733
Karma: 6690881
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by kiwidude View Post
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"?
If you can instantiate it, you must have a handle to it. Just take the () off of whatever you use to instantiate it.
chaley is offline   Reply With Quote
Old 03-09-2011, 08:53 AM   #5
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: 11,733
Karma: 6690881
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.
chaley is offline   Reply With Quote
Advert
Old 03-09-2011, 08:59 AM   #6
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
Karma: 2162064
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.
kiwidude is offline   Reply With Quote
Old 03-09-2011, 09:20 AM   #7
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
Karma: 2162064
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?
kiwidude is offline   Reply With Quote
Old 03-09-2011, 10:02 AM   #8
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
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.
meme is offline   Reply With Quote
Old 03-09-2011, 10:09 AM   #9
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
Quote:
Originally Posted by meme View Post
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.
This will be added to the Calibre codebase, not in a plugin. So it will affect every gui plugin a user adds and means we as plugin developers don't have to bother.
kiwidude is offline   Reply With Quote
Old 03-09-2011, 10:14 AM   #10
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
Can't get easier than that
meme is offline   Reply With Quote
Old 03-09-2011, 10:25 AM   #11
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,843
Karma: 22666666
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.
kovidgoyal is offline   Reply With Quote
Old 03-09-2011, 10:33 AM   #12
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
Karma: 2162064
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.
kiwidude is offline   Reply With Quote
Old 03-12-2011, 03:05 AM   #13
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
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?
meme is offline   Reply With Quote
Old 03-12-2011, 05:29 AM   #14
kiwidude
Calibre Plugins Developer
kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.kiwidude ought to be getting tired of karma fortunes by now.
 
Posts: 4,636
Karma: 2162064
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.
Click image for larger version

Name:	KindleCollections.png
Views:	420
Size:	18.4 KB
ID:	68198
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.
Click image for larger version

Name:	Toolbar.png
Views:	402
Size:	64.1 KB
ID:	68199
But when I plugin my Kindle, the plugin appears as expected?
Click image for larger version

Name:	ToolbarConnected.png
Views:	410
Size:	44.8 KB
ID:	68200

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.
kiwidude is offline   Reply With Quote
Old 03-12-2011, 06:36 AM   #15
meme
Sigil developer
meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.meme ought to be getting tired of karma fortunes by now.
 
Posts: 1,275
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.
meme is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
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


All times are GMT -4. The time now is 10:51 AM.


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