Thursday, January 12, 2012

writePictureTo fails, how to fix it

The Symptom is this: you use the native JES writePictureTo or you use our wrapper copyPic so save picture p as file pic.jpg. If you look in your Media Folder then you wil see pic.jpg. If you look closer you will see the file is empty.  This is a known JES problem as documented in the mediacomp repository (where JES lives).

The Problem for us is that all of your account names have a first.last format.

Here is the best Solution I can offer for working on school machines. You only need to do this if you are having the problem. (And on your own machine you can solve this more easily.)


  • Find the setMediaFolder( '...') line in your labcode.py file. Change it to mPath='...'  where the ... is just the path to your media folder. It should be at the top of the file.
  • Open Computer and navigate to C:\USers\Public. Right click and create a new folder JOTMP, where JO is replaced by your own initials.
  • Back in your labcode.py file add the line:  setMediaFolder("C:\\Users\\Public\\JOTMP\\") -- again replacing JO with your own initials. (This should be just below the mpath=.. line
  • Add the line    import os    to your file just below the setMediaFolder line
  • Add the following function just below import os
def doSave(pic, name ):
  writePictureTo(pic,name)
  s = getMediaPath() + name
  try:
    os.rename( s, mPath + name) 
  except Exception, e:
    print e
  • Any time you want to write picture p to file pic.jpg issue the command:  doSave( p, 'pic.jpg')
  • Note, the try/except lines are only there for debugging purposes. The following should work, but if you have an error the message will not be as helpful:
def doSave(pic, name ):
  writePictureTo(pic,name)
  s = getMediaPath() + name
  os.rename( s, mPath + name) 
 


The Down Side is that your media folder is no longer set where you really want it, so file dialogs (pickAFile() will be a bit of a pain.)

How it works: If we can code (and we can) then we can control the machine. JES cannot handle dots in path names. So we write the file into a place we can write that does not have a dot. Public works. However, we do not want to leve our stuff there -- anyone can erase it, see it etc. And we would be polluting the pubic space. So we create a space that looks like ours -- it has our initials -- and we write the file there. But we do not trust ourselves to remember to always copy over to our media folder, so we use jython to move the file for us. If you can program (you can) then you can make the machine do what you want it to.

No comments:

Post a Comment