## [Jython-checkins] SF.net SVN: jython:[6656] trunk/jython/Lib/test/Graph.py

 [Jython-checkins] SF.net SVN: jython:[6656] trunk/jython/Lib/test/Graph.py From: - 2009-08-10 18:59:06 ```Revision: 6656 http://jython.svn.sourceforge.net/jython/?rev=6656&view=rev Author: fwierzbicki Date: 2009-08-10 18:58:58 +0000 (Mon, 10 Aug 2009) Log Message: ----------- Reindent, mainly 8 space -> 4 space Modified Paths: -------------- trunk/jython/Lib/test/Graph.py Modified: trunk/jython/Lib/test/Graph.py =================================================================== --- trunk/jython/Lib/test/Graph.py 2009-08-10 18:56:57 UTC (rev 6655) +++ trunk/jython/Lib/test/Graph.py 2009-08-10 18:58:58 UTC (rev 6656) @@ -3,60 +3,60 @@ from jarray import array class Graph(awt.Canvas): - def __init__(self): - self.function = None + def __init__(self): + self.function = None - def paint(self, g): - if self.function is None: - return self.error(g) - - sz = self.size - xs = range(0, sz.width, 2) - - xscale = 4*pi/sz.width - xoffset = -2*pi - - yscale = -sz.height/2. - yoffset = sz.height/2. - - ys = [] - for x in xs: - x = xscale*x + xoffset - y = int(yscale*self.function(x)+yoffset) - ys.append(y) - g.drawPolyline(array(xs, 'i'), array(ys, 'i'), len(xs)) + def paint(self, g): + if self.function is None: + return self.error(g) - def error(self, g): - message = "Invalid Expression" - g.font = awt.Font('Serif', awt.Font.BOLD, 20) - width = g.fontMetrics.stringWidth(message) - - x = (self.size.width-width)/2 - y = (self.size.height+g.fontMetrics.height)/2 - g.drawString("Invalid Expression", x, y) - - def setExpression(self, e): - try: - self.function = eval('lambda x: '+e) - except: - self.function = None - self.repaint() - + sz = self.size + xs = range(0, sz.width, 2) + xscale = 4*pi/sz.width + xoffset = -2*pi + + yscale = -sz.height/2. + yoffset = sz.height/2. + + ys = [] + for x in xs: + x = xscale*x + xoffset + y = int(yscale*self.function(x)+yoffset) + ys.append(y) + g.drawPolyline(array(xs, 'i'), array(ys, 'i'), len(xs)) + + def error(self, g): + message = "Invalid Expression" + g.font = awt.Font('Serif', awt.Font.BOLD, 20) + width = g.fontMetrics.stringWidth(message) + + x = (self.size.width-width)/2 + y = (self.size.height+g.fontMetrics.height)/2 + g.drawString("Invalid Expression", x, y) + + def setExpression(self, e): + try: + self.function = eval('lambda x: '+e) + except: + self.function = None + self.repaint() + + if __name__ == '__main__': - def enter(e): - graph.setExpression(expression.text) - expression.caretPosition=0 - expression.selectAll() - - p = awt.Panel(layout=awt.BorderLayout()) - graph = Graph() - p.add(graph, 'Center') - - expression = awt.TextField(text='(sin(3*x)+cos(x))/2', actionPerformed=enter) - p.add(expression, 'South') - - import pawt - pawt.test(p, size=(300,300)) - - enter(None) + def enter(e): + graph.setExpression(expression.text) + expression.caretPosition=0 + expression.selectAll() + + p = awt.Panel(layout=awt.BorderLayout()) + graph = Graph() + p.add(graph, 'Center') + + expression = awt.TextField(text='(sin(3*x)+cos(x))/2', actionPerformed=enter) + p.add(expression, 'South') + + import pawt + pawt.test(p, size=(300,300)) + + enter(None) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```

 [Jython-checkins] SF.net SVN: jython:[6656] trunk/jython/Lib/test/Graph.py From: - 2009-08-10 18:59:06 ```Revision: 6656 http://jython.svn.sourceforge.net/jython/?rev=6656&view=rev Author: fwierzbicki Date: 2009-08-10 18:58:58 +0000 (Mon, 10 Aug 2009) Log Message: ----------- Reindent, mainly 8 space -> 4 space Modified Paths: -------------- trunk/jython/Lib/test/Graph.py Modified: trunk/jython/Lib/test/Graph.py =================================================================== --- trunk/jython/Lib/test/Graph.py 2009-08-10 18:56:57 UTC (rev 6655) +++ trunk/jython/Lib/test/Graph.py 2009-08-10 18:58:58 UTC (rev 6656) @@ -3,60 +3,60 @@ from jarray import array class Graph(awt.Canvas): - def __init__(self): - self.function = None + def __init__(self): + self.function = None - def paint(self, g): - if self.function is None: - return self.error(g) - - sz = self.size - xs = range(0, sz.width, 2) - - xscale = 4*pi/sz.width - xoffset = -2*pi - - yscale = -sz.height/2. - yoffset = sz.height/2. - - ys = [] - for x in xs: - x = xscale*x + xoffset - y = int(yscale*self.function(x)+yoffset) - ys.append(y) - g.drawPolyline(array(xs, 'i'), array(ys, 'i'), len(xs)) + def paint(self, g): + if self.function is None: + return self.error(g) - def error(self, g): - message = "Invalid Expression" - g.font = awt.Font('Serif', awt.Font.BOLD, 20) - width = g.fontMetrics.stringWidth(message) - - x = (self.size.width-width)/2 - y = (self.size.height+g.fontMetrics.height)/2 - g.drawString("Invalid Expression", x, y) - - def setExpression(self, e): - try: - self.function = eval('lambda x: '+e) - except: - self.function = None - self.repaint() - + sz = self.size + xs = range(0, sz.width, 2) + xscale = 4*pi/sz.width + xoffset = -2*pi + + yscale = -sz.height/2. + yoffset = sz.height/2. + + ys = [] + for x in xs: + x = xscale*x + xoffset + y = int(yscale*self.function(x)+yoffset) + ys.append(y) + g.drawPolyline(array(xs, 'i'), array(ys, 'i'), len(xs)) + + def error(self, g): + message = "Invalid Expression" + g.font = awt.Font('Serif', awt.Font.BOLD, 20) + width = g.fontMetrics.stringWidth(message) + + x = (self.size.width-width)/2 + y = (self.size.height+g.fontMetrics.height)/2 + g.drawString("Invalid Expression", x, y) + + def setExpression(self, e): + try: + self.function = eval('lambda x: '+e) + except: + self.function = None + self.repaint() + + if __name__ == '__main__': - def enter(e): - graph.setExpression(expression.text) - expression.caretPosition=0 - expression.selectAll() - - p = awt.Panel(layout=awt.BorderLayout()) - graph = Graph() - p.add(graph, 'Center') - - expression = awt.TextField(text='(sin(3*x)+cos(x))/2', actionPerformed=enter) - p.add(expression, 'South') - - import pawt - pawt.test(p, size=(300,300)) - - enter(None) + def enter(e): + graph.setExpression(expression.text) + expression.caretPosition=0 + expression.selectAll() + + p = awt.Panel(layout=awt.BorderLayout()) + graph = Graph() + p.add(graph, 'Center') + + expression = awt.TextField(text='(sin(3*x)+cos(x))/2', actionPerformed=enter) + p.add(expression, 'South') + + import pawt + pawt.test(p, size=(300,300)) + + enter(None) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```