Commits

Just van Rossum  committed 0468e8b

detabbed

  • Participants
  • Parent commits 65fe2ef

Comments (0)

Files changed (5)

File pyobjc/Examples/FieldGraph/CGraphController.py

 NibClassBuilder.extractClasses("MainMenu")
 
 
-#____________________________________________________________
 class CGraphController(NibClassBuilder.AutoBaseClass):
 
-#____________________________________________________________
-# Update GUI display and control values
-	def awakeFromNib(self):
-		self.RMSGainDisplayValue.setFloatValue_(self.graphModel.getRMSGain()*100.0)
-		self.towerSpacingDisplayValue.setFloatValue_(radToDeg(self.graphModel.getSpacing()))
-		self.towerSpacingSliderValue.setFloatValue_(radToDeg(self.graphModel.getSpacing()))
-		self.towerFieldDisplayValue0.setFloatValue_(self.graphModel.getField(0))
-		self.towerFieldDisplayValue1.setFloatValue_(self.graphModel.getField(1))
-		self.towerFieldDisplayValue2.setFloatValue_(self.graphModel.getField(2))
-		self.towerFieldSliderValue0.setFloatValue_(self.graphModel.getField(0))
-		self.towerFieldSliderValue1.setFloatValue_(self.graphModel.getField(1))
-		self.towerFieldSliderValue2.setFloatValue_(self.graphModel.getField(2))
-		self.towerPhaseDisplayValue0.setFloatValue_(radToDeg(self.graphModel.getPhase(0)))
-		self.towerPhaseDisplayValue1.setFloatValue_(radToDeg(self.graphModel.getPhase(1)))
-		self.towerPhaseDisplayValue2.setFloatValue_(radToDeg(self.graphModel.getPhase(2)))
-		self.towerPhaseSliderValue0.setFloatValue_(radToDeg(self.graphModel.getPhase(0)))
-		self.towerPhaseSliderValue1.setFloatValue_(radToDeg(self.graphModel.getPhase(1)))
-		self.towerPhaseSliderValue2.setFloatValue_(radToDeg(self.graphModel.getPhase(2)))
+    # Update GUI display and control values
+    def awakeFromNib(self):
+        self.RMSGainDisplayValue.setFloatValue_(self.graphModel.getRMSGain()*100.0)
+        self.towerSpacingDisplayValue.setFloatValue_(radToDeg(self.graphModel.getSpacing()))
+        self.towerSpacingSliderValue.setFloatValue_(radToDeg(self.graphModel.getSpacing()))
+        self.towerFieldDisplayValue0.setFloatValue_(self.graphModel.getField(0))
+        self.towerFieldDisplayValue1.setFloatValue_(self.graphModel.getField(1))
+        self.towerFieldDisplayValue2.setFloatValue_(self.graphModel.getField(2))
+        self.towerFieldSliderValue0.setFloatValue_(self.graphModel.getField(0))
+        self.towerFieldSliderValue1.setFloatValue_(self.graphModel.getField(1))
+        self.towerFieldSliderValue2.setFloatValue_(self.graphModel.getField(2))
+        self.towerPhaseDisplayValue0.setFloatValue_(radToDeg(self.graphModel.getPhase(0)))
+        self.towerPhaseDisplayValue1.setFloatValue_(radToDeg(self.graphModel.getPhase(1)))
+        self.towerPhaseDisplayValue2.setFloatValue_(radToDeg(self.graphModel.getPhase(2)))
+        self.towerPhaseSliderValue0.setFloatValue_(radToDeg(self.graphModel.getPhase(0)))
+        self.towerPhaseSliderValue1.setFloatValue_(radToDeg(self.graphModel.getPhase(1)))
+        self.towerPhaseSliderValue2.setFloatValue_(radToDeg(self.graphModel.getPhase(2)))
 
-		self.graphModel.drawGraph()
+        self.graphModel.drawGraph()
 
+    # Handle GUI values
+    def towerFieldDisplayValueControl0_(self, sender):
+        self.graphModel.setField(0, sender.floatValue())
+        self.awakeFromNib()
 
-#____________________________________________________________
-# Handle GUI values
-	def towerFieldDisplayValueControl0_(self, sender):
-		self.graphModel.setField(0, sender.floatValue())
-		self.awakeFromNib()
+    def towerFieldDisplayValueControl1_(self, sender):
+        self.graphModel.setField(1, sender.floatValue())
+        self.awakeFromNib()
 
-	def towerFieldDisplayValueControl1_(self, sender):
-		self.graphModel.setField(1, sender.floatValue())
-		self.awakeFromNib()
+    def towerFieldDisplayValueControl2_(self, sender):
+        self.graphModel.setField(2, sender.floatValue())
+        self.awakeFromNib()
 
-	def towerFieldDisplayValueControl2_(self, sender):
-		self.graphModel.setField(2, sender.floatValue())
-		self.awakeFromNib()
+    def towerFieldSliderValueControl0_(self, sender):
+        self.graphModel.setField(0, sender.floatValue())
+        self.awakeFromNib()
 
-	def towerFieldSliderValueControl0_(self, sender):
-		self.graphModel.setField(0, sender.floatValue())
-		self.awakeFromNib()
+    def towerFieldSliderValueControl1_(self, sender):
+        self.graphModel.setField(1, sender.floatValue())
+        self.awakeFromNib()
 
-	def towerFieldSliderValueControl1_(self, sender):
-		self.graphModel.setField(1, sender.floatValue())
-		self.awakeFromNib()
+    def towerFieldSliderValueControl2_(self, sender):
+        self.graphModel.setField(2, sender.floatValue())
+        self.awakeFromNib()
 
-	def towerFieldSliderValueControl2_(self, sender):
-		self.graphModel.setField(2, sender.floatValue())
-		self.awakeFromNib()
+    def towerPhaseDisplayValueControl0_(self, sender):
+        self.graphModel.setPhase(0, degToRad(sender.floatValue()))
+        self.awakeFromNib()
 
-	def towerPhaseDisplayValueControl0_(self, sender):
-		self.graphModel.setPhase(0, degToRad(sender.floatValue()))
-		self.awakeFromNib()
+    def towerPhaseDisplayValueControl1_(self, sender):
+        self.graphModel.setPhase(1, degToRad(sender.floatValue()))
+        self.awakeFromNib()
 
-	def towerPhaseDisplayValueControl1_(self, sender):
-		self.graphModel.setPhase(1, degToRad(sender.floatValue()))
-		self.awakeFromNib()
+    def towerPhaseDisplayValueControl2_(self, sender):
+        self.graphModel.setPhase(2, degToRad(sender.floatValue()))
+        self.awakeFromNib()
 
-	def towerPhaseDisplayValueControl2_(self, sender):
-		self.graphModel.setPhase(2, degToRad(sender.floatValue()))
-		self.awakeFromNib()
+    def towerPhaseSliderValueControl0_(self, sender):
+        self.graphModel.setPhase(0, degToRad(sender.floatValue()))
+        self.awakeFromNib()
 
-	def towerPhaseSliderValueControl0_(self, sender):
-		self.graphModel.setPhase(0, degToRad(sender.floatValue()))
-		self.awakeFromNib()
+    def towerPhaseSliderValueControl1_(self, sender):
+        self.graphModel.setPhase(1, degToRad(sender.floatValue()))
+        self.awakeFromNib()
 
-	def towerPhaseSliderValueControl1_(self, sender):
-		self.graphModel.setPhase(1, degToRad(sender.floatValue()))
-		self.awakeFromNib()
+    def towerPhaseSliderValueControl2_(self, sender):
+        self.graphModel.setPhase(2, degToRad(sender.floatValue()))
+        self.awakeFromNib()
 
-	def towerPhaseSliderValueControl2_(self, sender):
-		self.graphModel.setPhase(2, degToRad(sender.floatValue()))
-		self.awakeFromNib()
+    def towerSpacingDisplayValueControl_(self, sender):
+        self.graphModel.setSpacing(degToRad(sender.floatValue()))
+        self.awakeFromNib()
 
-	def towerSpacingDisplayValueControl_(self, sender):
-		self.graphModel.setSpacing(degToRad(sender.floatValue()))
-		self.awakeFromNib()
-
-	def towerSpacingSliderValueControl_(self, sender):
-		self.graphModel.setSpacing(degToRad(sender.floatValue()))
-		self.awakeFromNib()
+    def towerSpacingSliderValueControl_(self, sender):
+        self.graphModel.setSpacing(degToRad(sender.floatValue()))
+        self.awakeFromNib()

File pyobjc/Examples/FieldGraph/CGraphModel.py

 from fieldMath import *
 from CGraphView import *
 
-#____________________________________________________________
+
 class CGraphModel(NibClassBuilder.AutoBaseClass):
-	
-	def drawGraph(self):
-		self.graphView.setGain(self.fieldGain())
-		
-		path = NSBezierPath.bezierPath()
+    
+    def drawGraph(self):
+        self.graphView.setGain(self.fieldGain())
+        
+        path = NSBezierPath.bezierPath()
 
-		maxMag = 0
-		mag = self.fieldValue(0)
-		maxMag = max(maxMag, mag)
-		path.moveToPoint_(polarToRect((mag, 0)))
-		for deg in range(1, 359, 1):
-			r = (deg/180.0)*pi
-			mag = self.fieldValue(r)
-			maxMag = max(maxMag, mag)
-			path.lineToPoint_(polarToRect((mag, r)))
+        maxMag = 0
+        mag = self.fieldValue(0)
+        maxMag = max(maxMag, mag)
+        path.moveToPoint_(polarToRect((mag, 0)))
+        for deg in range(1, 359, 1):
+            r = (deg/180.0)*pi
+            mag = self.fieldValue(r)
+            maxMag = max(maxMag, mag)
+            path.lineToPoint_(polarToRect((mag, r)))
 
-		path.closePath()
-		self.graphView.setPath(path, maxMag)
+        path.closePath()
+        self.graphView.setPath(path, maxMag)
 
-		self.graphView.setNeedsDisplay_(1)
+        self.graphView.setNeedsDisplay_(1)
 
-	def fieldGain(self):
-		gain = 0
-		Et = self.field[0] + self.field[1] + self.field[2]
-		if Et:		# Don't want to divide by zero in the pathological case
-			spacing = [0, self.spacing, 2*self.spacing]
-			
-			# This could easily be optimized--but this is just anexample :-)
-			for i in range(3):
-				for j in range(3):
-					gain += self.field[i]*self.field[j] * cos(self.phase[j]-self.phase[i]) * bessel(spacing[j]-spacing[i])
-			gain = sqrt(gain) / Et
-		
-		self.RMSGain = gain
-		return gain
-	
-	def fieldValue(self, a):
-		# The intermediat values are used to more closely match standard field equations nomenclature
-		E0 = self.field[0]
-		E1 = self.field[1]
-		E2 = self.field[2]
-		B0 = self.phase[0]
-		B1 = self.phase[1] + self.spacing * cos(a)
-		B2 = self.phase[2] + 2 * self.spacing * cos(a)
-		
-		phix = sin(B0) * E0  + sin(B1) * E1 + sin(B2) * E2
-		phiy = cos(B0) * E0 + cos(B1) * E1 + cos(B2) * E2
-		mag = hypot(phix, phiy)
-		
-		return mag
+    def fieldGain(self):
+        gain = 0
+        Et = self.field[0] + self.field[1] + self.field[2]
+        if Et:      # Don't want to divide by zero in the pathological case
+            spacing = [0, self.spacing, 2*self.spacing]
+            
+            # This could easily be optimized--but this is just anexample :-)
+            for i in range(3):
+                for j in range(3):
+                    gain += self.field[i]*self.field[j] * cos(self.phase[j]-self.phase[i]) * bessel(spacing[j]-spacing[i])
+            gain = sqrt(gain) / Et
+        
+        self.RMSGain = gain
+        return gain
+    
+    def fieldValue(self, a):
+        # The intermediat values are used to more closely match standard field equations nomenclature
+        E0 = self.field[0]
+        E1 = self.field[1]
+        E2 = self.field[2]
+        B0 = self.phase[0]
+        B1 = self.phase[1] + self.spacing * cos(a)
+        B2 = self.phase[2] + 2 * self.spacing * cos(a)
+        
+        phix = sin(B0) * E0  + sin(B1) * E1 + sin(B2) * E2
+        phiy = cos(B0) * E0 + cos(B1) * E1 + cos(B2) * E2
+        mag = hypot(phix, phiy)
+        
+        return mag
 
-	def setField(self, tower, field):
-		self.field[tower] = field
+    def setField(self, tower, field):
+        self.field[tower] = field
 
-	def getField(self, tower):
-		return self.field[tower]
+    def getField(self, tower):
+        return self.field[tower]
 
-	def setPhase(self, tower, phase):
-		self.phase[tower] = phase
+    def setPhase(self, tower, phase):
+        self.phase[tower] = phase
 
-	def getPhase(self, tower):
-		return self.phase[tower]
+    def getPhase(self, tower):
+        return self.phase[tower]
 
-	def setRMSGain(self, RMSGain):
-		self.RMSGain = RMSGain
+    def setRMSGain(self, RMSGain):
+        self.RMSGain = RMSGain
 
-	def getRMSGain(self):
-		return self.RMSGain
+    def getRMSGain(self):
+        return self.RMSGain
 
-	def setSpacing(self, spacing):
-		self.spacing = spacing
+    def setSpacing(self, spacing):
+        self.spacing = spacing
 
-	def getSpacing(self):
-		return self.spacing
+    def getSpacing(self):
+        return self.spacing
 
-	def init(self):
-		self.field = [1.0, 1.12, 0.567]
-		self.phase = [degToRad(0), degToRad(152.6), degToRad(312.9-360)]
-		self.RMSGain = 0
-		self.spacing = degToRad(90)
-		return self
+    def init(self):
+        self.field = [1.0, 1.12, 0.567]
+        self.phase = [degToRad(0), degToRad(152.6), degToRad(312.9-360)]
+        self.RMSGain = 0
+        self.spacing = degToRad(90)
+        return self

File pyobjc/Examples/FieldGraph/CGraphView.py

 from AppKit import NSBezierPath, NSColor, NSRectFill, NSAffineTransform
 from math import pi, sin, cos
 
-#____________________________________________________________
+
 class CGraphView(NibClassBuilder.AutoBaseClass):
 
-	def awakeFromNib(self):
-		self.lines = 2
-		self.gain = 0.5
-	
-	def initWithFrame_(self, frame):
-		super(CGraphView, self).initWithFrame_(frame)
-		self.setGridColor()
-		self.setRmsColor()
-		self.setGraphColor()
-		return self
-		
-	def setGridColor(self, color=NSColor.greenColor()):
-		self.gridColor = color
-		
-	def setRmsColor(self, color=NSColor.blueColor()):
-		self.rmsColor = color
-		
-	def setGraphColor(self, color=NSColor.blackColor()):
-		self.graphColor = color
-		
-	def setGain(self, gain):
-		self.gain = gain
-		
-	def setLInes(self, lines):
-		self.lines = lines
-		
-	def setPath(self, path, maxMag):
-		self.path = path
-		if maxMag < 1e-5:
-			# prevent divide by zero
-			maxMag = 1e-5
-		self.maxMag = maxMag
-		
-	def drawRect_(self, rect):
-		frame = self.frame()
-		self.graphCenter = (frame[1][0]/2, frame[1][1]/2)
-		self.graphRadius = min(frame[1][0], frame[1][1]) / 2 - 4
-		
-		NSColor.whiteColor().set()
-		NSRectFill(self.bounds())
-		
-		self.drawGrid()
-		self.drawRMS()
-		self.drawField()
-		
-	def drawGrid(self):
-		self.gridColor.set()
-		self.drawCircle(1.0)
-		self.drawAxisLines()
-			
-	def drawCircle(self, scale):
-		center = self.graphCenter
-		radius = self.graphRadius*scale
-		x, y = 0, 1
-		if radius >= 1:
-			dotRect = ((center[x]-radius, center[y]-radius), (2*radius, 2*radius))
-			path = NSBezierPath.bezierPathWithOvalInRect_(dotRect)
-			path.stroke()
-	
-	def drawRMS(self):
-		self.rmsColor.set()
-		self.drawCircle(self.gain)
-		
-	def drawAxisLines(self):
-		center = self.graphCenter
-		radius = self.graphRadius
-		x, y = 0, 1
-		path = NSBezierPath.bezierPath()
-		for i in range(1, self.lines+1):
-			iR = pi / i
-			cosR = cos(iR) * radius
-			sinR = sin(iR) * radius
-			
-			path.moveToPoint_((center[x] - cosR, center[y] - sinR))
-			path.lineToPoint_((center[x] + cosR, center[y] + sinR))
-		path.closePath()
-		path.stroke()
+    def awakeFromNib(self):
+        self.lines = 2
+        self.gain = 0.5
+    
+    def initWithFrame_(self, frame):
+        super(CGraphView, self).initWithFrame_(frame)
+        self.setGridColor()
+        self.setRmsColor()
+        self.setGraphColor()
+        return self
+        
+    def setGridColor(self, color=NSColor.greenColor()):
+        self.gridColor = color
+        
+    def setRmsColor(self, color=NSColor.blueColor()):
+        self.rmsColor = color
+        
+    def setGraphColor(self, color=NSColor.blackColor()):
+        self.graphColor = color
+        
+    def setGain(self, gain):
+        self.gain = gain
+        
+    def setLInes(self, lines):
+        self.lines = lines
+        
+    def setPath(self, path, maxMag):
+        self.path = path
+        if maxMag < 1e-5:
+            # prevent divide by zero
+            maxMag = 1e-5
+        self.maxMag = maxMag
+        
+    def drawRect_(self, rect):
+        frame = self.frame()
+        self.graphCenter = (frame[1][0]/2, frame[1][1]/2)
+        self.graphRadius = min(frame[1][0], frame[1][1]) / 2 - 4
+        
+        NSColor.whiteColor().set()
+        NSRectFill(self.bounds())
+        
+        self.drawGrid()
+        self.drawRMS()
+        self.drawField()
+        
+    def drawGrid(self):
+        self.gridColor.set()
+        self.drawCircle(1.0)
+        self.drawAxisLines()
+            
+    def drawCircle(self, scale):
+        center = self.graphCenter
+        radius = self.graphRadius*scale
+        x, y = 0, 1
+        if radius >= 1:
+            dotRect = ((center[x]-radius, center[y]-radius), (2*radius, 2*radius))
+            path = NSBezierPath.bezierPathWithOvalInRect_(dotRect)
+            path.stroke()
+    
+    def drawRMS(self):
+        self.rmsColor.set()
+        self.drawCircle(self.gain)
+        
+    def drawAxisLines(self):
+        center = self.graphCenter
+        radius = self.graphRadius
+        x, y = 0, 1
+        path = NSBezierPath.bezierPath()
+        for i in range(1, self.lines+1):
+            iR = pi / i
+            cosR = cos(iR) * radius
+            sinR = sin(iR) * radius
+            
+            path.moveToPoint_((center[x] - cosR, center[y] - sinR))
+            path.lineToPoint_((center[x] + cosR, center[y] + sinR))
+        path.closePath()
+        path.stroke()
 
-	def drawField(self):
-		transform = NSAffineTransform.transform()
-		center = self.graphCenter
-		transform.translateXBy_yBy_(center[0], center[1])
-		transform.scaleBy_(self.graphRadius / self.maxMag)
-		path = self.path.copy()
-		path.transformUsingAffineTransform_(transform)
-		self.graphColor.set()
-		path.stroke()
+    def drawField(self):
+        transform = NSAffineTransform.transform()
+        center = self.graphCenter
+        transform.translateXBy_yBy_(center[0], center[1])
+        transform.scaleBy_(self.graphRadius / self.maxMag)
+        path = self.path.copy()
+        path.transformUsingAffineTransform_(transform)
+        self.graphColor.set()
+        path.stroke()

File pyobjc/Examples/FieldGraph/buildapp.py

 #
-# Successor of setup-app.py. Run this program from the command line like so:
+# Run this program from the command line like so:
 #
-# % python buildapp.py build
+# % python buildapp.py --link build
 #
-# It depends on two (new) modules from the Python CVS tree:
-#    Mac/Lib/bundlebuilder.py
-#    Mac/Lib/plistlib.py
-# These modules are otherwise completely standalone, they don't need any
-# Mac- or PyObjC-specific stuff.
 #
 
 from bundlebuilder import buildapp
 ]
 
 buildapp(
-        name = "FieldGraph",
-	mainprogram = "Main.py",
-	resources = ["English.lproj"] + SRC,
-	nibname = "MainMenu",
+    name = "FieldGraph",
+    mainprogram = "Main.py",
+    resources = ["English.lproj"] + SRC,
+    nibname = "MainMenu",
 )

File pyobjc/Examples/FieldGraph/fieldMath.py

 # Math functions
 
 def degToRad(deg):
-	return (deg/180.0)*pi
-	
+    return (deg/180.0)*pi
+    
 def radToDeg(rad):
-	return (rad/pi)*180.0
+    return (rad/pi)*180.0
 
 def polarToRect(polar):
-	r = polar[0]
-	theta = polar[1]
-	return (r*cos(theta), r*sin(theta))
+    r = polar[0]
+    theta = polar[1]
+    return (r*cos(theta), r*sin(theta))
 
 def bessel(z, t=0.00001):
-	j = 1
-	jn = 1
-	zz4 = z*z/4
-	for k in range(1, 100):
-		jn *= -1 * zz4 / (k*k)
-		j += jn
+    j = 1
+    jn = 1
+    zz4 = z*z/4
+    for k in range(1, 100):
+        jn *= -1 * zz4 / (k*k)
+        j += jn
 
-		if jn < 0:
-			if jn > t:
-				break
-		else:
-			if jn < t:
-				break
-	return j
+        if jn < 0:
+            if jn > t:
+                break
+        else:
+            if jn < t:
+                break
+    return j