首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在小部件上使用wxOverlay?

在小部件上使用wxOverlay?
EN

Stack Overflow用户
提问于 2012-03-16 02:29:34
回答 1查看 912关注 0票数 4

我在这个橡皮筋示例中创建了一个按钮。橡皮筋没有出现在按钮上面,我想让橡皮筋出现在按钮上面。

代码语言:javascript
复制
import wx
print wx.version()

class TestPanel(wx.Panel):
     def __init__(self, *args, **kw):
         wx.Panel.__init__(self, *args, **kw)

         self.Bind(wx.EVT_PAINT, self.OnPaint)
         self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
         self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
         self.Bind(wx.EVT_MOTION, self.OnMouseMove)

         self.startPos = None
         self.overlay = wx.Overlay()
         self.b=wx.Button(self)

     def OnPaint(self, evt):
         # Just some simple stuff to paint in the window for an example
         dc = wx.PaintDC(self)
         coords = ((40,40),(200,220),(210,120),(120,300))
         dc.SetBackground(wx.Brush("sky blue"))
         dc.Clear()
         dc.SetPen(wx.Pen("red", 2))
         dc.SetBrush(wx.CYAN_BRUSH)
         dc.DrawPolygon(coords)
         dc.DrawLabel("Drag the mouse across this window to see \n"
                     "a rubber-band effect using wx.Overlay",
                     (140, 50, -1, -1))

     def OnLeftDown(self, evt):
         # Capture the mouse and save the starting posiiton for the
         # rubber-band
         self.CaptureMouse()
         self.startPos = evt.GetPosition()

     def OnMouseMove(self, evt):
         if evt.Dragging() and evt.LeftIsDown():
             rect = wx.RectPP(self.startPos, evt.GetPosition())

             # Draw the rubber-band rectangle using an overlay so it
             # will manage keeping the rectangle and the former window
             # contents separate.
             dc = wx.ClientDC(self)

             #***  This won't work because wx.GCDC is not a wx.WindowDC
             #dc = wx.GCDC(dc)

             odc = wx.DCOverlay(self.overlay, dc)
             odc.Clear()

             #***  This crashes on wxMac

             #dc = wx.GCDC(dc)

             dc.SetPen(wx.Pen("black", 2))
             if 'wxMac' in wx.PlatformInfo:
                 dc.SetBrush(wx.Brush(wx.Colour(0xC0, 0xC0, 0xC0, 0x80)))
             else:
                 dc.SetBrush(wx.TRANSPARENT_BRUSH)
             dc.DrawRectangleRect(rect)

             del odc # work around a bug in the Python wrappers to make
                     # sure the odc is destroyed before the dc is.

     def OnLeftUp(self, evt):
         if self.HasCapture():
             self.ReleaseMouse()
         self.startPos = None

         # When the mouse is released we reset the overlay and it
         # restores the former content to the window.
         dc = wx.ClientDC(self)
         odc = wx.DCOverlay(self.overlay, dc)
         odc.Clear()
         del odc
         self.overlay.Reset()

app = wx.App(redirect=False)
frm = wx.Frame(None, title="wx.Overlay Test", size=(450,450))
pnl = TestPanel(frm)
frm.Show()
app.MainLoop()
EN

回答 1

Stack Overflow用户

发布于 2013-02-05 04:16:13

我认为目前它只能在wx.Overlay是真正的覆盖对象的OSX上完成。在其他平台上,它们只是使用wx.ClientDC进行模拟,这意味着对覆盖图的绘制只能发送到为其创建DC的窗口。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9725890

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档