I need a drop-down-style tool on my toolbar, however the wx.ToolBar does
not support it yet. So I want use a popup menu to simulate it -- when
the user clicks the toolbar button (not the real wx.Button, but the ones
using wxToolBar.AddLabelTool), a wx.Menu is PopupMenu'ed, right below
the tool button.
Then I need to know the position and size of the tool button to
calculate the position for popup menu. How can I get it?
I tried use wx.ToolBar.GetToolSize() to get the button's width, and
multiply with the number of tool buttons at the left of it. However,
there are two problems with this solution:
1. On my system (wxGTK 2.4), GetToolSize() returns (16,16), it is the
size of the bitmap associated with the toolbar. But my tool button is
much larger than that because of the button label.
2. There are several sperators in my toolbar. They must be calculated
in to get the correct position for popup menu. How can I get its width?
Or anyone has implemented a dropdown tool before?
···
--
Qiangning Hong
________________________
< I feel ... JUGULAR ... >
------------------------
\ __------~~-,
\ ,' ,
/ \
/ :
> '
> >
> >
> _-- |
_| =-. .-. ||
o>/o/ _. |
/ ~ \ |
(____@) ___~ |
>_===~~~.` |
_______.--~ |
\________ |
\ |
__/-___-- -__
/ _ \
Monday, June 20, 2005, 10:19:35 PM, Qiangning Hong wrote:
I need a drop-down-style tool on my toolbar, however the wx.ToolBar
does not support it yet. So I want use a popup menu to simulate it
-- when the user clicks the toolbar button (not the real wx.Button,
but the ones using wxToolBar.AddLabelTool), a wx.Menu is
PopupMenu'ed, right below the tool button.
Then I need to know the position and size of the tool button to
calculate the position for popup menu. How can I get it?
I haven't tried this, but I thought about trying to bind the
EVT_LEFT_DOWN event to some method that stores the mouse position for
the event (to, say, self.x and self.y). As you probably are already
binding the EVT_TOOL event to another method that does the tool work,
you could then just pop the menu inside that method at the coords
stored on self.x and self.y.
-- tacao
No bits were harmed during the making of this e-mail.
E. A. Tacao wrote:
Monday, June 20, 2005, 10:19:35 PM, Qiangning Hong wrote:
I need a drop-down-style tool on my toolbar, however the wx.ToolBar
does not support it yet. So I want use a popup menu to simulate it
-- when the user clicks the toolbar button (not the real wx.Button,
but the ones using wxToolBar.AddLabelTool), a wx.Menu is
PopupMenu'ed, right below the tool button.
Then I need to know the position and size of the tool button to
calculate the position for popup menu. How can I get it?
I haven't tried this, but I thought about trying to bind the
EVT_LEFT_DOWN event to some method that stores the mouse position for
the event (to, say, self.x and self.y). As you probably are already
binding the EVT_TOOL event to another method that does the tool work,
you could then just pop the menu inside that method at the coords
stored on self.x and self.y.
Record the mouse position isn't helpful for me. What I want is to pop
up the menu *right below* the tool button (just like the menu is dropped
down from the button), not at the position of mouse click.
If you use mozilla firefox, maybe you'll know what I mean: something
like the dropdown menu for the "backward" button on the navigation
toolbar. And as far as I know, the "backward" button on Internet
Explorer has a very similar dropdown menu.
···
--
Qiangning Hong
Tuesday, June 21, 2005, 1:04:28 AM, Qiangning Hong wrote:
Record the mouse position isn't helpful for me. What I want is to
pop up the menu *right below* the tool button (just like the menu is
dropped down from the button), not at the position of mouse click.
If you use mozilla firefox, maybe you'll know what I mean: something
like the dropdown menu for the "backward" button on the navigation
toolbar. And as far as I know, the "backward" button on Internet
Explorer has a very similar dropdown menu.
I see. Another approach would be not to use a toolbar and instead put
all the buttons inside a horizontal box sizer at the top of the frame
and use vertical static lines as separators (this way creating a
custom toolbar-like thing). This way you could easily keep track of
the size and position for every button/tool.
-- tacao
No bits were harmed during the making of this e-mail.
I need a drop-down-style tool on my toolbar, however the wx.ToolBar does
not support it yet.
The wxPython demo has a toolbar with a drop-down (and an edit box).
Doesn't that do what you want? Perhaps it doesn't work on GTK (it's fine
on Windows).
Hugh
The demo shows a wx.ComboBox, which isn't what the original poster
wants. (I'm not sure whether the control the poster is describing even
exists in wxPython.)
···
On 21-Jun-2005, Hugh Gibson wrote:
> I need a drop-down-style tool on my toolbar, however the
> wx.ToolBar does not support it yet.
The wxPython demo has a toolbar with a drop-down (and an edit box).
Doesn't that do what you want? Perhaps it doesn't work on GTK (it's
fine on Windows).
--
\ "Faith may be defined briefly as an illogical belief in the |
`\ occurrence of the improbable." -- Henry L. Mencken |
_o__) |
Ben Finney <ben@benfinney.id.au>