I know this might be the wrong place to ask but I recently modified
the ogl example from wxpython and it works fine in spe but when I call
it from other programs it wierds out because of the run.py thing they
have set it up with doesn't work when I call it from an external
program (including .bat files). when I call it outside of spe I
manage to just get a box without the tracker part. It is so close to
out right theft I was hopeing I could just tweek something to make it
work for me. Any help would be apreciated (I am trying to call it with
tracker.py bay-at-night.csd )
#!/usr/bin/env python
#----------------------------------------------------------------------------
# Name: run.py
# Purpose: Simple framework for running individual demos
#
# Author: Robin Dunn
#
# Created: 6-March-2000
# RCS-ID: $Id: run.py,v 1.29.2.1 2006/01/26 00:33:39 RD Exp $
# Copyright: (c) 2000 by Total Control Software
# Licence: wxWindows license
#----------------------------------------------------------------------------
"""
This program will load and run one of the individual demos in this
directory within its own frame window. Just specify the module name
on the command line.
"""
import wx # This module uses the new wx namespace
import sys, os
# stuff for debugging
print "wx.VERSION_STR ING = %s (%s)" % (wx.VERSION_STR ING,
wx.USE_UNICODE and 'unicode' or 'ansi')
print "pid:", os.getpid()
##raw_input("Pr ess Enter...")
assertMode = wx.PYAPP_ASSERT _DIALOG
##assertMode = wx.PYAPP_ASSERT _EXCEPTION
#----------------------------------------------------------------------------
class Log:
def WriteText(self, text):
if text[-1:] == '\n':
text = text[:-1]
wx.LogMessage(t ext)
write = WriteText
class RunDemoApp(wx.A pp):
def __init__(self, name, module, useShell):
self.name = name
self.demoModule = module
self.useShell = useShell
wx.App.__init__ (self, redirect=False)
def OnInit(self):
wx.Log_SetActiv eTarget(wx.LogS tderr())
self.SetAssertM ode(assertMode)
frame = wx.Frame(None, -1, "RunDemo: " + self.name,
pos=(50,50), size=(200,100),
style=wx.DEFAUL T_FRAME_STYLE)
frame.CreateSta tusBar()
menuBar = wx.MenuBar()
menu = wx.Menu()
item = menu.Append(-1, "E&xit\tAlt-X", "Exit demo")
self.Bind(wx.EV T_MENU, self.OnExitApp, item)
menuBar.Append( menu, "&File")
ns = {}
ns['wx'] = wx
ns['app'] = self
ns['module'] = self.demoModule
ns['frame'] = frame
frame.SetMenuBa r(menuBar)
frame.Show(True )
frame.Bind(wx.E VT_CLOSE, self.OnCloseFra me)
win = self.demoModule .runTest(frame, frame, Log())
# a window will be returned if the demo does not create
# its own top-level window
if win:
# so set the frame to a good size for showing stuff
frame.SetSize(( 640, 480))
win.SetFocus()
self.window = win
ns['win'] = win
frect = frame.GetRect()
else:
# It was probably a dialog or something that is already
# gone, so we're done.
frame.Destroy()
return True
self.SetTopWind ow(frame)
self.frame = frame
#wx.Log_SetActi veTarget(wx.Log Stderr())
#wx.Log_SetTrac eMask(wx.TraceM essages)
if self.useShell:
# Make a PyShell window, and position it below our test
window
from wx import py
shell = py.shell.ShellF rame(None, locals=ns)
frect.OffsetXY( 0, frect.height)
frect.height = 400
shell.SetRect(f rect)
shell.Show()
# Hook the close event of the test window so that we close
# the shell at the same time
def CloseShell(evt) :
if shell:
shell.Close()
evt.Skip()
frame.Bind(wx.E VT_CLOSE, CloseShell)
return True
def OnExitApp(self, evt):
self.frame.Clos e(True)
def OnCloseFrame(se lf, evt):
if hasattr(self, "window") and hasattr(self.wi ndow,
"ShutdownDemo") :
self.window.Shu tdownDemo()
evt.Skip()
#----------------------------------------------------------------------------
def main(argv):
useShell = False
for x in range(len(sys.a rgv)):
if sys.argv[x] in ['--shell', '-shell', '-s']:
useShell = True
del sys.argv[x]
break
if len(argv) < 2:
print "Please specify a demo module name on the command-line"
raise SystemExit
name, ext = os.path.splitex t(argv[1])
module = __import__(name )
app = RunDemoApp(name , module, useShell)
app.MainLoop()
if __name__ == "__main__":
main(sys.argv)
# -*- coding: iso-8859-1 -*-
# 11/20/2003 - Jeff Grimmett (gr********@sof thome.net)
#
# o Updated for wx namespace
#
# 20040508 - Pierre Hjälm
#
# o Changed to use the python version of OGL
# o Added TextShape, CompositeShape and CompositeShape with divisions
#
# 20040830 - Pierre Hjälm
#
# o Added DrawnShape
#
import wx
import wx.lib.ogl as ogl
import csoundroutines
import sys
#import images
#----------------------------------------------------------------------
class DrawnShape(ogl. DrawnShape):
def __init__(self):
ogl.DrawnShape. __init__(self)
self.SetDrawnBr ush(wx.WHITE_BR USH)
self.SetDrawnPe n(wx.BLACK_PEN)
self.DrawArc((0 , -10), (30, 0), (-30, 0))
self.SetDrawnPe n(wx.Pen("#ff80 30"))
self.DrawLine((-30, 5), (30, 5))
self.SetDrawnPe n(wx.Pen("#00ee 10"))
self.DrawRounde dRectangle((-20, 10, 40, 10), 5)
self.SetDrawnPe n(wx.Pen("#9090 f0"))
self.DrawEllips e((-30, 25, 60, 20))
self.SetDrawnTe xtColour(wx.BLA CK)
self.SetDrawnFo nt(wx.Font(8, wx.SWISS, wx.NORMAL, wx.NORMAL))
self.DrawText(" DrawText", (-26, 28))
self.SetDrawnBr ush(wx.GREEN_BR USH)
self.DrawPolygo n([(-100, 5), (-45, 30), (-35, 20), (-30, 5)])
self.SetDrawnPe n(wx.BLACK_PEN)
self.DrawLines([(30, -45), (40, -45), (40 ,45), (30, 45)])
# Make sure to call CalculateSize when all drawing is done
self.CalculateS ize()
#----------------------------------------------------------------------
class DiamondShape(og l.PolygonShape) :
def __init__(self, w=0.0, h=0.0):
ogl.PolygonShap e.__init__(self )
if w == 0.0:
w = 60.0
if h == 0.0:
h = 60.0
points = [ (0.0, -h/2.0),
(w/2.0, 0.0),
(0.0, h/2.0),
(-w/2.0, 0.0),
]
self.Create(poi nts)
#----------------------------------------------------------------------
class TrackerRectangl e(ogl.Rectangle Shape):
def __init__(self, w=0.0, h = 0.0):
ogl.RectangleSh ape.__init__(se lf, w, h)
#self.TextShape (text)
class RoundedRectangl eShape(ogl.Rect angleShape):
def __init__(self, w=0.0, h=0.0):
ogl.RectangleSh ape.__init__(se lf, w, h)
self.SetCornerR adius(-0.3)
#----------------------------------------------------------------------
class CompositeDivisi onShape(ogl.Com positeShape):
def __init__(self, canvas):
ogl.CompositeSh ape.__init__(se lf)
self.SetCanvas( canvas)
# create a division in the composite
self.MakeContai ner()
# add a shape to the original division
shape2 = ogl.RectangleSh ape(40, 60)
self.GetDivisio ns()[0].AddChild(shape 2)
# now divide the division so we get 2
self.GetDivisio ns()[0].Divide(wx.HORI ZONTAL)
# and add a shape to the second division (and move it to the
# centre of the division)
shape3 = ogl.CircleShape (40)
shape3.SetBrush (wx.CYAN_BRUSH)
self.GetDivisio ns()[1].AddChild(shape 3)
shape3.SetX(sel f.GetDivisions( )[1].GetX())
for division in self.GetDivisio ns():
division.SetSen sitivityFilter( 0)
#----------------------------------------------------------------------
class CompositeShape( ogl.CompositeSh ape):
def __init__(self, canvas):
ogl.CompositeSh ape.__init__(se lf)
self.SetCanvas( canvas)
constraining_sh ape = ogl.RectangleSh ape(120, 100)
constrained_sha pe1 = ogl.CircleShape (50)
constrained_sha pe2 = ogl.RectangleSh ape(80, 20)
constraining_sh ape.SetBrush(wx .BLUE_BRUSH)
constrained_sha pe2.SetBrush(wx .RED_BRUSH)
self.AddChild(c onstraining_sha pe)
self.AddChild(c onstrained_shap e1)
self.AddChild(c onstrained_shap e2)
constraint = ogl.Constraint( ogl.CONSTRAINT_ MIDALIGNED_BOTT OM,
constraining_sh ape, [constrained_sha pe1, constrained_sha pe2])
self.AddConstra int(constraint)
self.Recompute( )
# If we don't do this, the shapes will be able to move on their
# own, instead of moving the composite
constraining_sh ape.SetDraggabl e(False)
constrained_sha pe1.SetDraggabl e(False)
constrained_sha pe2.SetDraggabl e(False)
# If we don't do this the shape will take all left-clicks for
itself
constraining_sh ape.SetSensitiv ityFilter(0)
#----------------------------------------------------------------------
class DividedShape(og l.DividedShape) :
def __init__(self, width, height, canvas):
ogl.DividedShap e.__init__(self , width, height)
region1 = ogl.ShapeRegion ()
region1.SetText ('DividedShape' )
region1.SetProp ortions(0.0, 0.2)
region1.SetForm atMode(ogl.FORM AT_CENTRE_HORIZ )
self.AddRegion( region1)
region2 = ogl.ShapeRegion ()
region2.SetText ('This is Region number two.')
region2.SetProp ortions(0.0, 0.3)
region2.SetForm atMode(ogl.FORM AT_CENTRE_HORIZ |ogl.FORMAT_CEN TRE_VERT)
self.AddRegion( region2)
region3 = ogl.ShapeRegion ()
region3.SetText ('Region 3\nwith embedded\nline breaks')
region3.SetProp ortions(0.0, 0.5)
region3.SetForm atMode(ogl.FORM AT_NONE)
self.AddRegion( region3)
self.SetRegionS izes()
self.ReformatRe gions(canvas)
def ReformatRegions (self, canvas=None):
rnum = 0
if canvas is None:
canvas = self.GetCanvas( )
dc = wx.ClientDC(can vas) # used for measuring
for region in self.GetRegions ():
text = region.GetText( )
self.FormatText (dc, text, rnum)
rnum += 1
def OnSizingEndDrag Left(self, pt, x, y, keys, attch):
print "***", self
ogl.DividedShap e.OnSizingEndDr agLeft(self, pt, x, y, keys,
attch)
self.SetRegionS izes()
self.ReformatRe gions()
self.GetCanvas( ).Refresh()
#----------------------------------------------------------------------
class MyEvtHandler(og l.ShapeEvtHandl er):
def __init__(self, log, frame):
ogl.ShapeEvtHan dler.__init__(s elf)
self.log = log
self.statbarFra me = frame
def UpdateStatusBar (self, shape):
x, y = shape.GetX(), shape.GetY()
width, height = shape.GetBoundi ngBoxMax()
self.statbarFra me.SetStatusTex t("Pos: (%d, %d) Size: (%d, %d)"
%
(x, y, width, height))
def OnLeftClick(sel f, x, y, keys=0, attachment=0):
shape = self.GetShape()
canvas = shape.GetCanvas ()
dc = wx.ClientDC(can vas)
canvas.PrepareD C(dc)
if shape.Selected( ):
shape.Select(Fa lse, dc)
canvas.Redraw(d c)
else:
redraw = False
shapeList = canvas.GetDiagr am().GetShapeLi st()
toUnselect = []
for s in shapeList:
if s.Selected():
# If we unselect it now then some of the objects in
# shapeList will become invalid (the control points
are
# shapes too!) and bad things will happen...
toUnselect.appe nd(s)
shape.Select(Tr ue, dc)
if toUnselect:
for s in toUnselect:
s.Select(False, dc)
canvas.Redraw(d c)
self.UpdateStat usBar(shape)
def OnEndDragLeft(s elf, x, y, keys=0, attachment=0):
shape = self.GetShape()
ogl.ShapeEvtHan dler.OnEndDragL eft(self, x, y, keys, attachment)
if not shape.Selected( ):
self.OnLeftClic k(x, y, keys, attachment)
self.UpdateStat usBar(shape)
def OnSizingEndDrag Left(self, pt, x, y, keys, attch):
ogl.ShapeEvtHan dler.OnSizingEn dDragLeft(self, pt, x, y, keys,
attch)
self.UpdateStat usBar(self.GetS hape())
def OnMovePost(self , dc, x, y, oldX, oldY, display):
ogl.ShapeEvtHan dler.OnMovePost (self, dc, x, y, oldX, oldY,
display)
self.UpdateStat usBar(self.GetS hape())
def OnRightClick(se lf, *dontcare):
self.log.WriteT ext("%s\n" % self.GetShape() )
#----------------------------------------------------------------------
class TestWindow(ogl. ShapeCanvas):
def __init__(self, parent, log, frame):
ogl.ShapeCanvas .__init__(self, parent)
maxWidth = 1000
maxHeight = 1000
self.SetScrollb ars(20, 20, maxWidth/20, maxHeight/20)
self.log = log
self.frame = frame
self.SetBackgro undColour("LIGH T BLUE") #wx.WHITE)
self.diagram = ogl.Diagram()
self.SetDiagram (self.diagram)
self.diagram.Se tCanvas(self)
self.shapes = []
self.save_gdi = []
rRectBrush = wx.Brush("MEDIU M TURQUOISE", wx.SOLID)
dsBrush = wx.Brush("WHEAT ", wx.SOLID)
#self.MyAddShap e(
# CompositeDivisi onShape(self),
# 270, 310, wx.BLACK_PEN, wx.BLUE_BRUSH, "Division"
# )
#self.MyAddShap e(
# CompositeShape( self),
# 100, 260, wx.BLACK_PEN, wx.RED_BRUSH, "Composite"
# )
#self.MyAddShap e(
# ogl.CircleShape (80),
# 75, 110, wx.Pen(wx.BLUE, 3), wx.GREEN_BRUSH, "Circle"
# )
#self.MyAddShap e(
# ogl.TextShape(1 20, 45),
# 160, 35, wx.GREEN_PEN, wx.LIGHT_GREY_B RUSH, "OGL is now
a\npure Python lib!"
# )
#self.MyAddShap e(
# ogl.RectangleSh ape(85, 50),
# 305, 60, wx.BLACK_PEN, wx.LIGHT_GREY_B RUSH, "Rectangle"
# )
#self.MyAddShap e(
# DrawnShape(),
# 500, 80, wx.BLACK_PEN, wx.BLACK_BRUSH, "DrawnShape "
# )
#ds = self.MyAddShape (
# DividedShape(14 0, 150, self),
# 520, 265, wx.BLACK_PEN, dsBrush, ''
# )
#self.MyAddShap e(
# DiamondShape(90 , 90),
# 355, 260, wx.Pen(wx.BLUE, 3, wx.DOT), wx.RED_BRUSH,
"Polygon"
# )
#self.MyAddShap e(
# RoundedRectangl eShape(95, 70),
# 345, 145, wx.Pen(wx.RED, 2), rRectBrush, "Rounded Rect"
# )
instr = csoundroutines. csdInstrumentLi st2(sys.argv[1])
connections = csoundroutines. return_pins2(sy s.argv[1])
shape = []
for i in range(0, len(instr.instr num)):
#shape[i] = ogl.RectangleSh ape(80, 30)
#shape[i].AddText(instr. comments[i])
#canvas.AddShap e( shape[i] )
#shape[i].SetX( 25.0 ) #
#shape[i].SetY( 25.0 )
self.MyAddShape (
TrackerRectangl e(70,30),
25, 25, wx.Pen(wx.RED, 2),rRectBrush,
instr.comments[i]
)
dc = wx.ClientDC(sel f)
self.PrepareDC( dc)
print 'is here'
line = {}
x1 = {}
y1 = {}
x2 = {}
y2 = {}
for i in range(0, len(instr.instr num)):
if connections.ins tr_output[i] != 0:
#check for an output
for n in range(0,len(ins tr.comments)):
#iterate through names
print(connectio ns.instr_number[i],
int(instr.instr num[n]))
if connections.ins tr_number[i] ==
int(instr.instr num[n]): #check for a match
x1[i] = self.shapes[i].GetX #
y1[i] = self.shapes[i].GetY
print instr.instrnum
print 'instr num'
print i
print 'iterator'
#outstring = instr.comments[n] + ' -'
#grab the name
for o in range(0, len(connections .instr_number)) :
#iterate through connections
#print(o, outstring)
if connections.ins tr_output[i] ==
connections.ins tr_input[o]: #check for pin match
for n2 in range(0,len(ins tr.comments)):
#iterate through connections
if connections.ins tr_number[o] ==
int(instr.instr num[n2]): #match names
x2 = self.shapes[n2].GetX
y2 = self.shapes[n2].GetY
fromShape = self.shapes[i]
toShape = self.shapes[n2]
line = ogl.LineShape()
line.SetCanvas( self)
line.SetPen(wx. BLACK_PEN)
line.SetBrush(w x.BLACK_BRUSH)
line.AddArrow(o gl.ARROW_ARROW)
line.MakeLineCo ntrolPoints(2)
fromShape.AddLi ne(line, toShape)
#fromShape.AddL ine(line, toShape)
self.diagram.Ad dShape(line)
line.Show(True)
#shape[i].AddLine(line[o], shape[n2])
#line[o] = ogl.LineShape()
#line[o].SetCanvas(self )
#line[o].MakeLineContro lPoints(2)
# S
def MyAddShape(self , shape, x, y, pen, brush, text):
# Composites have to be moved for all children to get in place
if isinstance(shap e, ogl.CompositeSh ape):
dc = wx.ClientDC(sel f)
self.PrepareDC( dc)
shape.Move(dc, x, y)
else:
shape.SetDragga ble(True, True)
shape.SetCanvas (self)
shape.SetX(x)
shape.SetY(y)
if pen: shape.SetPen(pe n)
if brush: shape.SetBrush( brush)
if text:
for line in text.split('\n' ):
shape.AddText(l ine)
#shape.SetShado wMode(ogl.SHADO W_RIGHT)
self.diagram.Ad dShape(shape)
shape.Show(True )
evthandler = MyEvtHandler(se lf.log, self.frame)
evthandler.SetS hape(shape)
evthandler.SetP reviousHandler( shape.GetEventH andler())
shape.SetEventH andler(evthandl er)
self.shapes.app end(shape)
return shape
def OnBeginDragLeft (self, x, y, keys):
self.log.write( "OnBeginDragLef t: %s, %s, %s\n" % (x, y, keys))
def OnEndDragLeft(s elf, x, y, keys):
self.log.write( "OnEndDragL eft: %s, %s, %s\n" % (x, y, keys))
#----------------------------------------------------------------------
def runTest(frame, nb, log):
# This creates some pens and brushes that the OGL library uses.
# It should be called after the app object has been created, but
# before OGL is used.
ogl.OGLInitiali ze()
win = TestWindow(nb, log, frame)
return win
#----------------------------------------------------------------------
overview = """<html><b ody>
<h2>Object Graphics Library</h2>
The Object Graphics Library is a library supporting the creation and
manipulation of simple and complex graphic images on a canvas.
<p>The OGL library was originally written in C++ and provided to
wxPython via an extension module wrapper as is most of the rest of
wxPython. The code has now been ported to Python (with many thanks to
Pierre Hjälm!) in order to make it be more easily maintainable and
less likely to get rusty because nobody cares about the C++ lib any
more.
<p>The Python version should be mostly drop-in compatible with the
wrapped C++ version, except for the location of the package
(wx.lib.ogl instead of wx.ogl) and that the base class methods are
called the normal Python way (superclass.Met hod(self, ...)) instead of
the
hacky way that had to be done to support overloaded methods with the
old SWIG (self.base_Meth od(...))
"""
def main2(programna me, filename):
import sys, os
import run
run.main(['', os.path.basenam e(sys.argv[0])] + sys.argv[1:])
if __name__ == '__main__':
import sys, os
import run
run.main(['', os.path.basenam e(sys.argv[0])] + sys.argv[1:])