1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# Copyright 2008 Nanorex, Inc. See LICENSE file for details.
"""
@author: Ninad
@copyright: 2008 Nanorex, Inc. See LICENSE file for details.
@version:$Id$
History:
Ninad 2008-07-15: Created during an initial refactoring of class CommandToolbar
Moved the common code out of Ui_CommandToolBar and CommandToolbar into this
class.
TODO:
"""
from foundation.wiki_help import QToolBar_WikiHelp
from PyQt4.Qt import QMenu
from PyQt4.Qt import Qt
from PyQt4.Qt import QPalette
from PyQt4.Qt import QToolButton
from PM.PM_Colors import getPalette
from commandToolbar.CommandToolbar_Constants import cmdTbarCmdAreaBtnColor
from utilities.icon_utilities import geticon
_superclass = QToolBar_WikiHelp
class FlyoutToolBar(QToolBar_WikiHelp):
def __init__(self, parent):
_superclass.__init__(self, parent)
self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
self.addSeparator()
self.setAutoFillBackground(True)
palette = self.getPalette()
self.setPalette(palette)
self._setExtensionButtonIcon()
def clear(self):
"""
Clear the actions within this toolbar AND also clear the
submenu of the extension popup indicator ('>>") button of this toolbar.
NOTE: QToolBar.clear() doesn't automatically clear the latter. (at least
in Qt4.3) Because of this, there was a problem in fixing bug 2916.
Apparently, the only way to access an extension button widget of a QToolBar
is to access its children() and the 3rd button in the list is
the extension indicator button, whose menu need to be cleared.
"""
_superclass.clear(self)
extension_menu = self.getExtensionMenu()
if extension_menu is not None:
extension_menu.clear()
def getPalette(self):
"""
Return a palette for Command Manager 'Commands area'(flyout toolbar)
(Palette for Tool Buttons in command toolbar command area)
"""
return getPalette(None,
QPalette.Button,
cmdTbarCmdAreaBtnColor
)
def _setExtensionButtonIcon(self):
"""
Sets the icon for the Flyout Toolbar extension button.
The PNG image can be 24 (or less) pixels high by 10 pixels wide.
"""
extension_button = self.getExtensionButton()
extension_button.setIcon(geticon(
"ui/actions/Command Toolbar/ExtensionButtonImage.png"))
def getExtensionButton(self):
"""
Returns the extension popup indicator toolbutton ">>"
"""
btn = None
clist = self.children()
for c in range(0, len(clist)):
if isinstance(clist[c], QToolButton):
btn = clist[c]
break
return btn
def getExtensionMenu(self):
"""
Return the extension menu i.e. the submenu of the extension popup
indicator button ">>" (if any)
"""
toolbtn = self.getExtensionButton()
if toolbtn is None:
return None
menu = None
# Children of 1st QToolButton (3rd toolbar child) contains a single QMenu
toolbtn_clist = toolbtn.children()
if toolbtn_clist:
extension_menu = toolbtn_clist[0] # The extension menu!
if isinstance(extension_menu, QMenu):
menu = extension_menu
return menu
|