Advertisement
here2share

b_gui4py2exe.py

Jul 5th, 2018
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.91 KB | None | 0 0
  1. # b_gui4py2exe.py
  2.  
  3. '''
  4. People often want to suppress the console when they're packaging their app for other computers (e.g. via py2exe), and they don't want the users to be distracted by an ugly console. It's also easy to get rid of the console in an app packaged with py2exe; just put the script in the "windows" key of the setup dictionary. Here's an example setup.py that does this.
  5. '''
  6.  
  7. from distutils.core import setup
  8. import py2exe
  9. import sys
  10. import os
  11. import time
  12.  
  13. VERSION = "1.0"
  14. PROG_NAME = "My Program"
  15. DESCRIPTION = "Description of the program"
  16.  
  17. MANIFEST_TEMPLATE = """
  18. <assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestversion="1.0">
  19. <assemblyidentity>
  20. </assemblyidentity>     version="5.0.0.0"
  21.     processorArchitecture="x86"
  22.     name="%(name)s"
  23.     type="win32"
  24. />
  25. <description>%(name)s Program</description>
  26. <dependency>
  27.     <dependentassembly>
  28.         <assemblyidentity>
  29. </assemblyidentity>             type="win32"
  30.             name="Microsoft.Windows.Common-Controls"
  31.             version="6.0.0.0"
  32.             processorArchitecture="X86"
  33.             publicKeyToken="6595b64144ccf1df"
  34.             language="*"
  35.         />
  36.     </dependentassembly>
  37. </dependency>
  38. </assembly>
  39. """.strip()
  40.  
  41. RT_MANIFEST = 24
  42. """Resource ID in Windows executables"""
  43.  
  44. def main():
  45.     """Create a setup file"""
  46.  
  47.     manifest = MANIFEST_TEMPLATE % dict(name=PROG_NAME)
  48.     ugly_name = PROG_NAME.replace(" ", "")
  49.  
  50.     prog_dict = dict(version=VERSION,
  51.                      company_name = "My Company",
  52.                      copyright = "(C) My Company",
  53.                      author = "My Company",
  54.                      author_email = "support@mycompany.com",
  55.                      description=DESCRIPTION,
  56.                      script="main.py",
  57.                      #icon_resources = [(1, "./res/%s.ico" % ugly_name)],
  58.                      other_resources = [(RT_MANIFEST, 1, manifest)],
  59.                      dest_base= ugly_name,
  60.                      name= "%s Application v %s" % (PROG_NAME,
  61.                                           VERSION)
  62.        )
  63.  
  64.     setup_dict = {}
  65.     setup_dict['windows'] = [prog_dict]
  66.     setup_dict['console'] = []
  67.  
  68.     excludes = ["pywin", "pywin.debugger", "pywin.debugger.dbgcon",
  69.             "pywin.dialogs", "pywin.dialogs.list", "win32com.server",
  70.             "email"]
  71.  
  72.     options = dict(optimize=2,
  73.                dist_dir=PROG_NAME.replace(" ", ""),
  74.                excludes=excludes)
  75.  
  76.     setup_dict['options'] = {"py2exe" : options}
  77.  
  78.     # If run without args, build executables, in quiet mode.
  79.     if len(sys.argv) == 1:
  80.          sys.argv.append("py2exe")
  81.          sys.argv.append("-q")
  82.  
  83.     start_time = time.time()
  84.  
  85.     os.chdir(os.path.dirname(__file__))
  86.  
  87.     print "Creating exe..."
  88.     setup(
  89.           **setup_dict
  90.         )
  91.  
  92.     print "Created exe in", time.time() - start_time, "seconds"
  93.  
  94. if __name__ == "__main__":
  95.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement