04-20-2011, 11:02 AM | #1 |
Sigil developer
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Refreshing toolbar icons
I've added a feature to my plugin (mainly for kiwidude ) to allow you to change the behaviour of the toolbar icon through customization. By default when you install the plugin its only a dropdown menu. But you can customize it to select any of the menu's functions to be the default action (or to just show the menu). When you restart calibre, the icon will change to the split icon/menu view if you've chosen a function, and if you click the icon it will run the function you configured. You can of course click the down arrow to get the menu as usual.
I'd like to avoid having to restart calibre. I see that if I run Preferences and add/remove another icon and save, that my icon correctly updates, so I know its possible. There are many functions in the source and after testing a few I think it might be safer to ask the right way to do this in order to avoid problems later. So how to I get the toolbar icons to refresh without restarting? I expect to call this either in my plugins __init__ save_settings, or possibly within the ui rebuild_menus (but I think that might be calling a refresh inside of a refresh). |
04-20-2011, 11:09 AM | #2 |
Calibre Plugins Developer
Posts: 4,637
Karma: 2162064
Join Date: Oct 2010
Location: Australia
Device: Kindle Oasis
|
There is code that does this in my walk search history plugin. There is a bunch more stuff to actually hook/unhook events as appropriate but the magic line is:
Code:
# Apply the popup type for this action in the toolbar # Only update on the toolbar if it is actually visible there if self.qaction in self.gui.tool_bar.added_actions: self.gui.tool_bar.setup_tool_button(self.gui.tool_bar, self.qaction, self.popup_type) |
04-20-2011, 11:26 AM | #3 |
creator of calibre
Posts: 43,870
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Code:
self.gui.tool_bar.build_bar() self.gui.menu_bar.build_bar() self.gui.build_context_menus() |
04-20-2011, 12:16 PM | #4 |
Sigil developer
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
Okay, thanks to both. Got that working. Should have known you had that in one of your plugins - but it was fun figuring the rest out
It was necessary to put the rebuild_menus into initialization complete otherwise I would get: Code:
AttributeError: 'Main' object has no attribute 'tool_bar' |
04-20-2011, 12:26 PM | #5 |
creator of calibre
Posts: 43,870
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Actually, I'm a little surprised that just calling setIcon on your qaction in initialization_complete doesn't automatically change the icon in the bar.
|
04-20-2011, 01:22 PM | #6 |
Sigil developer
Posts: 1,275
Karma: 1101600
Join Date: Jan 2011
Location: UK
Device: Kindle PW, K4 NT, K3, Kobo Touch
|
It doesn't seem to. It appears as if the tooltip and function changes ok. But if I change from a split icon to a single icon and vice versa using
Code:
self.popup_type = QToolButton.InstantPopup or self.popup_type = QToolButton.MenuButtonPopup |
04-20-2011, 01:27 PM | #7 |
creator of calibre
Posts: 43,870
Karma: 22666666
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Ah yes, for the popup type you would need this
Code:
for bar in (self.gui.tool_bar, self.gui.tool_bar.child_bar): w = bar.widgetForAction(self.qaction) if w is not None: w.setPopupMode(QToolButton.whatever) |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
LrfAppender: IE toolbar similar to "Toolbar for Librie" | mumurik | LRF | 1 | 10-13-2009 04:01 AM |
LrfAppender: IE toolbar similar to "Toolbar for Librie" | mumurik | Sony Reader Dev Corner | 1 | 10-06-2009 03:33 AM |
Toolbar icons | yingwu | iRex | 3 | 06-17-2009 12:20 PM |
iLiad Add new icons to the toolbar | ouais32 | iRex Developer's Corner | 2 | 01-04-2008 12:04 PM |
iLiad Toolbar icons | tomchek | iRex Developer's Corner | 6 | 07-30-2007 11:13 AM |