BuildApplet.py :  » Language-Interface » ChinesePython » chinesepython2.1.3-0.4 » Mac » scripts » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Language Interface » ChinesePython 
ChinesePython » chinesepython2.1.3 0.4 » Mac » scripts » BuildApplet.py
"""Create an applet from a Python script.

This puts up a dialog asking for a Python source file ('TEXT').
The output is a file with the same name but its ".py" suffix dropped.
It is created by copying an applet template and then adding a 'PYC '
resource named __main__ containing the compiled, marshalled script.
"""


import sys
sys.stdout = sys.stderr

import os
import macfs
import MacOS
import EasyDialogs
import buildtools


def main():
  try:
    buildapplet()
  except buildtools.BuildError, detail:
    EasyDialogs.Message(detail)


def buildapplet():
  buildtools.DEBUG=1
  
  # Find the template
  # (there's no point in proceeding if we can't find it)
  
  template = buildtools.findtemplate()
  
  # Ask for source text if not specified in sys.argv[1:]
  
  if not sys.argv[1:]:
    srcfss, ok = macfs.PromptGetFile('Select Python source or applet:', 'TEXT', 'APPL')
    if not ok:
      return
    filename = srcfss.as_pathname()
    tp, tf = os.path.split(filename)
    if tf[-3:] == '.py':
      tf = tf[:-3]
    else:
      tf = tf + '.applet'
    dstfss, ok = macfs.StandardPutFile('Save application as:', tf)
    if not ok: return
    dstfilename = dstfss.as_pathname()
    cr, tp = MacOS.GetCreatorAndType(filename)
    if tp == 'APPL':
      buildtools.update(template, filename, dstfilename)
    else:
      buildtools.process(template, filename, dstfilename, 1)
  else:
    
    # Loop over all files to be processed
    for filename in sys.argv[1:]:
      cr, tp = MacOS.GetCreatorAndType(filename)
      if tp == 'APPL':
        buildtools.update(template, filename, '')
      else:
        buildtools.process(template, filename, '', 1)


if __name__ == '__main__':
  main()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.