annotate scripts-java/visualizer/test.py @ 117:fce61ee25d20

run FederatedLinda experiment on torque
author kazz
date Wed, 08 Feb 2012 18:02:00 +0900
parents 1809e2b05824
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
1 from wxPython.wx import *
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
2 from wxPython.ogl import *
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
3
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
4 #wxOGLInitialize()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
5
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
6
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
7 class MyEvtHandler(wxShapeEvtHandler):
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
8 """
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
9 Overwrite the default event handler to implement some custom features.
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
10 """
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
11 def __init__(self):
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
12 wxShapeEvtHandler.__init__(self)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
13
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
14 def OnLeftClick(self, x, y, keys = 0, attachment = 0):
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
15 """
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
16 The dragging is done here.
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
17 You should probably comment out the EVT_MOTION below, to see it work.
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
18 """
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
19 shape = self.GetShape()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
20 print shape.__class__, shape.GetClassName(), shape.a
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
21 canvas = shape.GetCanvas()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
22 dc = wxClientDC(canvas)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
23 canvas.PrepareDC(dc)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
24
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
25 if shape.Selected():
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
26 shape.Select(False, dc)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
27 canvas.Redraw(dc)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
28 else:
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
29 redraw = False
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
30 shapeList = canvas.GetDiagram().GetShapeList()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
31 toUnselect = []
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
32 for s in shapeList:
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
33 if s.Selected():
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
34 toUnselect.append(s)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
35
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
36 shape.Select(True, dc)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
37
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
38 if toUnselect:
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
39 for s in toUnselect:
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
40 s.Select(False, dc)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
41 canvas.Redraw(dc)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
42
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
43
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
44 class OGLCanvas(wxShapeCanvas):
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
45 def __init__(self, parent, frame):
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
46 wxShapeCanvas.__init__(self, parent)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
47
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
48 self.SetBackgroundColour("LIGHT BLUE")
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
49 self.diagram = wxDiagram()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
50 self.SetDiagram(self.diagram)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
51 self.diagram.SetCanvas(self)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
52
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
53 self.circle = wxCircleShape(100)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
54 self.circle.SetCanvas(self)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
55 self.circle.a="Circle identified"
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
56 self.diagram.AddShape(self.circle)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
57 self.circle.Show(True)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
58
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
59 self.evthandler = MyEvtHandler()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
60 self.evthandler.SetShape(self.circle)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
61 self.evthandler.SetPreviousHandler(self.circle.GetEventHandler())
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
62 self.circle.SetEventHandler(self.evthandler)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
63
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
64 EVT_MOTION(self, self.OnMotion)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
65
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
66 def OnMotion(self, event):
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
67 shape = self.evthandler.GetShape()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
68
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
69 bx = shape.GetX()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
70 by = shape.GetY()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
71 bw, bh = shape.GetBoundingBoxMax()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
72 oldrect = wxRect(int(bx-bw/2)-1, int(by-bh/2)-1, int(bw)+2, int(bh)+2)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
73
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
74 canvas = shape.GetCanvas()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
75 dc = wxClientDC(canvas)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
76 canvas.PrepareDC(dc)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
77
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
78 shape.Move(dc, event.GetPosition()[0], event.GetPosition()[1])
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
79 canvas.Refresh(False, oldrect)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
80 event.Skip()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
81
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
82
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
83 class OGLFrame(wxFrame):
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
84 def __init__(self, *args, **kwds):
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
85 wxFrame.__init__(self, *args, **kwds)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
86
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
87 self.SetTitle("OGL TEST")
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
88 self.SetBackgroundColour(wxColour(8, 197, 248))
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
89 self.canvas = OGLCanvas(self, self)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
90
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
91 class Main(wxApp):
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
92 def OnInit(self):
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
93 wxInitAllImageHandlers()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
94 frame = OGLFrame(None, -1, "")
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
95 self.SetTopWindow(frame)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
96 frame.Show(True)
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
97 return True
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
98
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
99 if __name__ == "__main__":
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
100 app = Main()
1809e2b05824 Initial revision
fuchita
parents:
diff changeset
101 app.MainLoop()