From: <jon...@wa...> - 2004-12-03 16:31:57
|
I found a script that will out-put the PythonCard components of a resou= rce file. I did not write it, so I can't take credit for it. I only updated it f= or the 0.8 release. Usage: resource.py yourresourcefile.rsrc.py #!/usr/bin/python2.3 import sys #from PythonCardPrototype import res from PythonCard import resource def GetResourceImports(rsrcFileName): rsrcImports =3D [] builtinimport =3D __builtins__.__dict__['__import__'] def wrapimport(name, globals, locals, fromlist): rsrcImports.append((name, fromlist)) return apply(builtinimport, (name, globals, locals, fromlis= t)) __builtins__.__dict__['__import__'] =3D wrapimport rsrcFile =3D resource.ResourceFile(rsrcFileName) rsrc =3D rsrcFile.getResource() # revert to old import __builtins__.__dict__['__import__'] =3D builtinimport return rsrcImports def importcommand(name, fromlist): # """returns a string containing a command to import the module refer= red to by name, fromlist""" # either it's a tuple: import stuff from a module if type(fromlist) =3D=3D tuple: return "from "+name+" import "+",".join(fromlist) # or it's a import from a package elif type(fromlist) =3D=3D list: namelist =3D name.split('.') prefixlen =3D len(fromlist) for n in range(prefixlen): if fromlist[n] !=3D namelist[n]: prefixlen =3D n break if prefixlen =3D=3D 0: return "import "+name else: # if prefixlen>1, we have a problem... return "from "+".".join(namelist[:prefixlen])+" impor= t "+".".join(namelist[prefixlen:]) # or it's just a simple import else: return "import "+name def tryimports(imports): print "import traceback" # for handling errors for name, fromlist in imports: # print name, fromlist print "try:" print " ",importcommand(name, fromlist) print "except ImportError:" print " traceback.print_exc()" if __name__ =3D=3D '__main__': rsrcFileName =3D sys.argv[1] imports =3D GetResourceImports(rsrcFileName) if '--allcomponents' in sys.argv: tryimports(imports) else: # by default, handle PythonCard component imports print "#!/usr/bin/python2.2" print ''' """This file was autogenerated by resimports.py to import all the PythonCard components referred to by %s This is useful in generating dependencies for an installer """ ''' % rsrcFileName for name, fromlist in imports: if fromlist =3D=3D ['components']: print importcommand("PythonCardPrototype."+name= , ['PythonCardPrototype']+fromlist) Jonathan Papageorgiou |---------+--------------------------------------------> | | Gregory Pi=F1ero | | | <gre...@gm...> | | | Sent by: | | | pyt...@li...ur| | | ceforge.net | | | | | | | | | 12/01/2004 04:11 PM | | | Please respond to Gregory Pi=F1ero | | | | |---------+--------------------------------------------> >--------------------------------------------------------------------= ----------------------------------------------------------| | = | | To: Ruben Marquez <rmc...@ya...> = | | cc: pyt...@li... = | | Subject: Re: [Pythoncard-users] Using py2exe with pythoncard= | >--------------------------------------------------------------------= ----------------------------------------------------------| Wow it finally worked! Thanks! I just had to add: from PythonCard.components import button,image,staticbox,statictext,textarea,textfield Though I'm slightly dissapointed it didn't make just one big exe file, but rather a whole folder of junk. Do I need to bring that whole folder to another computer in order to run my program? Wish me luck on my presentation tonight on a computer that I'm not allowed to install python on ;-) -Greg On Wed, 1 Dec 2004 12:35:18 -0800 (PST), Ruben Marquez <rmc...@ya...> wrote: > Gregory, > > I know, there is a lot to take in when you are getting > started. Note that Kevin said: > > "You need to specifically import the component modules > that you use in your resource file" > > What that means is that, when using py2exe, you have > to explicitly import each component that you use in > your app individually. In other words, it is not > enough to do: > > from PythonCard import model, dialog, etc... > > In addition to that, you need to do: > > from PythonCard.components import button, radiogroup, > etc... > > -Ruben > > > __________________________________ > Do you Yahoo!? > Read only the mail you want - Yahoo! Mail SpamGuard. > http://promotions.yahoo.com/new_mail > ------------------------------------------------------- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users= . Discover which products truly live up to the hype. Start reading now. http://productguide.itmanagersjournal.com/ _______________________________________________ Pythoncard-users mailing list Pyt...@li... https://lists.sourceforge.net/lists/listinfo/pythoncard-users = |