[howto] dabo use py2exe to generate win32 gui e...

author: kjpioo2006 # the_gmail dot com

1环境:

  • dabo 版本信息
package_name = "dabo"
_version = "0.9.3"
_approximateRevision = "~6293"
  • python 2.7
  • 测试app名为webtest,用dabo的appWizard生成,使用sqlite3数据库,名为webtest.sqlite3。
  • webtest目录下已经自动产生了默认的 buildwin.bat 和setup.py
  • py2exe为dabo GUI应用软件生成win32 exe 文件,需要python安装这些module:  
  1. win32com

2生成 EXE

1) setup.py修改

根据 官方提供的 setup.py (官方用了3年都没出现问题),需要对appWizard生成的setup.py 适当修改(下面列出diff文件,左侧是默认setup.py,右侧是修正后的):

diff --git "a/C:\\DOCUME~1\\ADMINI~1\\LOCALS~1\\Temp\\set477.tmp\\setup-HEAD-left.py" "b/D:\\tmp\\python\\daboframework\\test\\webtest\\setup.py"
index bef4677..86d6ede 100644
--- "a/C:\\DOCUME~1\\ADMINI~1\\LOCALS~1\\Temp\\set477.tmp\\setup-HEAD-left.py"
+++ "b/D:\\tmp\\python\\daboframework\\test\\webtest\\setup.py"
@@ -23,23 +23,21 @@ import glob
 if sys.platform.startswith("win"):
 	from distutils.core import setup
 	import py2exe
-elif sys.platform.startswith("darwin"):
+else:
 	from setuptools import setup
-	import py2app
-elif sys.platform.startswith("linux"):
-	from cx_Freeze import setup, Executable
+	if sys.platform.startswith("darwin"):
+		import py2app
 import dabo.icons
 from App import App
 
 
 daboDir = os.path.split(dabo.__file__)[0]
 
-
 # Find the location of the dabo icons:
 iconDir = os.path.split(dabo.icons.__file__)[0]
 iconSubDirs = []
 def getIconSubDir(arg, dirname, fnames):
-	if ".svn" not in dirname and dirname[-1] != "\\":
+	if ".svn" not in dirname and "cards" not in dirname.lower() and dirname[-1] != "\\":
 		icons = glob.glob(os.path.join(dirname, "*.png"))
 		if icons:
 			subdir = (os.path.join("resources", dirname[len(arg)+1:]), icons)
@@ -51,12 +49,12 @@ localeDir = "%s%slocale" % (daboDir, os.sep)
 #locales = [("dabo.locale", (os.path.join(daboDir, "locale", "dabo.pot"),))]
 locales = []
 def getLocales(arg, dirname, fnames):
-  if ".svn" not in dirname and dirname[-1] != "\\":
-    #po_files = tuple(glob.glob(os.path.join(dirname, "*.po")))
-    mo_files = tuple(glob.glob(os.path.join(dirname, "*.mo")))
-    if mo_files:
-      subdir = os.path.join("dabo.locale", dirname[len(arg)+1:])
-      locales.append((subdir, mo_files))
+	if ".svn" not in dirname and dirname[-1] != "\\":
+		#po_files = tuple(glob.glob(os.path.join(dirname, "*.po")))
+		mo_files = tuple(glob.glob(os.path.join(dirname, "*.mo")))
+		if mo_files:
+			subdir = os.path.join("dabo.locale", dirname[len(arg)+1:])
+			locales.append((subdir, mo_files))
 os.path.walk(localeDir, getLocales, localeDir)
 
 # The applications App object contains all the meta info:
@@ -64,26 +62,25 @@ app = App(MainFormClass=None)
 
 _appName = app.getAppInfo("appName")
 _appShortName = app.getAppInfo("appShortName")
+_appFileStem = _appShortName.lower().replace(" ", "_")
 _appVersion = app.getAppInfo("appVersion")
 _appDescription = app.getAppInfo("appDescription")
 _copyright = app.getAppInfo("copyright")
-_authorName = app.getAppInfo("authorName")
+_authorName = app.getAppInfo("authorName") 
 _authorEmail = app.getAppInfo("authorEmail")
 _authorURL = app.getAppInfo("authorURL")
 _authorPhone = app.getAppInfo("authorPhone")
 
-
 _appComments = ("This is custom software by %s.\r\n"
 		"\r\n"
-		"%s\r\n"
-		"%s\r\n"
+		"%s\r\n" 
+		"%s\r\n" 
 		"%s\r\n") % (_authorName, _authorEmail, _authorURL, _authorPhone)
 
-# Set your app icon here:
-_appIcon = None
-#_appIcon = "./resources/stock_addressbook.ico"
 
+_appIcon = None
 _script = "webtest.py"
+
 manifest = open("webtest.exe.manifest").read()
 
 class Target:
@@ -98,9 +95,9 @@ class Target:
 		self.comments = _appComments
 
 		self.script=_script
-		self.other_resources=[(24, 1, manifest)]
+		self.other_resources = [(24, 1, manifest)]
 		if _appIcon is not None:
-			self.icon_resources=[(1, _appIcon)]
+			self.icon_resources = [(1, _appIcon)]
 
 
 data_files=[("db", ["db/default.cnxml"]),
@@ -133,22 +130,28 @@ if sys.platform.startswith("win"):
 			data_files=data_files
 	)
 
+	# Write out the setup.iss file for inno:
+	#iss = open("setup.iss.txt").read() % locals()
+	#open("setup.iss", "wb").write(iss)
+
 elif sys.platform.startswith("darwin"):
 	options = {"py2app":
-			{"includes": ["App", "__version__", "ui", "biz", "encodings",
-				"wx", "wx.lib.calendar", "wx.gizmos"],
-			"optimize": 2,
-			"excludes": ["matplotlib", "Tkconstants","Tkinter","tcl",
-				"_imagingtk", "PIL._imagingtk",
-				"ImageTk", "PIL.ImageTk", "FixTk", "wxPython",],
-			"argv_emulation": True,
-			"resources": data_files,
-			"plist": dict(CFBundleGetInfoString=_appVersion,
-				CFBundleIdentifier="com.example.webtest",
-				LSPrefersPPC=False,
-				NSHumanReadableCopyright=_copyright),
-			#"iconfile": "resources/logo_green.icns",
-			}}
+	              {"includes": ["App", "__version__", "constants", "db.updates", 
+	                            "ui", "biz", "ss_common.lib.floatcanvas",
+	                            "encodings", "wx", "wx.lib.calendar", "wx.gizmos"],
+	              "optimize": 2,
+	              "excludes": ["matplotlib", "Tkconstants","Tkinter","tcl", 
+	                          "_imagingtk", "PIL._imagingtk",
+	                          "ImageTk", "PIL.ImageTk", "FixTk", "wxPython",
+	                          ],
+	              "argv_emulation": True,
+	              "resources": data_files,
+	              "plist": dict(CFBundleGetInfoString=_appVersion,
+	                            LSPrefersPPC=False,
+	                            NSHumanReadableCopyright=_copyright
+	                           ),
+	              }
+	          }
 
 	setup(name=_appName,
 		app=[_script],
@@ -183,4 +186,3 @@ elif sys.platform.startswith("linux"):
 		executables=[Executable(_script, compress=True,
 				appendScriptToExe=True)],
 		options=options)
-


2) buildwin.bat文件需要根据实际路径修改:

diff --git "a/C:\\DOCUME~1\\ADMINI~1\\LOCALS~1\\Temp\\bui474.tmp\\buildwin-HEAD-left.bat" "b/D:\\tmp\\python\\daboframework\\test\\webtest\\buildwin.bat"
index f0733a6..131f6c3 100644
--- "a/C:\\DOCUME~1\\ADMINI~1\\LOCALS~1\\Temp\\bui474.tmp\\buildwin-HEAD-left.bat"
+++ "b/D:\\tmp\\python\\daboframework\\test\\webtest\\buildwin.bat"
@@ -1,9 +1,11 @@
 del /q dist
 rmdir /s /q dist build
 
-python -OO setup.py py2exe --bundle 1
+rem --> must be --bundle 3 for pywincomm to work...
+python -OO setup.py py2exe --bundle 3 %1
+rem python -OO setup.py py2exe
 
-copy c:\python26\lib\site-packages\wx-2.8-msw-unicode\wx\gdiplus.dll dist
+copy c:\python27\lib\site-packages\wx-2.8-msw-unicode\wx\gdiplus.dll dist
 
 
 rem  You either need to have your users install the Microsoft Visual Studio 9.0 Runtimes,
@@ -16,10 +18,10 @@ rem  installation on XP and earlier. In addition, these requirements will probab
 rem  with new versions of Python and wxPython. My current setup is Python 2.6.5, 
 rem  and wxPython 2.8.11.0.
 
-copy win_todist\msvcr90.dll dist
-copy win_todist\msvcm90.dll dist
-copy win_todist\msvcp90.dll dist
-copy win_todist\Microsoft.VC90.CRT.manifest dist
+copy C:\WINDOWS\system32\msvcr90.dll dist
+copy C:\WINDOWS\system32\msvcm90.dll dist
+copy C:\WINDOWS\system32\msvcp90.dll dist
+copy C:\python27\Microsoft.VC90.CRT.manifest dist
 
 rem Those 3 DLL's can be found in c:\Windows\WinSxS\x86_Microsoft.VC90.CRT_*\
 rem The Manifest is c:\Windows\WinSxS\Manifests\x86_Microsoft.VC90.CRT_*.manifest 

3) 生成( cmd.exe执行buildwin.bat)

D:\tmp\python\daboframework\test\webtest> .\buildwin.bat

D:\tmp\python\daboframework\test\webtest> dir .\dist

目录: D:\tmp\python\daboframework\test\webtest\dist


Mode                LastWriteTime     Length Name
----                -------------     ------ ----
d----          2013-1-8     13:11            dabo.locale
d----          2013-1-8     13:11            db
d----          2013-1-8     13:11            reports
d----          2013-1-8     13:11            resources
-a---         2012-4-10     23:31      59904 bz2.pyd
-a---         2007-7-18     15:33    1700352 gdiplus.dll
-a---         2008-7-29      9:10       1857 Microsoft.VC90.CRT.manifest
-a---         2008-7-29      3:54     225280 msvcm90.dll
-a---         2008-7-29      8:05     572928 msvcp90.dll
-a---         2008-7-29      8:05     655872 msvcr90.dll
-a---         2012-4-10     23:31     103424 pyexpat.pyd
-a---         2012-4-10     23:31    2303488 python27.dll
-a---        2012-10-27     22:22     364544 pythoncom27.dll
-a---        2012-10-27     22:20     110080 pywintypes27.dll
-a---         2012-4-10     23:31       9728 select.pyd
-a---         2012-4-10     23:31     337920 sqlite3.dll
-a---          2013-1-8     13:12          0 TESTLOG.log
-a---         2012-4-10     23:31     686592 unicodedata.pyd
-a---        2008-10-21      9:42     216064 UxTheme.dll
-a---         2012-4-10     23:31      49664 w9xpopen.exe
-a---          2013-1-8     13:11    6327749 webtest.exe
-a---        2012-10-27     22:21      98816 win32api.pyd
-a---        2012-10-27     22:23     320512 win32com.shell.shell.pyd
-a---        2012-10-27     22:21      33792 win32evtlog.pyd
-a---        2012-10-27     22:21     167936 win32gui.pyd
-a---        2012-10-27     22:20      24064 win32pipe.pyd
-a---        2012-10-27     22:20      35840 win32process.pyd
-a---        2012-10-27     22:20      15872 win32trace.pyd
-a---        2012-10-27     22:26     778752 win32ui.pyd
-a---        2012-10-27     22:26      36864 win32uiole.pyd
-a---        2012-10-27     22:20      25088 win32wnet.pyd
-a---        2012-10-27     22:21     319488 winxpgui.pyd
-a---         2011-7-15     21:39     171008 wx._activex.pyd
-a---         2011-7-15     21:38      73216 wx._animate.pyd
-a---         2011-7-15     21:38     467456 wx._aui.pyd
-a---         2011-7-15     21:38      90624 wx._calendar.pyd
-a---         2011-7-15     21:38     146944 wx._combo.pyd
-a---         2011-7-15     21:38     966144 wx._controls_.pyd
-a---         2011-7-15     21:37     981504 wx._core_.pyd
-a---         2011-7-15     21:38     746496 wx._gdi_.pyd
-a---         2011-7-15     21:39     341504 wx._gizmos.pyd
-a---         2011-7-15     21:38      57856 wx._glcanvas.pyd
-a---         2011-7-15     21:38     395776 wx._grid.pyd
-a---         2011-7-15     21:38     346112 wx._html.pyd
-a---         2011-7-15     21:38      65024 wx._media.pyd
-a---         2011-7-15     21:38     674816 wx._misc_.pyd
-a---         2011-7-15     21:38     562176 wx._richtext.pyd
-a---         2011-7-15     21:39     448000 wx._stc.pyd
-a---         2011-7-15     21:38      74240 wx._webkit.pyd
-a---         2011-7-15     21:38     670720 wx._windows_.pyd
-a---         2011-7-15     21:38     109568 wx._wizard.pyd
-a---         2011-7-15     21:38     144896 wx._xrc.pyd
-a---         2011-7-15     21:33     122368 wxbase28uh_net_vc.dll
-a---         2011-7-15     21:33    1300992 wxbase28uh_vc.dll
-a---         2011-7-15     21:34     121856 wxbase28uh_xml_vc.dll
-a---         2011-7-15     21:34     730112 wxmsw28uh_adv_vc.dll
-a---         2011-7-15     21:34     325120 wxmsw28uh_aui_vc.dll
-a---         2011-7-15     21:34    3165184 wxmsw28uh_core_vc.dll
-a---         2011-7-15     21:34     146432 wxmsw28uh_gizmos_vc.dll
-a---         2011-7-15     21:34      37376 wxmsw28uh_gl_vc.dll
-a---         2011-7-15     21:34     479744 wxmsw28uh_html_vc.dll
-a---         2011-7-15     21:34     102912 wxmsw28uh_media_vc.dll
-a---         2011-7-15     21:34     774656 wxmsw28uh_richtext_vc.dll
-a---         2011-7-15     21:35     532992 wxmsw28uh_stc_vc.dll
-a---         2011-7-15     21:34     504320 wxmsw28uh_xrc_vc.dll
-a---         2012-4-10     23:31      74240 _ctypes.pyd
-a---         2012-4-10     23:31     285184 _hashlib.pyd
-a---         2012-4-10     23:31      40960 _socket.pyd
-a---         2012-4-10     23:31      41984 _sqlite3.pyd
-a---         2012-4-10     23:31     721920 _ssl.pyd
-a---        2012-10-27     22:21       8192 _win32sysloader.pyd
-a---        2012-10-27     22:21      16384 _winxptheme.pyd

D:\tmp\python\daboframework\test\webtest>

双击webtest.exe 出现GUI界面。


你可能感兴趣的:(GUI,exe,howto,dabo)