> From what I understand, windows (subclasses of wx.Window) are drawn
> after their parents. So, if you want to draw on top of some previously
> existing window/widget, you could make a control that is a child of the
> window/widget, and override its drawing behavior.
>
>
> The following doesn't quite work the way I expect it to, but it should
> give you an idea...
Your code segfaults without error, but changing the self.d =
drawover(self.tc2) to a self.d = drawover(self) does perform mostly
correctly; apparently the sizers are drawn first in this case; maybe
textctrls can't have children?
It doesn't segfault using 2.6.3.3 or 2.7.1.3 on Windows, but what I was
trying to do is to have a child of the text control draw over the text
control without blocking what is underneath it. It still segfaults on
Linux, and trying to reparent the drawover window doesn't seem to do the
drawing right.
The problem if I do this is that the wx.Window has a grey background.
To function as I want, it has to be transparent. Is there an easy way
to clear the background?
Looking back in the archives, I remembered a thread with the subject of
"Custom red X control and wx.window styles documentation", that uses the
wx.TRANSPARENT_WINDOW style. Adding that to the class that I provided
seems to work, at least on Windows...
- Josiah
import wx
class drawover(wx.Window):
def __init__(self, parent):
wx.Window.__init__(self, parent, style=wx.TRANSPARENT_WINDOW)
self.Bind(wx.EVT_PAINT, self.OnPaint)
self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnErase)
self.Bind(wx.EVT_SET_FOCUS, self.OnFocus)
wx.FutureCall(100, self.callrefresh)
def callrefresh(self):
self.Refresh()
wx.FutureCall(100, self.callrefresh)
def OnFocus(self, evt):
self.GetParent().SetFocus()
def OnErase(self, evt):
pass
def OnPaint(self, evt):
dc = wx.PaintDC(self)
dc.BeginDrawing()
dc.SetPen(wx.Pen("RED", 1))
size = self.GetSize()
dc.DrawLine(0, 0, size[0], size[1])
dc.DrawLine(size[0], 0, 0, size[1])
dc.EndDrawing()
class frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, size=(600,600))
s = wx.BoxSizer(wx.VERTICAL)
self.tc1 = wx.TextCtrl(self, style=wx.TE_MULTILINE)
s.Add(self.tc1, 1, wx.EXPAND)
self.tc2 = wx.TextCtrl(self, style=wx.TE_MULTILINE)
s.Add(self.tc2, 1, wx.EXPAND)
self.d = drawover(self.tc2)
self.tc2.Bind(wx.EVT_SIZE, self.OnSize2)
self.SetSizer(s)
self.Layout()
def OnSize2(self, evt):
self.d.SetSize(self.tc2.GetSize())
evt.Skip()
if __name__ == '__main__':
a = wx.App(0)
b = frame()
b.Show(1)
a.MainLoop()
···
"Dusty Phillips" <buchuki@gmail.com> wrote: