Hey Peoples,
I'm very new to wxPython and I'm having a play around. But like usual
I have encountered may problems.
If anyone can help I would be very grateful.
The ControlPanel class is a panel down the left side where the user
selects what they want. When they press the button I want a shape to
be drawn on the canvas. But this never happens.
The DrawWindow class is the canvas class with a shape already on it
and a function called InsertShape which as it says inserts a shape
onto the canvas when called.
The code is :-
···
##########################################
class ControlPanel(wx.Panel):
def __init__(self, parent, ID, canvasBoard):
wx.Panel.__init__(self, parent, ID, style=wx.RAISED_BORDER, size=(20,20))
numCols = 2
spacing = 4
# Make a grid of buttons for each colour. Attach each button
# event to self.OnSetColour. The button ID is the same as the
# key in the colour dictionary.
box = wx.BoxSizer(wx.VERTICAL)
b = wx.Button(self, 20, "Shape", (20, 80))
self.Bind(wx.EVT_BUTTON, self.OnMake, b)
box.Add(b, 0, wx.ALL, spacing)
# Other buttons
self.SetSizer(box)
self.SetAutoLayout(True)
box.Fit(self)
def OnMake(self,event):
canvasBoard.DrawWindow.InsertShape()
event.Skip()
#----------------------------------------------------------------------
class DrawWindow(ogl.ShapeCanvas):
def __init__(self, parent, id = -1, size = wx.DefaultSize):
ogl.ShapeCanvas.__init__(self, parent, id, (0, 0), size=size,
style=wx.SUNKEN_BORDER)
self.lines = []
self.maxWidth = 1000
self.maxHeight = 1000
self.x = self.y = 0
self.drawing = False
self.shapes = []
self.SetBackgroundColour("Light Blue")
self.SetScrollbars(20, 20, self.maxWidth/20, self.maxHeight/20)
self.diagram = ogl.Diagram()
self.SetDiagram( self.diagram )
self.diagram.SetCanvas( self )
#########################
#Test Shape
#########################
shape = ogl.CircleShape(80)
shape.SetDraggable(True, True)
shape.SetCanvas(self)
shape.SetX(200)
shape.SetY(200)
shape.SetPen(wx.Pen(wx.BLUE,2))
shape.SetBrush(wx.GREEN_BRUSH)
self.diagram.AddShape(shape)
shape.Show(True)
def InsertShape(self):
shape = ogl.CircleShape(80)
shape.SetDraggable(True, True)
shape.SetCanvas(self)
shape.SetX(200)
shape.SetY(200)
shape.SetPen(wx.Pen(wx.RED,2))
shape.SetBrush(wx.BLACK_BRUSH)
self.diagram.AddShape(shape)
shape.Show(True)
#########################################
Thankyou for your time
Cheers
Naeill