I'm looking for a window that will incrementally add text strings with
out keeping track of them all. (i.e. I want to use the display frame
buffer as my display memory.) In the program below, additional text
strings to be displayed come in whenever the mouse is clicked as
fgColor:wxBLUE, bgColor:wxWHITE, X:100, Y:200, text: "Clicked Here".
Unfortunately, I can't seem to stop the window erase on an EVT_PAINT
event, and therefore lose all the prior text strings that were
displayed. I trapped the EVT_ERASE_BACKGROUND event but could not
prevent the window erasing.
Also the SetTextBackground method of wxDC does not seem to do anything.
I have included a little test program to demonstrate my dilemma
COLORLIST = [wxBLUE, wxRED, wxBLACK, wxGREEN]
DEFAULT_FORECOLOR = COLORLIST[0]
DEFAULT_BACKCOLOR = COLORLIST[0]
class MBDisplay(wxWindow):
def __init__(self, parent, id,
pos=wxDefaultPosition,size=wxDefaultSize):
wxWindow.__init__(self, parent, id, pos, size)
self.SetBackgroundColour(wxNamedColour('white'))
self.font = wxFont(12, wxMODERN, wxNORMAL,
wxNORMAL,faceName='courier')
EVT_PAINT(self, self.OnPaint)
EVT_ERASE_BACKGROUND(self, self.eraseBackground)
EVT_LEFT_DOWN(self, self.OnClick)
self.random = whrandom.whrandom()
# INFO FOR MAKING THE TEXT DISPLAY, UPDATED WHEN MOUSE IS CLICKED
self.drawInfo = (DEFAULT_BACKCOLOR, DEFAULT_FORECOLOR,
100, 100, "In the beginning")
def Draw(self, dc = None):
if not dc:
dc = wxClientDC(self)
dc.SetFont(self.font)
xPos = self.drawInfo[2]
yPos = self.drawInfo[3]
textSize = dc.GetTextExtent(self.drawInfo[4])
dc.SetClippingRegion(xPos, yPos, textSize[0],
textSize[1])
dc.Clear()
dc.SetTextForeground(self.drawInfo[1])
# THIS LINE DOES NOT SEEM TO DO ANYTHING
dc.SetTextBackground(self.drawInfo[0])
dc.DrawText(self.drawInfo[4], xPos, yPos)
def OnPaint(self, event):
# WHEN THIS GETS CALLED WINDOW GETS ERASED
dc = wxPaintDC(self)
self.Draw(dc)
print 'OnPaint called'
def eraseBackground(self, event):
# GETS CALLED BUT DOES NOT SEEM TO STOP THE WINDOW
ERASE
print 'eraseBackground called'
return TRUE
# event.Skip()
def OnClick(self, event):
x = event.GetX()
y = event.GetY()
# pick random colors for text and background
bgNum = self.random.randint(0, len(COLORLIST) - 1)
fgNum = self.random.randint(0, len(COLORLIST) - 1)
bgColor = COLORLIST[bgNum]
fgColor = COLORLIST[fgNum]
self.drawInfo = (bgColor, fgColor, x, y, "Clicked Here")
self.Draw()
class MBDisplayFrame(wxFrame):
def __init__(self, parent, id, title):
self.id = id
# First, call the base class' __init__ method to create
the frame
wxFrame.__init__(self, parent, id, title, wxPoint(100,
100), wxSize(645, 485))
# EVT_ERASE_BACKGROUND(self, self.eraseBackground)
# create window
wid = NewId()
self.mbd = MBDisplay(self,wid)
def eraseBackground(self, event):
print 'Frame eraseBackground called'
# event.Skip()
# return FALSE
def OnCloseWindow(self,event):
self.Destroy()
class MyApp(wxApp):
def OnInit(self):
mbDisplay = MBDisplayFrame(NULL, -1, 'Display window')
mbDisplay.Show(true)
self.SetTopWindow(mbDisplay)
return true
if __name__ == "__main__":
app = MyApp(0) # Create an instance of the application class
app.MainLoop() # Tell it to start processing events
Patrick Gaffney
patrickg@asti-usa.com
···
_______________________________________________
wxPython-users mailing list
wxPython-users@lists.sourceforge.net
http://lists.sourceforge.net/mailman/listinfo/wxpython-users