I am trying to create a subclass of StaticText with a menu that pops up on a
mouse left down. It should look and behave like a menu on a menubar except
that the text changes to indicate the last selection (like a Choice -- in
fact, I could use a Choice if there were a way to select a flat style).
However, the StaticTextWithMenu can go on a panel with other controls, such
as StaticBitmaps or Buttons. My implementation uses a ListCtrl for the
menu. I thought I had the control working, but there is a problem. When
the control is placed on a short panel, the ListCtrl gets clipped. I am
trying to think of a way to get the ListCtrl to draw outside the bounds of
its parent.
In my StaticTextWithMenu class, both the StaticText and the popup ListCtrl
are owned by the panel the StaticTextWithMenu is placed on. One
possibility I have been exploring is to give the ListCtrl to the top-level
Frame. That change does circumvent the clipping, but I will have to figure
out how to position the ListCtrl relative to the StaticText on the panel.
Also, the ListCtrl draws without a box around it on Linux (with
wx.SIMPLE_BORDER)(on Windows the border still appears).
The other approach I explored was a popup menu. That approach is
wonderfully simple, but I can't find a way to position the popup menu. It
needs to appear in a fixed position relative to the static text, not
relative to the position of the mouse event.
I forgot to mention that the pos argument to the PopupMenu method almost
solves the problem with the popup menu approach, but I also have to be able
to specify whether the menu is placed above or below the static text -- or
I have to be able to rely on the default. However, with the static text at
the bottom of a window, the default position is down (out of the window)
when I would like for it to go up. If I could figure out the height of the
popup menu I could adjust the position accordingly, but I don't see a way
to get that information.
In my StaticTextWithMenu class, both the StaticText and the popup ListCtrl
are owned by the panel the StaticTextWithMenu is placed on. One
possibility I have been exploring is to give the ListCtrl to the top-level
Frame. That change does circumvent the clipping, but I will have to figure
out how to position the ListCtrl relative to the StaticText on the panel.
You can find the position of the static text relative to the screen with ClientToScreen().
Also, the ListCtrl draws without a box around it on Linux (with
wx.SIMPLE_BORDER)(on Windows the border still appears).
Yeah, I'm not sure why that style doesn't do anything on wxGTK, but it's always been that way.
The other approach I explored was a popup menu. That approach is
wonderfully simple, but I can't find a way to position the popup menu. It
needs to appear in a fixed position relative to the static text, not
relative to the position of the mouse event.
Am I missing something obvious?
If you don't need it to work on OS X you can try using a wx.PopupWindow as the base.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!