Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 04-20-2011, 11:02 AM   #1
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
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).
meme is offline   Reply With Quote
Old 04-20-2011, 11:09 AM   #2
kiwidude
calibre/Sigil 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,228
Karma: 1334002
Join Date: Oct 2010
Location: London, UK
Device: Kindle Paperwhite 3G, iPad 3, iPad Air
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)
Of course with all the additional toolbars etc Calibre has nowadays perhaps it is not sufficient, I haven't tested it elsewhere than the main toolbar.
kiwidude is offline   Reply With Quote
Old 04-20-2011, 11:26 AM   #3
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: 26,126
Karma: 5381911
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()
kovidgoyal is offline   Reply With Quote
Old 04-20-2011, 12:16 PM   #4
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
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'
I'm using the check if the icon is in the bar before refreshing it, and then just running self.gui.tool_bar.build_bar() since I don't actually change the submenus in my plugin just the icon, although I'll put them in the code as comments so I don't forget if I ever due change the submenus.
meme is offline   Reply With Quote
Old 04-20-2011, 12:26 PM   #5
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: 26,126
Karma: 5381911
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.
kovidgoyal is offline   Reply With Quote
Old 04-20-2011, 01:22 PM   #6
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
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
Then the icon doesn't change until I restart or I use the build bar_function.
meme is offline   Reply With Quote
Old 04-20-2011, 01:27 PM   #7
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: 26,126
Karma: 5381911
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)
kovidgoyal is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

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


All times are GMT -4. The time now is 02:40 AM.


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