![]() |
#1 |
Sigil developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,274
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
![]() 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). |
![]() |
![]() |
![]() |
#2 |
Calibre Plugins Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 4,728
Karma: 2197770
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) |
![]() |
![]() |
Advert | |
|
![]() |
#3 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,296
Karma: 27111240
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() |
![]() |
![]() |
![]() |
#4 |
Sigil developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,274
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' |
![]() |
![]() |
![]() |
#5 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,296
Karma: 27111240
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.
|
![]() |
![]() |
Advert | |
|
![]() |
#6 |
Sigil developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 1,274
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 |
![]() |
![]() |
![]() |
#7 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,296
Karma: 27111240
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) |
![]() |
![]() |
![]() |
|
![]() |
||||
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 |