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 02-02-2014, 06:15 PM   #1
kabirmaar
Member
kabirmaar began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Feb 2014
Device: none
reference to the plugin's toolbar button

i would like to make plugin with drop-down menu (self.popup_type = QToolButton.InstantPopup) and instead of textual (q)action i would like to add custom QWidget.

i have separated code which looks like this:
Code:
class Window(QtGui.QWidget):
    def __init__(self):
        QtGui.QWidget.__init__(self)
        layout = QtGui.QHBoxLayout(self)
        self.button = QtGui.QToolButton(self)
        self.button.setPopupMode(QtGui.QToolButton.InstantPopup)
        self.button.setMenu(QtGui.QMenu(self.button))
        self.textBox = QtGui.QTextBrowser(self)
        action = QtGui.QWidgetAction(self.button)
        action.setDefaultWidget(self.textBox)
        self.button.menu().addAction(action)
        layout.addWidget(self.button)

if __name__ == '__main__':

    import sys
    app = QtGui.QApplication(sys.argv)
    window = Window()
    window.resize(100, 60)
    window.show()
    sys.exit(app.exec_())
i can't find the reference to plugin's toolbar button in calibre which i would use as equivalent to self.button (as above).

in calibre plugin development i tried things like: self.qaction.parentWidget() and few others (but rather would avoid showing it )

no luck.

any idea how to do that?
kabirmaar is offline   Reply With Quote
Old 02-02-2014, 09:23 PM   #2
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: 37,316
Karma: 16447605
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
See setup_tool_button() in gui2/bars.py

Though I'm not clear why you need a reference to the button. Simply add your QWidgetAction to the qactions menu as you would normally.
kovidgoyal is offline   Reply With Quote
Advert
Old 02-02-2014, 10:28 PM   #3
kabirmaar
Member
kabirmaar began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Feb 2014
Device: none
Quote:
Originally Posted by kovidgoyal View Post
See setup_tool_button() in gui2/bars.py

Though I'm not clear why you need a reference to the button. Simply add your QWidgetAction to the qactions menu as you would normally.
hm. i was looking for a toolbar button as a reference because QWidgetAction asks for parent when created. and in the example above that parent is button on which action should be added.

when i do this in InterfaceAction.genesis (having action_add_menu = True):

Code:
self.qaction.menu().addAction(QWidgetAction().setDefaultWidget(d))
where d is QDialog instance in main.py (canonical plugin example) nothing happens. my guess was that QWidgetAction(plugin_toolbar_button).setDefaultWid get(d) will solve that problem. i could be easily wrong...

Last edited by kabirmaar; 02-02-2014 at 10:30 PM. Reason: formating
kabirmaar is offline   Reply With Quote
Old 02-02-2014, 10:48 PM   #4
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: 37,316
Karma: 16447605
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Set the menu as the parent. And keep a python reference to the widget action to prevent it from being garbage collected.
kovidgoyal is offline   Reply With Quote
Old 02-02-2014, 11:09 PM   #5
kabirmaar
Member
kabirmaar began at the beginning.
 
Posts: 15
Karma: 10
Join Date: Feb 2014
Device: none
Quote:
Originally Posted by kovidgoyal View Post
Set the menu as the parent. And keep a python reference to the widget action to prevent it from being garbage collected.
thanx. works!

had to add QMenu(self.gui) to qaction and keep a python reference to the widget action...

Code:
d = MyPlugin(self.gui, self.qaction.icon(), do_user_config, self.qaction)
m = QMenu(self.gui)
self.qaction.setMenu(m)
a = QWidgetAction(m)
a.setDefaultWidget(d)
m.addAction(a)
kabirmaar is offline   Reply With Quote
Advert
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with p toolbar button JimmyG Sigil 9 02-14-2013 04:26 PM
Eject button on toolbar? alliani Calibre 9 12-08-2012 07:31 AM
Wikipedia button/plugin for Calibre? ChrisKaos Calibre 2 04-20-2012 04:53 PM
Can I hold a reference to .model() and .db in a plugin? kiwidude Development 11 02-18-2011 06:52 PM
Interface - Button size in toolbar suggestion jbpilote Calibre 1 01-31-2010 10:27 AM


All times are GMT -4. The time now is 03:34 PM.


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