2013/03/20

使用 py2exe 製作 wxPython 執行檔

製作 wxPython 執行檔的方法很多,像 pyinstaller, cx-freeze, shedlin,網路上有人做了個比較表可以參考。本篇主要給了一個 py2exe 的例子。

所有的程式放在 github

環境
  • Windows XP
  • Visual Studio 2008 Express
  • Python 2.7
  • wxPython 2.8
  • py2exe 0.6.8.win32-py2.7
Hello World in wxPython

首先,先準備好要編成執行檔的 wxPython 源碼,存成 main.py

import wx

class MainWindow(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(200,100))
        self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
        self.CreateStatusBar() # A Statusbar in the bottom of the window

        # Setting up the menu.
        filemenu= wx.Menu()

        # wx.ID_ABOUT and wx.ID_EXIT are standard IDs provided by wxWidgets.
        filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")
        filemenu.AppendSeparator()
        filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")

        # Creating the menubar.
        menuBar = wx.MenuBar()
        menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar
        self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
        self.Show(True)

app = wx.App(False)
frame = MainWindow(None, "Sample editor")
app.MainLoop()

py2exe setup.py

複製 Visual studio libraries 到 python DLLs 資料匣
copy C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.dll C:\Python27\DLLs
準備 py2exe 佈署設定程式 setup.py 如下

#!/usr/bin/python

from distutils.core import setup
import py2exe
from glob import glob
import sys

#sys.path.append('ftpserver')

manifest = """
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1"
manifestVersion="1.0">
<assemblyIdentity
    version="0.64.1.0"
    processorArchitecture="x86"
    name="Controls"
    type="win32"
/>
<description>Your Application</description>
<dependency>
    <dependentAssembly>
        <assemblyIdentity
            type="win32"
            name="Microsoft.Windows.Common-Controls"
            version="6.0.0.0"
            processorArchitecture="X86"
            publicKeyToken="6595b64144ccf1df"
            language="*"
        />
    </dependentAssembly>
</dependency>
</assembly>
"""

"""
installs manifest and icon into the .exe
but icon is still needed as we open it
for the window icon (not just the .exe)
changelog and logo are included in dist
      data_files=["yourapplication.ico"]
            "other_resources": [(24,1,manifest)]
    data_files=data_files,
"""
data_files = [("Microsoft.VC90.CRT", glob(r'C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*'))]
includes = []
excludes = ['_gtkagg', '_tkagg', 'bsddb', 'curses', 'email', 'pywin.debugger',
            'pywin.debugger.dbgcon', 'pywin.dialogs', 'tcl',
            'Tkconstants', 'Tkinter']
packages = []
dll_excludes = ['libgdk-win32-2.0-0.dll', 'libgobject-2.0-0.dll', 'tcl84.dll',
                'tk84.dll']

setup(
    windows = [
        {
            "script": "main.py",
        }
    ],
    options = {"py2exe": {"compressed": 2,
                          "optimize": 2,
                          "includes": includes,
                          "excludes": excludes,
                          "packages": packages,
                          "dll_excludes": dll_excludes,
                          "bundle_files": 3,
                          "dist_dir": "dist",
                          "xref": False,
                          "skip_archive": False,
                          "ascii": False,
                          "custom_boot_script": '',
                         }
              },
) 

打開命令提示字元下

cd \path\to\hello
python setup.py py2exe

在資料匣 dist 便可發現執行檔

2013/03/18

近況


記錄一下近況


這陣子結束了 1 年多在 NAS 產業的工作,該公司剛成立我便進去了,離開的原因有很多,除了我認為公司要上市的時間會比我想像的很還久,另外也是 C 社的魅力,以及我希望能做一些開源的專案。

A 公司

在 A 公司的那段時間,我主要的工作是把 Boxee 放在 NAS 上執行。為了達到最佳的使用者經驗,做了不少貢獻,
  1. a window manager which is based on evilwm/xcompmgr
  2. a media player which is based on mplayer
  3. SGX 545 OpenGL and VAAPI porting
  4. a server, written in Python, to broadcast Avahi packet and communicate with Remote Controller and Boxee
  5. a Android App to control Boxee remotely. 
除了 Boxee 外,另一個專案關於串流的部分還沒來得及看到成果便離開。

 C 社

在加入 C 社前思考了很多,最大的動力是想說來到這裡可以有更多的時間從事自己有興趣的專案,也希望在這幾個月內,能夠多寫一些東西或將目前在做的電視串流的專案能夠開源。