hi,
thanks robin for your reply last time.the centre is indeed the origin of an OGL object. my code has improved considerably but there is still a small problem. the resizers are appearing with the object having its top-left at their centre.i wanted to know if i could some how get the resizers to overlap with the object.i am sending along the code.
sandy.
···
****************************************************
import os
from wxPython.wx import *
from wxPython.ogl import *
wxOGLInitialize()
class UnitOp(wxDrawnShape):
def __init__(self,flag,nam):
wxDrawnShape.__init__(self)
self.default = [] #default size of the unitop in terms of maximum x and y co-ords
#loop to read in co-ords for straight lines in terms of percentage deviation from the default co-ords read earlier
self.straightLine = [ [] * 2 for k in range(5)] #buffer to hold straight line co-ords
self.name = nam
def GetMaxHeight(self):
return self.default[1]
def GetMaxWidth(self):
return self.default[0]
def CreateDiagram(self,origin):
for j in range(0,len(self.straightLine)-1,1):
newPoint1 = wxPoint(int((self.straightLine[j][0].x / 100.0) * self.default[0]) ,int((self.straightLine[j][0].y / 100.0)* self.default[1]) )
newPoint2 = wxPoint(int((self.straightLine[j][1].x / 100.0) * self.default[0]) ,int((self.straightLine[j][1].y / 100.0)* self.default[1]) )
self.DrawLine(newPoint1,newPoint2)
textPoint = wxPoint(0, self.default[1] + 4)
self.DrawText(self.name,textPoint)
self.SetDraggable(true, true)
self.SetCentreResize(false)
rect = wxRect(origin.x + self.default[0],origin.y + self.default[1])
#self.SetDefaultRegionSize()
self.CalculateSize()
#self.SetClippingRect(rect)
#self.SetX(origin.x + self.default[0])
#self.SetY(origin.y + self.default[1])
self.SetX(origin.x)#sets the top-left of the object in the screen
self.SetY(origin.y)
class palette(wxShapeCanvas):
def __init__(self, parent):
wxShapeCanvas.__init__(self, parent)
self.maxWidth = 200
self.maxHeight = 700
self.SetScrollbars(20, 20, self.maxWidth/20, self.maxHeight/20)
self.SetBackgroundColour("WHITE")
self.buffer = []
self.diagram = wxDiagram()
self.frame = parent
siz = (212,720)
self.frame.SetSize(siz)
self.frame.Show(true)
self.SetDiagram(self.diagram)
self.diagram.SetCanvas(self)
EVT_WINDOW_DESTROY(self, self.OnDestroy)
self.listOfUnitOp = []
i = 0
#create three dummy unitops
#first one
uop = UnitOp(1,"UOP1")
uop.default.append(40)
j = 0
uop.straightLine[j].append(wxPoint(0,0))
uop.straightLine[j].append(wxPoint(0,100))
j = j + 1
uop.straightLine[j].append(wxPoint(100,0))
uop.straightLine[j].append(wxPoint(100,100))
j = j + 1
uop.straightLine[j].append(wxPoint(0,0))
uop.straightLine[j].append(wxPoint(100,0))
j = j + 1
uop.straightLine[j].append(wxPoint(0,100))
uop.straightLine[j].append(wxPoint(100,100))
j = j + 1
uop.straightLine[j].append(wxPoint(0,100))
uop.straightLine[j].append(wxPoint(100,0))
self.listOfUnitOp.append(uop)
i = i + 1
#second one
uop = UnitOp(0,"UOP2")
uop.default.append(50)
j = 0
uop.straightLine[j].append(wxPoint(0,0))
uop.straightLine[j].append(wxPoint(0,100))
j = j + 1
uop.straightLine[j].append(wxPoint(100,0))
uop.straightLine[j].append(wxPoint(100,100))
j = j + 1
uop.straightLine[j].append(wxPoint(0,0))
uop.straightLine[j].append(wxPoint(100,0))
j = j + 1
uop.straightLine[j].append(wxPoint(0,100))
uop.straightLine[j].append(wxPoint(100,100))
if self.listOfUnitOp[0].GetMaxHeight() > uop.GetMaxHeight():
self.listOfUnitOp. insert(0,uop)
else:
self.listOfUnitOp.append(uop)
i = i + 1
#third one
uop = UnitOp(0,"UOP3")
uop.default.append(35)
uop.default.append(70)
j = 0
uop.straightLine[j].append(wxPoint(0,0))
uop.straightLine[j].append(wxPoint(0,100))
j = j + 1
uop.straightLine[j].append(wxPoint(100,0))
uop.straightLine[j].append(wxPoint(100,100))
j = j + 1
uop.straightLine[j].append(wxPoint(0,0))
uop.straightLine[j].append(wxPoint(100,0))
j = j + 1
uop.straightLine[j].append(wxPoint(0,100))
uop.straightLine[j].append(wxPoint(100,100))
if self.listOfUnitOp[0].GetMaxHeight() > uop.GetMaxHeight():
self.listOfUnitOp. insert(0,uop)
elif self.listOfUnitOp[1].GetMaxHeight() > uop.GetMaxHeight():
self.listOfUnitOp.insert(1,uop)
else:
self.listOfUnitOp.append(uop)
curx = 0 # x,y co-ords where the current unitop will be placed
cury = 10
maxy = 10
for j in range(len(self.listOfUnitOp)):
if(curx + self.listOfUnitOp[j].GetMaxWidth() + 10 > self.maxWidth):
curx = 10
cury = maxy + 10
else:
curx = curx + 10
#print curx, cury, maxy
self.AddUnitOp(self.listOfUnitOp[j],curx,cury,wxBLACK_PEN)
maxy = cury + self.listOfUnitOp[j].GetMaxHeight()
curx = curx + self.listOfUnitOp[j].GetMaxWidth()
def AddUnitOp(self, shape, x, y, pen, brush = None, text = None):
origin = wxPoint( x,y )
shape.CreateDiagram(origin)
shape.SetCanvas(self)
if pen: shape.SetPen(pen)
if brush: shape.SetBrush(brush)
if text: shape.AddText(text)
self.diagram.AddShape(shape)
shape.Show(true)
evthandler = MyEvtHandler(self.frame)
evthandler.SetShape(shape)
evthandler.SetPreviousHandler(shape.GetEventHandler())
shape.SetEventHandler(evthandler)
def OnLeftClick(self,x,y,key):
shapelist = self.GetDiagram().GetShapeList()
toUnselect = []
dc = wxClientDC(self)
self.PrepareDC(dc)
for s in shapelist:
if s.Selected():
toUnselect.append(s)
if toUnselect:
for s in toUnselect:
s.Select(false, dc)
self.Redraw(dc)
self.Refresh()
def OnDestroy(self, evt):
for shape in self.diagram.GetShapeList():
if shape.GetParent() == None:
shape.SetCanvas(None)
shape.Destroy()
self.diagram.Destroy()
class MyEvtHandler(wxShapeEvtHandler):
def __init__(self, frame):
wxShapeEvtHandler.__init__(self)
def OnLeftClick(self, x, y, keys = 0, attachment = 0):
shape = self.GetShape()
canvas = shape.GetCanvas()
dc = wxClientDC(canvas)
canvas.PrepareDC(dc)
if shape.Selected():
shape.Select(false, dc)
canvas.Redraw(dc)
else:
redraw = false
shapeList = canvas.GetDiagram().GetShapeList()
toUnselect = []
for s in shapeList:
if s.Selected():
toUnselect.append(s)
shape.Select(true, dc)
if toUnselect:
for s in toUnselect:
s.Select(false, dc)
canvas.Redraw(dc)
canvas.Refresh()
def OnEndDragLeft(self, x, y, keys = 0, attachment = 0):
shape = self.GetShape()
self.base_OnEndDragLeft(x, y, keys, attachment)
if not shape.Selected():
self.OnLeftClick(x, y, keys, attachment)
shape.GetCanvas().Refresh()
def OnSizingEndDragLeft(self, pt, x, y, keys, attch):
self.base_OnSizingEndDragLeft(pt, x, y, keys, attch)
shape = self.GetShape()
self.GetShape().GetCanvas().Refresh()
def OnMovePost(self, dc, x, y, oldX, oldY, display):
self.base_OnMovePost(dc, x, y, oldX, oldY, display)
shape = self.GetShape()
self.GetShape().GetCanvas().Refresh()
class test(wxFrame):
def __init__(self,parent):
wxFrame.__init__(self, parent, -1, "Vector diagrams", pos = (0,0), size=(212,720), style=wxDEFAULT_FRAME_STYLE | wxNO_FULL_REPAINT_ON_RESIZE)
self.pal = palette(self)
def dele(self):
self.pal.destroy(true)
class MyApp(wxApp):
def OnInit(self):
t = test(None)
return true
app = MyApp()
app.MainLoop()
**********************************************************************