PythonCard on the Mac
I needed to get PythonCard working on my mac for a course I'm teaching with Warren and Carter Sande's book, Hello World! By changing the model.py file that comes with PythonCard 0.8.2, I was able to run resourceEditor.py from a Terminal window and complete the TempGUI project in chapter 20 of the book.
If you'd like to see if this change will work for you, download my model.py. Do a search for model.py on your hard drive. Rename the original (I renamed mine to model.original.py) in case you need it later. Then copy the downloaded model.py to the same directory. The directory name will be something like:
For the Curious Hacker
Below are the changes I made. I'm relatively new to Python, and brand new to PythonCard, so if you have a cleaner solution that works on your mac, please shoot me an email at firstname.lastname@example.org.
My problem occurred while running:
I got the following error running resourceEditor.py out of iTerm:
TJ-Leones-MacBook-Pro:resourceEditor tjleone$ python resourceEditor.py no resource file for /Library/Frameworks/Python.framework/Versions/2.6/lib/pytho n2.6/site-packages/PythonCard/tools/resourceEditor/propertyEditor Traceback (most recent call last): File "/usr/local/lib/wxPython-unicode-188.8.131.52/lib/python2.6/site-packages/wx -2.8-mac-unicode/wx/_core.py", line 14669, in <lambda> lambda event: event.callable(*event.args, **event.kw) ) File "resourceEditor.py", line 138, in on_initialize self.propertyEditorWindow = model.childWindow(self, PropertyEditor) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-pa ckages/PythonCard/model.py", line 213, in childWindow rsrc = resource.ResourceFile(filename).getResource() File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-pa ckages/PythonCard/resource.py", line 45, in __init__ self.dictionary = util.readAndEvalFile(rsrcFileName) File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-pa ckages/PythonCard/util.py", line 39, in readAndEvalFile f = open(filename) TypeError: coercing to Unicode: need string or buffer, NoneType found
I traced the error back to the inability to find propertyEditor.py in PythonCard/tools/resourceEditor/modules/. I was afraid to move files around, so I added a couple of conditions to the internationalResourceName() function in model.py instead.
Here's the original version:
def internationalResourceName(base): ... # AGT 2005-05-17 Detect missing resource file, give some warning; no clean recovery possible. filename = None for f in filenames: if os.path.exists(f): filename = f break if not filename: print "no resource file for", base return filename
Here's my change:
def internationalResourceName(base): ... # AGT 2005-05-17 Detect missing resource file, give some warning; no clean recovery possible. filename = None for f in filenames: if os.path.exists(f): filename = f break if not filename: for f in filenames: ## A workaround to find files in the modules directory --TJ fn = os.path.join(os.path.dirname(f), "modules", os.path.basename(f)) if os.path.exists(fn): filename = fn break if not filename: print "no resource file for", base return filename
Leone Learning Systems, Inc. (LLS) is a North Shore company that provides online courses for kids anywhere and local teaching and tutoring services for students in Chicago and the Northern Suburbs of Chicagoland. LLS also provides a free geometry software package for children age 6 and up, and free resources for teachers and parents. This site includes information about tutoring and classes provided, learning activities for kids, lesson plans, and ongoing software and curriculum research and development efforts.