Commits

Ronald Oussoren committed 2b1571a

Import new version of FieldGraph
Make sure CodeGenerator scripts work when the target doesn't exist
Add self attribute to selectors

  • Participants
  • Parent commits 126bc0e

Comments (0)

Files changed (17)

File pyobjc/Examples/FieldGraph/CGraphController.py

 from objc import *
 
 from CGraphModel import *
+from CGraphView import *
+from fieldMath import *
 
 
 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
 
-        self.graphModel.drawGraph()
+	def awakeFromNib(self):
+		self.mapImage = NSImage.imageNamed_("Map")
+		self.graphView.setMapImage(self.mapImage)
+		self.drawGraph()
 
-    # Handle GUI values
-    def towerFieldDisplayValueControl0_(self, sender):
-        self.graphModel.setField(0, sender.floatValue())
-        self.awakeFromNib()
+	def drawGraph(self):
+		self.spacingDisplay.setFloatValue_(radToDeg(self.graphModel.getSpacing()))
+		self.spacingSlider.setFloatValue_(radToDeg(self.graphModel.getSpacing()))
+		self.fieldDisplay0.setFloatValue_(self.graphModel.getField(0))
+		self.fieldDisplay1.setFloatValue_(self.graphModel.getField(1))
+		self.fieldDisplay2.setFloatValue_(self.graphModel.getField(2))
+		self.fieldSlider0.setFloatValue_(self.graphModel.getField(0))
+		self.fieldSlider1.setFloatValue_(self.graphModel.getField(1))
+		self.fieldSlider2.setFloatValue_(self.graphModel.getField(2))
+		self.phaseDisplay0.setFloatValue_(radToDeg(self.graphModel.getPhase(0)))
+		self.phaseDisplay1.setFloatValue_(radToDeg(self.graphModel.getPhase(1)))
+		self.phaseDisplay2.setFloatValue_(radToDeg(self.graphModel.getPhase(2)))
+		self.phaseSlider0.setFloatValue_(radToDeg(self.graphModel.getPhase(0)))
+		self.phaseSlider1.setFloatValue_(radToDeg(self.graphModel.getPhase(1)))
+		self.phaseSlider2.setFloatValue_(radToDeg(self.graphModel.getPhase(2)))
+		
+		totalField = self.graphModel.getField(0) + self.graphModel.getField(1) + self.graphModel.getField(2)
 
-    def towerFieldDisplayValueControl1_(self, sender):
-        self.graphModel.setField(1, sender.floatValue())
-        self.awakeFromNib()
+		RMSGain = self.graphModel.fieldGain()
+		self.graphView.setGain(RMSGain, totalField)
+		self.RMSGainDisplay.setFloatValue_(RMSGain*100.0)
 
-    def towerFieldDisplayValueControl2_(self, sender):
-        self.graphModel.setField(2, sender.floatValue())
-        self.awakeFromNib()
+		path, maxMag  = self.graphModel.getGraph()
+		self.graphView.setPath(path, maxMag)
 
-    def towerFieldSliderValueControl0_(self, sender):
-        self.graphModel.setField(0, sender.floatValue())
-        self.awakeFromNib()
 
-    def towerFieldSliderValueControl1_(self, sender):
-        self.graphModel.setField(1, sender.floatValue())
-        self.awakeFromNib()
+#____________________________________________________________
+# Handle GUI values
 
-    def towerFieldSliderValueControl2_(self, sender):
-        self.graphModel.setField(2, sender.floatValue())
-        self.awakeFromNib()
+	def fieldDisplay0_(self, sender):
+		self.setNormalizedField(0, sender.floatValue())
+		self.drawGraph()
 
-    def towerPhaseDisplayValueControl0_(self, sender):
-        self.graphModel.setPhase(0, degToRad(sender.floatValue()))
-        self.awakeFromNib()
+	def fieldDisplay1_(self, sender):
+		self.setNormalizedField(1, sender.floatValue())
+		self.drawGraph()
 
-    def towerPhaseDisplayValueControl1_(self, sender):
-        self.graphModel.setPhase(1, degToRad(sender.floatValue()))
-        self.awakeFromNib()
+	def fieldDisplay2_(self, sender):
+		self.setNormalizedField(2, sender.floatValue())
+		self.drawGraph()
 
-    def towerPhaseDisplayValueControl2_(self, sender):
-        self.graphModel.setPhase(2, degToRad(sender.floatValue()))
-        self.awakeFromNib()
+	def fieldSlider0_(self, sender):
+		self.setNormalizedField(0, sender.floatValue())
+		self.drawGraph()
 
-    def towerPhaseSliderValueControl0_(self, sender):
-        self.graphModel.setPhase(0, degToRad(sender.floatValue()))
-        self.awakeFromNib()
+	def fieldSlider1_(self, sender):
+		self.setNormalizedField(1, sender.floatValue())
+		self.drawGraph()
 
-    def towerPhaseSliderValueControl1_(self, sender):
-        self.graphModel.setPhase(1, degToRad(sender.floatValue()))
-        self.awakeFromNib()
+	def fieldSlider2_(self, sender):
+		self.setNormalizedField(2, sender.floatValue())
+		self.drawGraph()
+		
+	def setNormalizedField(self, t, v):
+		if self.fieldNormalizeCheck.intValue():
+			f = [0, 0, 0]
+			cft = 0
+			for i in range(3):
+				f[i] = self.graphModel.getField(i)
+				cft += f[i]
+				
+			aft = cft - v
+			if aft < 0.001:
+				v = cft - 0.001
+				aft = 0.001
+			f[t] = v
+			
+			nft = 0
+			for i in range(3):
+				nft +=  f[i]
+			r = aft / (nft - f[t])
+		
+			for i in range(3):
+				self.graphModel.setField(i, f[i] * r)
+			self.graphModel.setField(t, v)
 
-    def towerPhaseSliderValueControl2_(self, sender):
-        self.graphModel.setPhase(2, degToRad(sender.floatValue()))
-        self.awakeFromNib()
+		else:
+			self.graphModel.setField(t, v)
 
-    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 phaseDisplay0_(self, sender):
+		self.graphModel.setPhase(0, degToRad(sender.floatValue()))
+		self.drawGraph()
+
+	def phaseDisplay1_(self, sender):
+		self.graphModel.setPhase(1, degToRad(sender.floatValue()))
+		self.drawGraph()
+
+	def phaseDisplay2_(self, sender):
+		self.graphModel.setPhase(2, degToRad(sender.floatValue()))
+		self.drawGraph()
+
+	def phaseSlider0_(self, sender):
+		self.graphModel.setPhase(0, degToRad(sender.floatValue()))
+		self.drawGraph()
+
+	def phaseSlider1_(self, sender):
+		self.graphModel.setPhase(1, degToRad(sender.floatValue()))
+		self.drawGraph()
+
+	def phaseSlider2_(self, sender):
+		self.graphModel.setPhase(2, degToRad(sender.floatValue()))
+		self.drawGraph()
+
+	def spacingDisplay_(self, sender):
+		self.graphModel.setSpacing(degToRad(sender.floatValue()))
+		self.drawGraph()
+
+	def spacingSlider_(self, sender):
+		self.graphModel.setSpacing(degToRad(sender.floatValue()))
+		self.drawGraph()
+	
+	def settingDrawerButton_(self, sender):
+		self.settingDrawer.toggle_(self)

File pyobjc/Examples/FieldGraph/CGraphModel.py

 from Foundation import NSObject
 from PyObjCTools import NibClassBuilder
 from objc import *
+from AppKit import NSBezierPath
 
 from fieldMath import *
-from CGraphView import *
 
+#____________________________________________________________
+class CGraphModel(NibClassBuilder.AutoBaseClass):
 
-class CGraphModel(NibClassBuilder.AutoBaseClass):
-    
-    def drawGraph(self):
-        self.graphView.setGain(self.fieldGain())
-        
-        path = NSBezierPath.bezierPath()
+	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 getGraph(self):
+		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()
+		
+		return path, maxMag;
+		
+	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 intermedate 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
 
-        path.closePath()
-        self.graphView.setPath(path, maxMag)
 
-        self.graphView.setNeedsDisplay_(1)
+	def setField(self, tower, field):
+		self.field[tower] = field
 
-    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 getField(self, tower):
+		return self.field[tower]
 
-    def setField(self, tower, field):
-        self.field[tower] = field
+	def setPhase(self, tower, phase):
+		self.phase[tower] = phase
 
-    def getField(self, tower):
-        return self.field[tower]
+	def getPhase(self, tower):
+		return self.phase[tower]
 
-    def setPhase(self, tower, phase):
-        self.phase[tower] = phase
+	def setSpacing(self, spacing):
+		self.spacing = spacing
 
-    def getPhase(self, tower):
-        return self.phase[tower]
-
-    def setRMSGain(self, RMSGain):
-        self.RMSGain = RMSGain
-
-    def getRMSGain(self):
-        return self.RMSGain
-
-    def setSpacing(self, spacing):
-        self.spacing = 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 getSpacing(self):
+		return self.spacing

File pyobjc/Examples/FieldGraph/CGraphView.py

 from PyObjCTools import NibClassBuilder
 from objc import *
 
+from Foundation import NSData
 from AppKit import NSBezierPath, NSColor, NSRectFill, NSAffineTransform
+from AppKit import NSImage, NSCompositeSourceOver, NSCursor
 from math import pi, sin, cos
+from fieldMath import *
 
+# Convience global variables
+x, y = 0, 1
+llc, sze = 0, 1	# Left Lower Corner, Size
 
+#____________________________________________________________
 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 initWithFrame_(self, frame):
+		super(CGraphView, self).initWithFrame_(frame)
+		self.setGridColor()
+		self.setRmsColor()
+		self.setGraphColor()
+		self.graphMargin = 2
+		self.mapImage = 0
+		self.mapRect = 0
+		self.mapVisible = 0.70
+		self.mapScale = 3.0
+		self.mapOffsetEW = 0.27
+		self.mapOffsetNS = 0.40
+		self.mapBaseRadius = 200
+		
+		self.lines = 2
+		self.gain = 0.5
+		return self
+		
+	def awakeFromNib(self):
+		self.setCrossCursor()
+		self.mapVisibleSlider.setFloatValue_(self.mapVisible)
+		self.setAzmuth(125)
+		self.setMapRect()
+		
+	def setCrossCursor(self):
+		crosshairImage = NSImage.imageNamed_("CrossCursor")
+        	imageSize = crosshairImage.size()
+		self.crossCursor = NSCursor.alloc().initWithImage_hotSpot_(crosshairImage, (8, 8))
+		rect = self.bounds()
+		self.trackingRect = self.addTrackingRect_owner_userData_assumeInside_(self.bounds(), self, 0, 0)
+		
+	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, total):
+		self.gain = gain
+		self.totalField = total
+		
+	def setLines(self, lines):
+		self.lines = lines
+		
+	def setMapImage(self, mapImage):
+		self.mapImage = mapImage
+		self.mapRect = ((0, 0), mapImage.size())
+		
+	def setPath(self, path, maxMag):
+		self.path = path
+		self.maxMag = maxMag
+		self.setNeedsDisplay_(1)
 
-    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 drawRect_(self, rect):
+		frame = self.frame()
+		self.origin = frame[0]
+		self.graphCenter = (frame[sze][x]/2, frame[sze][y]/2)
+		self.graphRadius = (min(frame[sze][x], frame[sze][y]) / 2) - self.graphMargin
+		
+		NSColor.whiteColor().set()
+		NSRectFill(self.bounds())
+		
+		self.drawMap()
+		self.drawGrid()
+		self.drawRMS()
+		self.drawField()
+
+	def drawMap(self):
+		if self.mapImage == 0:
+			return
+
+		scale = self.mapScale * (self.graphRadius / self.mapBaseRadius) * self.gain / self.totalField
+		xImageSize = scale * self.mapRect[sze][x]
+		yImageSize = scale * self.mapRect[sze][y]
+		xCenterMove = self.graphCenter[x] - self.graphRadius
+		yCenterMove = self.graphCenter[y] - self.graphRadius
+
+		xOffset = -((1 - self.mapOffsetEW) / 2) * xImageSize
+		yOffset = -((1 + self.mapOffsetNS) / 2) * yImageSize
+		xOffset += self.graphRadius + xCenterMove
+		yOffset += self.graphRadius + yCenterMove
+		
+		drawInRect = ((xOffset, yOffset), (xImageSize, yImageSize))
+
+		self.mapImage.drawInRect_fromRect_operation_fraction_(drawInRect, self.mapRect, NSCompositeSourceOver, self.mapVisible)
+		
+	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):
+		if self.maxMag:		# Don't want to divide by zero in the pathological case
+			self.graphColor.set()
+			path = self.path.copy()
+			
+			transform = NSAffineTransform.transform()
+			transform.rotateByRadians_(-(pi / 2.0) - self.azmuth)
+			path.transformUsingAffineTransform_(transform)
+			
+			transform = NSAffineTransform.transform()
+			center = self.graphCenter
+			transform.translateXBy_yBy_(center[0], center[1])
+			transform.scaleBy_(self.graphRadius / self.maxMag)
+			path.transformUsingAffineTransform_(transform)
+
+			path.stroke()
+			
+
+#____________________________________________________________
+# Handle GUI values
+
+	def mapVisibleSlider_(self, sender):
+		self.mapVisible = (sender.floatValue())
+		self.setNeedsDisplay_(1)
+
+	def azmuthDisplay_(self, sender):
+		self.setAzmuth(sender.floatValue())
+
+	def azmuthSlider_(self, sender):
+		self.setAzmuth(sender.floatValue())
+		
+	def setAzmuth(self, value):
+		self.azmuth = degToRad(value)
+		self.azmuthSlider.setFloatValue_(value)
+		self.azmuthDisplay.setFloatValue_(value)
+		self.setNeedsDisplay_(1)
+
+	def mapScaleDisplay_(self, sender):
+		self.mapScale = sender.floatValue()
+		self.setMapRect()
+
+	def mapScaleSlider_(self, sender):
+		self.mapScale = sender.floatValue()
+		self.setMapRect()
+
+	def mapOffsetNSDisplay_(self, sender):
+		self.mapOffsetNS = sender.floatValue()
+		self.setMapRect()
+
+	def mapOffsetNSSlider_(self, sender):
+		self.mapOffsetNS = sender.floatValue()
+		self.setMapRect()
+
+	def mapOffsetEWDisplay_(self, sender):
+		self.mapOffsetEW = sender.floatValue()
+		self.setMapRect()
+
+	def mapOffsetEWSlider_(self, sender):
+		self.mapOffsetEW = sender.floatValue()
+		self.setMapRect()
+	
+	def mouseUp_(self, event):
+		loc = event.locationInWindow()
+		xLoc = loc[x] - self.origin[x]
+		yLoc = loc[y] - self.origin[y]
+		xDelta = self.graphCenter[x] - xLoc
+		yDelta = self.graphCenter[y] - yLoc
+		
+		
+		scale = 0.5 * self.mapScale * (self.gain / self.totalField) * (self.graphRadius / self.mapBaseRadius)
+		xOffset = xDelta / (scale * self.mapRect[sze][x])
+		yOffset = yDelta / (scale * self.mapRect[sze][y]) 
+		
+		self.mapOffsetEW += xOffset
+		self.mapOffsetNS -= yOffset
+		self.setMapRect()
+		
+	def mouseDown_(self, event):
+		self.crossCursor.set()
+
+
+	def setMapRect(self):
+		self.mapScaleDisplay.setFloatValue_(self.mapScale)
+		self.mapScaleSlider.setFloatValue_(self.mapScale)
+		self.mapOffsetEWDisplay.setFloatValue_(self.mapOffsetEW)
+		self.mapOffsetEWSlider.setFloatValue_(self.mapOffsetEW)
+		self.mapOffsetNSDisplay.setFloatValue_(self.mapOffsetNS)
+		self.mapOffsetNSSlider.setFloatValue_(self.mapOffsetNS)
+		self.setNeedsDisplay_(1)
+	
+	def mouseEntered_(self, event):
+		print 'CGraphView: mouseEntered_'
+	
+	def mouseExited_(self, event):
+		print 'CGraphView: mouseExited_'

File pyobjc/Examples/FieldGraph/CrossCursor.tiff

Added
New image

File pyobjc/Examples/FieldGraph/English.lproj/InfoPlist.strings

Binary file modified.

File pyobjc/Examples/FieldGraph/English.lproj/MainMenu.nib/classes.nib

     IBClasses = (
         {
             ACTIONS = {
-                towerFieldDisplayValueControl0 = id; 
-                towerFieldDisplayValueControl1 = id; 
-                towerFieldDisplayValueControl2 = id; 
-                towerFieldSliderValueControl0 = id; 
-                towerFieldSliderValueControl1 = id; 
-                towerFieldSliderValueControl2 = id; 
-                towerPhaseDisplayValueControl0 = id; 
-                towerPhaseDisplayValueControl1 = id; 
-                towerPhaseDisplayValueControl2 = id; 
-                towerPhaseSliderValueControl0 = id; 
-                towerPhaseSliderValueControl1 = id; 
-                towerPhaseSliderValueControl2 = id; 
-                towerSpacingDisplayValueControl = id; 
-                towerSpacingSliderValueControl = id; 
+                fieldDisplay0 = id; 
+                fieldDisplay1 = id; 
+                fieldDisplay2 = id; 
+                fieldSlider0 = id; 
+                fieldSlider1 = id; 
+                fieldSlider2 = id; 
+                phaseDisplay0 = id; 
+                phaseDisplay1 = id; 
+                phaseDisplay2 = id; 
+                phaseSlider0 = id; 
+                phaseSlider1 = id; 
+                phaseSlider2 = id; 
+                settingDrawerButton = id; 
+                spacingDisplay = id; 
+                spacingSlider = id; 
             }; 
             CLASS = CGraphController; 
             LANGUAGE = ObjC; 
             OUTLETS = {
-                RMSGainDisplayValue = NSTextField; 
+                RMSGainDisplay = NSTextField; 
+                fieldDisplay0 = NSTextField; 
+                fieldDisplay1 = NSTextField; 
+                fieldDisplay2 = NSTextField; 
+                fieldNormalizeCheck = NSButton; 
+                fieldSlider0 = NSSlider; 
+                fieldSlider1 = NSSlider; 
+                fieldSlider2 = NSSlider; 
                 graphModel = CGraphModel; 
-                towerFieldDisplayValue0 = NSTextField; 
-                towerFieldDisplayValue1 = NSTextField; 
-                towerFieldDisplayValue2 = NSTextField; 
-                towerFieldSliderValue0 = NSSlider; 
-                towerFieldSliderValue1 = NSSlider; 
-                towerFieldSliderValue2 = NSSlider; 
-                towerPhaseDisplayValue0 = NSTextField; 
-                towerPhaseDisplayValue1 = NSTextField; 
-                towerPhaseDisplayValue2 = NSTextField; 
-                towerPhaseSliderValue0 = NSSlider; 
-                towerPhaseSliderValue1 = NSSlider; 
-                towerPhaseSliderValue2 = NSSlider; 
-                towerSpacingDisplayValue = NSTextField; 
-                towerSpacingSliderValue = NSSlider; 
+                graphView = CGraphView; 
+                phaseDisplay0 = NSTextField; 
+                phaseDisplay1 = NSTextField; 
+                phaseDisplay2 = NSTextField; 
+                phaseSlider0 = NSSlider; 
+                phaseSlider1 = NSSlider; 
+                phaseSlider2 = NSSlider; 
+                settingDrawer = NSDrawer; 
+                spacingDisplay = NSTextField; 
+                spacingSlider = NSSlider; 
             }; 
             SUPERCLASS = NSObject; 
         }, 
+        {CLASS = CGraphModel; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 
         {
-            CLASS = CGraphModel; 
+            ACTIONS = {
+                azmuthDisplay = id; 
+                azmuthSlider = id; 
+                mapOffsetEWDisplay = id; 
+                mapOffsetEWSlider = id; 
+                mapOffsetNSDisplay = id; 
+                mapOffsetNSSlider = id; 
+                mapScaleDisplay = id; 
+                mapScaleSlider = id; 
+                mapVisibleSlider = id; 
+            }; 
+            CLASS = CGraphView; 
             LANGUAGE = ObjC; 
-            OUTLETS = {graphView = CGraphView; }; 
-            SUPERCLASS = NSObject; 
+            OUTLETS = {
+                azmuthDisplay = NSTextField; 
+                azmuthSlider = NSSlider; 
+                mapOffsetEWDisplay = NSTextField; 
+                mapOffsetEWSlider = NSSlider; 
+                mapOffsetNSDisplay = NSTextField; 
+                mapOffsetNSSlider = NSSlider; 
+                mapScaleDisplay = NSTextField; 
+                mapScaleSlider = NSSlider; 
+                mapVisibleSlider = NSSlider; 
+            }; 
+            SUPERCLASS = NSView; 
         }, 
-        {CLASS = CGraphView; LANGUAGE = ObjC; SUPERCLASS = NSView; }, 
         {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }
     ); 
     IBVersion = 1; 

File pyobjc/Examples/FieldGraph/English.lproj/MainMenu.nib/info.nib

 <plist version="1.0">
 <dict>
 	<key>IBDocumentLocation</key>
-	<string>75 85 462 357 0 0 1440 878 </string>
+	<string>498 108 462 357 0 0 1440 878 </string>
 	<key>IBEditorPositions</key>
 	<dict>
 		<key>29</key>
 		<string>232 562 318 44 0 0 1440 878 </string>
+		<key>325</key>
+		<string>575 426 290 321 0 0 1440 878 </string>
 	</dict>
 	<key>IBFramework Version</key>
-	<string>291.0</string>
+	<string>313.0</string>
 	<key>IBOpenObjects</key>
 	<array>
+		<integer>325</integer>
 		<integer>21</integer>
 	</array>
 	<key>IBSystem Version</key>

File pyobjc/Examples/FieldGraph/English.lproj/MainMenu.nib/objects.nib

Binary file modified.

File pyobjc/Examples/FieldGraph/Main.py

 import CGraphController
 
 AppHelper.runEventLoop()
-

File pyobjc/Examples/FieldGraph/Map.png

Added
New image

File pyobjc/Examples/FieldGraph/buildapp.py

-#
-# Run this program from the command line like so:
-#
-# % python buildapp.py --link build
-#
-#
+#! /usr/local/python
+
+import os
 
 from bundlebuilder import buildapp
 
-SRC=[
-    'CGraphController.py',
-    'CGraphModel.py',
-    'CGraphView.py',
-    'fieldMath.py',
-]
+src = [ fn for fn in os.listdir('.') if fn.endswith('.py') and fn not in ('Main.py', 'buildapp.py') ]
 
 buildapp(
-    name = "FieldGraph",
-    mainprogram = "Main.py",
-    resources = ["English.lproj"] + SRC,
-    nibname = "MainMenu",
+	name = "FieldGraph",
+	mainprogram = "Main.py",
+	resources = ["English.lproj", 'CrossCursor.tiff', 'Map.png' ] + 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

File pyobjc/Lib/objc/test/test_methodedits.py

 import objc
 
 # NSIdEnumerator is not used anywhere else in the unittests
-MEClass  = objc.runtime.NSIdEnumerator
+#MEClass  = objc.runtime.NSIdEnumerator
 
 ## If you use this definition this test causes a crash.
-#class MEClass(objc.runtime.NSObject):
-#   pass
+class MEClass(objc.runtime.NSObject):
+   pass
 
 preEverythingInstance = MEClass.new()
 

File pyobjc/Modules/objc/module.m

 
 		/* install in methods to add */
 		objcMethod = &methodsToAdd->method_list[methodIndex];
-		objcMethod->method_name = PyObjCSelector_Selector(aMethod);
+		objcMethod->method_name = sel_registerName(PyObjCSelector_Selector(aMethod));
 
 		objcMethod->method_types = strdup(PyObjCSelector_Signature(
 			aMethod));

File pyobjc/Modules/objc/selector.m

 static PyObject*
 pysel_new(PyTypeObject* type, PyObject* args, PyObject* kwds);
 
+PyDoc_STRVAR(base_self_doc, "'self' object for bound methods, None otherwise");
+static PyObject*
+base_self(PyObjCSelector* self, void* closure __attribute__((__unused__)))
+{
+	if (self->sel_self) {
+		Py_INCREF(self->sel_self);
+		return self->sel_self;
+	} else {
+		Py_INCREF(Py_None);
+		return Py_None;
+	}
+}
+
 PyDoc_STRVAR(base_signature_doc, "Objective-C signature for the method");
 static PyObject*
 base_signature(PyObjCSelector* self, void* closure __attribute__((__unused__)))
 		0
 	},
 	{ 
+		"self", 
+		(getter)base_self, 
+		0,
+		base_self_doc, 
+		0
+	},
+	{ 
 		"selector",  
 		(getter)base_selector, 
 		0, 

File pyobjc/Scripts/CodeGenerators/dupfile.py

 class dupfile:
     def __init__(self, fname, mode):
         self.fname = fname
+        self.done = 0
         self.tfile = fname + ".wrk"
         self.mode = mode
 
     def close(self):
         self.fp.close()
         if self.mode == 'w':
-            if cmpfile(self.tfile, self.fname):
+            if os.path.exists(self.fname) and cmpfile(self.tfile, self.fname):
                 os.unlink(self.tfile)
             else:
                 os.rename(self.tfile, self.fname)
+        self.done = 1
+
+    def __del__(self):
+        if self.done:
+            return
+        if self.mode == 'w':
+            if os.path.exists(self.fname) and cmpfile(self.tfile, self.fname):
+                os.unlink(self.tfile)
+            else:
+                os.rename(self.tfile, self.fname)

File pyobjc/Scripts/CodeGenerators/func_collector.py

 	for f in fnames:
 		process_file(fp, f, match_prefix, ignore_list)
 
+        fp.close()
+
 if __name__ == "__main__":
 	import sys
 	generate(sys.argv[1], match_prefix=sys.argv[2])