From: Kevin A. <ka...@us...> - 2004-05-11 01:12:59
|
Update of /cvsroot/pythoncard/PythonCard/samples/turtle In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23170 Modified Files: readme.txt turtle.py Removed Files: tWrapper.py wxTurtleCurves.py Log Message: changed turtle script to Python modules changed how modules are run by using __import__ refactored the turtle wrappers removed redundant examples --- tWrapper.py DELETED --- --- wxTurtleCurves.py DELETED --- Index: turtle.py =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/turtle/turtle.py,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** turtle.py 5 May 2004 16:53:48 -0000 1.22 --- turtle.py 11 May 2004 01:12:50 -0000 1.23 *************** *** 15,63 **** import os import time - from math import * # Also for export - import wx class TurtleBg(model.Background): - - """ - as per other samples, __init__ will go away once we are doing - openStack, openBackground messages - the font initialization, dc, and other wxPython code exposed below - will be hidden as those features are added to the PythonCard - framework - """ def on_initialize(self, event): ! self.fNameTurtleScript = "scripts/4bugs.txt" ! sizer1 = wx.BoxSizer(wx.VERTICAL) ! comp = self.components ! #flags = wx.LEFT | wx.RIGHT | wx.BOTTOM | wx.ALIGN_BOTTOM ! #sizer1.Add(comp.btnColor._delegate, 0, flags, 5) ! sizer1.Add(comp.bufOff, 1, wx.EXPAND) ! ! sizer1.Fit(self) ! sizer1.SetSizeHints(self) ! self.panel.SetSizer(sizer1) ! self.panel.SetAutoLayout(1) ! self.panel.Layout() self.components.bufOff.backgroundColor = 'white' if wx.Platform == '__WXMAC__': ! self.menuBar.setChecked('menuCommandsAutoRefresh', 0) ! self.components.bufOff.autoRefresh = 0 def doDraw(self): starttime = time.time() ! ###dc = wxTurtle.TurtleDC(self.panel) ! ###dc.BeginDrawing() ! input = open(self.fNameTurtleScript, 'r') ! codeString = input.read() ! input.close() ! namespace = {} # Just an empty dictionary ! exec(codeString, None, namespace) ! func = namespace['drawMain'] # or some other predefined name ! func(self.components.bufOff, self) if not self.components.bufOff.autoRefresh: self.components.bufOff.refresh() --- 15,43 ---- import os import time class TurtleBg(model.Background): def on_initialize(self, event): ! self.fNameTurtleScript = os.path.join('scripts', 'threeTurtles.py') ! self.singleItemExpandingSizerLayout() self.components.bufOff.backgroundColor = 'white' if wx.Platform == '__WXMAC__': ! self.menuBar.setChecked('menuCommandsAutoRefresh', False) ! self.components.bufOff.autoRefresh = False def doDraw(self): starttime = time.time() ! cwd = os.getcwd() ! path, filename = os.path.split(self.fNameTurtleScript) ! os.chdir(path) ! module = __import__(os.path.splitext(filename)[0], globals(), globals()) ! # make sure that if this module was previously imported ! # that we get the new version ! reload(module) ! module.draw(self.components.bufOff) ! os.chdir(cwd) if not self.components.bufOff.autoRefresh: self.components.bufOff.refresh() *************** *** 65,71 **** # back in sync with the menu self.components.bufOff.autoRefresh = self.menuBar.getChecked('menuCommandsAutoRefresh') ! ! ###dc.EndDrawing() ! stoptime = time.time() elapsed = stoptime - starttime --- 45,49 ---- # back in sync with the menu self.components.bufOff.autoRefresh = self.menuBar.getChecked('menuCommandsAutoRefresh') ! stoptime = time.time() elapsed = stoptime - starttime *************** *** 74,78 **** def on_menuFileOpen_select(self, event): currentDir = os.getcwd() ! wildcard = "Turtle files (*.txt)|*.txt" path = 'scripts' filename = '' --- 52,56 ---- def on_menuFileOpen_select(self, event): currentDir = os.getcwd() ! wildcard = "Turtle files (*.py)|*.py" path = 'scripts' filename = '' *************** *** 91,95 **** # of commands I want to support in the menu and whether # they should be global or specific to individual turtles - ###self.panel._getDelegate().Refresh() self.components.bufOff.clear() if not self.components.bufOff.autoRefresh: --- 69,72 ---- Index: readme.txt =================================================================== RCS file: /cvsroot/pythoncard/PythonCard/samples/turtle/readme.txt,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** readme.txt 17 Jul 2002 21:28:57 -0000 1.3 --- readme.txt 11 May 2004 01:12:50 -0000 1.4 *************** *** 18,21 **** 2002-07-17 Update: All of the samples will draw dramatically faster if Auto Refresh is unchecked in the Commands menu. If you have a fast machine and especially if you have a fast video card such as a nVidia GeForce2 or better, then a lot of the turtle samples will draw reasonably fast, except where points are plotted; the full window blit after each drawing operation will make even those sample scripts slow. If you have on-board video or a slow machine you will definitely want to uncheck Auto Refresh! This applies to Mac OS X as well which seems quite slow if Auto Refresh is checked. - - I have not updated the comments in the scripts for almost a year, so many of the comments could apply to older versions of the turtle drawing routines and should be taken with a grain of salt. If there is demand, I'll revisit the drawing support in PythonCard and refactor and speed up operations where possible. See the hopalong sample (not the turtle version of hopalong) if you are interested in plotting data. It is much faster. \ No newline at end of file --- 18,19 ---- |