from wxPython.wx import *
from wxPython.ogl import *
+import images
+
#----------------------------------------------------------------------
# This creates some pens and brushes that the OGL library uses.
#----------------------------------------------------------------------
-## class LabeledBitmapShape(wxBitmapShape):
-## def __init__(self, bmp, text):
-## wxBitmapShape.__init__(self)
-## self.SetBitmap(bmp)
-## self.region = r = wxShapeRegion()
-## r.SetPosition(0, 0) #bmp.GetHeight())
-## r.SetSize(bmp.GetWidth(), bmp.GetHeight())
-## r.SetText(text)
-## self.AddRegion(r)
+class DividedShape(wxDividedShape):
+ def __init__(self, width, height, canvas):
+ wxDividedShape.__init__(self, width, height)
+
+ region1 = wxShapeRegion()
+ region1.SetText('wxDividedShape')
+ region1.SetProportions(0.0, 0.2)
+ region1.SetFormatMode(FORMAT_CENTRE_HORIZ)
+ self.AddRegion(region1)
+
+ region2 = wxShapeRegion()
+ region2.SetText('This is Region number two.')
+ region2.SetProportions(0.0, 0.3)
+ region2.SetFormatMode(FORMAT_CENTRE_HORIZ|FORMAT_CENTRE_VERT)
+ self.AddRegion(region2)
-## def OnMovePost(self, dc, x, y, old_x, old_y, display):
-## self.region.SetPosition(x, y)
-## self.base_OnMovePost(dc, x, y, old_x, old_y, display)
+ region3 = wxShapeRegion()
+ region3.SetText('Region 3\nwith embedded\nline breaks')
+ region3.SetProportions(0.0, 0.5)
+ region3.SetFormatMode(FORMAT_NONE)
+ self.AddRegion(region3)
+ self.SetRegionSizes()
+ self.ReformatRegions(canvas)
-## class LabeledBitmapShape(wxCompositeShape):
-## def __init__(self, canvas, bmp, text):
-## wxCompositeShape.__init__(self)
-## self.bs = wxBitmapShape()
-## self.bs.SetBitmap(bmp)
-## self.ts = wxTextShape()
-## self.ts.AddText(text)
-## self.AddChild(self.bs)
-## self.AddChild(self.ts, self.bs)
+ def ReformatRegions(self, canvas=None):
+ rnum = 0
+ if canvas is None:
+ canvas = self.GetCanvas()
+ dc = wxClientDC(canvas) # used for measuring
+ for region in self.GetRegions():
+ text = region.GetText()
+ self.FormatText(dc, text, rnum)
+ rnum += 1
-## self.AddConstrainedShapes(gyCONSTRAINT_CENTRED_VERTICALLY, self, [self.bs, self.ts])
-## self.AddSimpleConstraint(gyCONSTRAINT_BELOW, self.bs, self.ts)
-## self.AddSimpleConstraint(gyCONSTRAINT_ALIGNED_TOP, self, self.bs)
-## self.AddSimpleConstraint(gyCONSTRAINT_ALIGNED_BOTTOM, self, self.ts)
+
+ def OnSizingEndDragLeft(self, pt, x, y, keys, attch):
+ self.base_OnSizingEndDragLeft(pt, x, y, keys, attch)
+ self.SetRegionSizes()
+ self.ReformatRegions()
+ self.GetCanvas().Refresh()
#----------------------------------------------------------------------
def OnLeftClick(self, x, y, keys = 0, attachment = 0):
shape = self.GetShape()
+ print shape.__class__
canvas = shape.GetCanvas()
dc = wxClientDC(canvas)
canvas.PrepareDC(dc)
if shape.Selected():
- shape.Select(false, dc)
+ shape.Select(False, dc)
canvas.Redraw(dc)
else:
- redraw = false
+ redraw = False
shapeList = canvas.GetDiagram().GetShapeList()
toUnselect = []
for s in shapeList:
# shapes too!) and bad things will happen...
toUnselect.append(s)
- shape.Select(true, dc)
+ shape.Select(True, dc)
if toUnselect:
for s in toUnselect:
- s.Select(false, dc)
+ s.Select(False, dc)
canvas.Redraw(dc)
self.UpdateStatusBar(shape)
self.UpdateStatusBar(shape)
- def OnSize(self, x, y):
- self.base_OnSize(x, y)
+ def OnSizingEndDragLeft(self, pt, x, y, keys, attch):
+ self.base_OnSizingEndDragLeft(pt, x, y, keys, attch)
self.UpdateStatusBar(self.GetShape())
-# def OnMovePost(self, dc, x, y, oldX, oldY, display):
-# self.base_OnMovePost(dc, x, y, oldX, oldY, display)
-# self.UpdateStatusBar(self.GetShape())
+ def OnMovePost(self, dc, x, y, oldX, oldY, display):
+ self.base_OnMovePost(dc, x, y, oldX, oldY, display)
+ self.UpdateStatusBar(self.GetShape())
def OnRightClick(self, *dontcare):
self.log = log
self.frame = frame
- self.SetBackgroundColour(wxWHITE)
+ self.SetBackgroundColour("LIGHT BLUE") #wxWHITE)
self.diagram = wxDiagram()
self.SetDiagram(self.diagram)
self.diagram.SetCanvas(self)
self.shapes = []
self.save_gdi = []
- rRectBrush = wxBrush(wxNamedColour("MEDIUM TURQUOISE"), wxSOLID)
+ rRectBrush = wxBrush("MEDIUM TURQUOISE", wxSOLID)
+ dsBrush = wxBrush("WHEAT", wxSOLID)
self.MyAddShape(wxCircleShape(80), 100, 100, wxPen(wxBLUE, 3), wxGREEN_BRUSH, "Circle")
self.MyAddShape(wxRectangleShape(85, 50), 305, 60, wxBLACK_PEN, wxLIGHT_GREY_BRUSH, "Rectangle")
+ ds = self.MyAddShape(DividedShape(140, 150, self), 495, 145, wxBLACK_PEN, dsBrush, '')
self.MyAddShape(DiamondShape(90, 90), 345, 235, wxPen(wxBLUE, 3, wxDOT), wxRED_BRUSH, "Polygon")
- self.MyAddShape(RoundedRectangleShape(95,70), 140, 255, wxPen(wxRED, 1), rRectBrush, "Rounded Rect")
+ self.MyAddShape(RoundedRectangleShape(95,70), 140, 255, wxPen(wxRED, 2), rRectBrush, "Rounded Rect")
- bmp = wxBitmap('bitmaps/test2.bmp', wxBITMAP_TYPE_BMP)
+ bmp = images.getTest2Bitmap()
mask = wxMaskColour(bmp, wxBLUE)
bmp.SetMask(mask)
-## s = LabeledBitmapShape(self, bmp, "Hello")
-## self.MyAddShape(s, 225, 150, None, None, None)
-## print s.Recompute()
-## s.CalculateSize()
-## print s.GetX(), s.GetY()
-## s.SetSize(225)
-## s.SetY(150)
-## s.SetSize(80, 80)
-## print s.GetX(), s.GetY()
-## #print s.GetSize()
s = wxBitmapShape()
s.SetBitmap(bmp)
line.MakeLineControlPoints(2)
fromShape.AddLine(line, toShape)
self.diagram.AddShape(line)
- line.Show(true)
+ line.Show(True)
# for some reason, the shapes have to be moved for the line to show up...
fromShape.Move(dc, fromShape.GetX(), fromShape.GetY())
+ EVT_WINDOW_DESTROY(self, self.OnDestroy)
def MyAddShape(self, shape, x, y, pen, brush, text):
- shape.SetDraggable(true, true)
+ shape.SetDraggable(True, True)
shape.SetCanvas(self)
shape.SetX(x)
shape.SetY(y)
if text: shape.AddText(text)
#shape.SetShadowMode(SHADOW_RIGHT)
self.diagram.AddShape(shape)
- shape.Show(true)
+ shape.Show(True)
evthandler = MyEvtHandler(self.log, self.frame)
evthandler.SetShape(shape)
shape.SetEventHandler(evthandler)
self.shapes.append(shape)
+ return shape
-
- def __del__(self):
+ def OnDestroy(self, evt):
+ # Do some cleanup
for shape in self.diagram.GetShapeList():
if shape.GetParent() == None:
shape.SetCanvas(None)
shape.Destroy()
+ self.diagram.Destroy()
+
+
+ def OnBeginDragLeft(self, x, y, keys):
+ self.log.write("OnBeginDragLeft: %s, %s, %s\n" % (x, y, keys))
+
+ def OnEndDragLeft(self, x, y, keys):
+ self.log.write("OnEndDragLeft: %s, %s, %s\n" % (x, y, keys))
#----------------------------------------------------------------------
"""
+
+if __name__ == '__main__':
+ import sys,os
+ import run
+ run.main(['', os.path.basename(sys.argv[0])])
+