John,
You've got an indentation problem.
def DrawLines(self, dc):
""" Redraw all lines that have been recorded """
dc.BeginDrawing()
x = 214
y = 54
for colour, thickness, line in self.lines:
pen = wx.Pen(wx.NamedColour(colour), thickness, self.linestyle)
dc.SetPen(pen)
for coords in line:
apply(dc.DrawLine, coords)
# Too much indentation starting here! This should NOT be under the
"for" statement
font = wx.Font(14, wx.ROMAN, wx.NORMAL, wx.NORMAL)
dc.SetFont(font)
colour = [('Red', 0x0000ff), ('Green', 0x00ff00), ('Blue',0xff0000),
('DarkRed', 0x000099), ('DarkGreen', 0x009900), ('DarkBlue',0x990000)]
#0x00bbggrr
for (text, col) in colour:
thisColour = wx.ColourRGB(col)
text = "%s: 0x%06x = (%d, %d, %d)" % (text, col,thisColour.Red(),
thisColour.Green(), thisColour.Blue())
dc.SetTextForeground(thisColour)
dc.DrawText(text, x, y)
y = y + 20
dc.EndDrawing()
You'll note that self.lines is empty () and that the "for" loop that draws
the lines doesn't get called because there are no lines to draw. (I
should've deleted that code from my example.)
Just for fun, replace
self.lines=
in the "__init__ " method with:
self.lines =
tempLine =
tempLine.append((200, 20, 780, 20))
tempLine.append((780, 20, 780, 520))
tempLine.append((780, 520, 200, 520))
tempLine.append((200, 520, 200, 20))
self.lines.append((self.colour, self.thickness, tempLine))
Then you'll get a black box around the list of colors.
David
···
-----Original Message-----
From: John Fabiani [mailto:jfabiani@yolo.com]
Sent: Sunday, December 12, 2004 11:08 AM
To: wxPython-users@lists.wxwidgets.org
Subject: Re: [wxPython-users] Color ProblemsOn Sunday 12 December 2004 00:32, Robin Dunn wrote:
> 0x00bbggrrOk even after changing the color=hex I get nothing. below is my code.
What's wrong I get no drawing....
Johnimport wx
class MainWindow(wx.Frame):
""" This window displays a variety of GUI Widgets. """
def __init__(self,parent,id,title):
wx.Frame.__init__(self,parent,-1, title, size =
(800,600),style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
self.SetBackgroundColour(wx.WHITE)
# Messing About with Graphics
self.colour = "BLACK"
self.thickness = 1
self.linestyle = wx.SOLID
self.pen = wx.Pen(wx.NamedColour(self.colour),
self.thickness,self.linestyle)
self.lines =
self.InitBuffer()# Resize Event
wx.EVT_SIZE(self, self.OnSize)
# Idle event (draws when idle to prevent multiple redraws)
wx.EVT_IDLE(self, self.OnIdle)
# Refresh Event
wx.EVT_PAINT(self, self.OnPaint)
self.Show(True)
self.reInitBuffer = Truedef InitBuffer(self):
""" Initialize the Bitmap used for buffering the display """
size = self.GetClientSize()
self.buffer = wx.EmptyBitmap(size.width, size.height)
dc = wx.BufferedDC(None, self.buffer)
dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
dc.Clear()
self.DrawLines(dc)
self.reInitBuffer = Falsedef DrawLines(self, dc):
""" Redraw all lines that have been recorded """
dc.BeginDrawing()
x = 214
y = 54
for colour, thickness, line in self.lines:
pen = wx.Pen(wx.NamedColour(colour), thickness, self.linestyle)
dc.SetPen(pen)
for coords in line:
apply(dc.DrawLine, coords)
font = wx.Font(14, wx.ROMAN, wx.NORMAL, wx.NORMAL)
dc.SetFont(font)
colour = [('Red', 0x0000ff), ('Green', 0x00ff00),
('Blue',0xff0000),
('DarkRed', 0x000099), ('DarkGreen', 0x009900), ('DarkBlue',0x990000)]
#0x00bbggrr
for (text, col) in colour:
thisColour = wx.ColourRGB(col)
text = "%s: 0x%06x = (%d, %d, %d)" % (text, col,thisColour.Red(),
thisColour.Green(), thisColour.Blue())
dc.SetTextForeground(thisColour)
dc.DrawText(text, x, y)
y = y + 20dc.EndDrawing()
def OnSize(self, event):
self.reInitBuffer = Truedef OnIdle(self, event):
if self.reInitBuffer:
self.InitBuffer()
self.Refresh(False)def OnPaint(self, event):
dc = wx.BufferedPaintDC(self, self.buffer)class MyApp(wx.App):
def OnInit(self):
global frame
frame = MainWindow(None, -1, "Color Test")
self.SetTopWindow(frame)
return Trueapp = MyApp(0)
app.MainLoop()---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org