[help]setup.py for py2exe

He Jibo hejibo at gmail.com
Fri Mar 7 14:14:50 PST 2008


Skipped content of type multipart/alternative-------------- next part -----=
---------
# 11/18/2003 - Jeff Grimmett (grimmtooth at softhome.net)
#
# o Updated for wx namespace
# =


import  wx

if wx.Platform =3D=3D '__WXMSW__':
    import  wx.lib.iewin    as  iewin

#----------------------------------------------------------------------

class TestPanel(wx.Panel):
    def __init__(self, parent, log, frame=3DNone):
        wx.Panel.__init__(
            self, parent, -1,
            style=3Dwx.TAB_TRAVERSAL|wx.CLIP_CHILDREN|wx.NO_FULL_REPAINT_ON=
_RESIZE
            )
            =

        self.log =3D log
        self.current =3D "http://wxPython.org/"
        self.frame =3D frame
        =

        if frame:
            self.titleBase =3D frame.GetTitle()

        sizer =3D wx.BoxSizer(wx.VERTICAL)
        btnSizer =3D wx.BoxSizer(wx.HORIZONTAL)

        self.ie =3D iewin.IEHtmlWindow(self, -1, style =3D wx.NO_FULL_REPAI=
NT_ON_RESIZE)


        btn =3D wx.Button(self, -1, "Open", style=3Dwx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.OnOpenButton, btn)
        btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)

        btn =3D wx.Button(self, -1, "Home", style=3Dwx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.OnHomeButton, btn)
        btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)

        btn =3D wx.Button(self, -1, "<--", style=3Dwx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.OnPrevPageButton, btn)
        btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)

        btn =3D wx.Button(self, -1, "-->", style=3Dwx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.OnNextPageButton, btn)
        btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)

        btn =3D wx.Button(self, -1, "Stop", style=3Dwx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.OnStopButton, btn)
        btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)

        btn =3D wx.Button(self, -1, "Search", style=3Dwx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.OnSearchPageButton, btn)
        btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)

        btn =3D wx.Button(self, -1, "Refresh", style=3Dwx.BU_EXACTFIT)
        self.Bind(wx.EVT_BUTTON, self.OnRefreshPageButton, btn)
        btnSizer.Add(btn, 0, wx.EXPAND|wx.ALL, 2)

        txt =3D wx.StaticText(self, -1, "Location:")
        btnSizer.Add(txt, 0, wx.CENTER|wx.ALL, 2)

        self.location =3D wx.ComboBox(
                            self, -1, "", style=3Dwx.CB_DROPDOWN|wx.PROCESS=
_ENTER
                            )
        =

        self.Bind(wx.EVT_COMBOBOX, self.OnLocationSelect, self.location)
        self.location.Bind(wx.EVT_KEY_UP, self.OnLocationKey)
        self.location.Bind(wx.EVT_CHAR, self.IgnoreReturn)
        btnSizer.Add(self.location, 1, wx.EXPAND|wx.ALL, 2)

        sizer.Add(btnSizer, 0, wx.EXPAND)
        sizer.Add(self.ie, 1, wx.EXPAND)

        self.ie.LoadUrl(self.current)
        self.location.Append(self.current)

        self.SetSizer(sizer)
        # Since this is a wxWindow we have to call Layout ourselves
        self.Bind(wx.EVT_SIZE, self.OnSize)

        # Hook up the event handlers for the IE window
        self.Bind(iewin.EVT_BeforeNavigate2, self.OnBeforeNavigate2, self.i=
e)
        self.Bind(iewin.EVT_NewWindow2, self.OnNewWindow2, self.ie)
        self.Bind(iewin.EVT_DocumentComplete, self.OnDocumentComplete, self=
.ie)
        ##self.Bind(iewin.EVT_ProgressChange,  self.OnProgressChange, self.=
ie)
        self.Bind(iewin.EVT_StatusTextChange, self.OnStatusTextChange, self=
.ie)
        self.Bind(iewin.EVT_TitleChange, self.OnTitleChange, self.ie)


    def ShutdownDemo(self):
        # put the frame title back
        if self.frame:
            self.frame.SetTitle(self.titleBase)


    def OnSize(self, evt):
        self.Layout()


    def OnLocationSelect(self, evt):
        url =3D self.location.GetStringSelection()
        self.log.write('OnLocationSelect: %s\n' % url)
        self.ie.Navigate(url)
        =


    def OnLocationKey(self, evt):
        if evt.GetKeyCode() =3D=3D wx.WXK_RETURN:
            URL =3D self.location.GetValue()
            self.location.Append(URL)
            self.ie.Navigate(URL)
        else:
            evt.Skip()


    def IgnoreReturn(self, evt):
        if evt.GetKeyCode() !=3D wx.WXK_RETURN:
            evt.Skip()

    def OnOpenButton(self, event):
        dlg =3D wx.TextEntryDialog(self, "Open Location",
                                "Enter a full URL or local path",
                                self.current, wx.OK|wx.CANCEL)
        dlg.CentreOnParent()

        if dlg.ShowModal() =3D=3D wx.ID_OK:
            self.current =3D dlg.GetValue()
            self.ie.Navigate(self.current)

        dlg.Destroy()

    def OnHomeButton(self, event):
        self.ie.GoHome()    ## ET Phone Home!

    def OnPrevPageButton(self, event):
        self.ie.GoBack()

    def OnNextPageButton(self, event):
        self.ie.GoForward()

    def OnStopButton(self, evt):
        self.ie.Stop()

    def OnSearchPageButton(self, evt):
        self.ie.GoSearch()

    def OnRefreshPageButton(self, evt):
        self.ie.Refresh(iewin.REFRESH_COMPLETELY)


    def logEvt(self, evt):
        pst =3D ""
        for name in evt.paramList:
            pst +=3D " %s:%s " % (name, repr(getattr(evt, name)))
        self.log.write('%s: %s\n' % (evt.eventName, pst))


    def OnBeforeNavigate2(self, evt):
        self.logEvt(evt)

    def OnNewWindow2(self, evt):
        self.logEvt(evt)
        # Veto the new window.  Cancel is defined as an "out" param
        # for this event.  See iewin.py
        evt.Cancel =3D True   =


    def OnProgressChange(self, evt):
        self.logEvt(evt)
        =

    def OnDocumentComplete(self, evt):
        self.logEvt(evt)
        self.current =3D evt.URL
        file=3Dopen("url_log.txt","a")
        file.seek(0,2)
        print >>file,self.current
        file.close()
        self.location.SetValue(self.current)

    def OnTitleChange(self, evt):
        self.logEvt(evt)
        if self.frame:
            self.frame.SetTitle(self.titleBase + ' -- ' + evt.Text)

    def OnStatusTextChange(self, evt):
        self.logEvt(evt)
        if self.frame:
            self.frame.SetStatusText(evt.Text)


#----------------------------------------------------------------------
# for the demo framework...

def runTest(frame, nb, log):
    if wx.Platform =3D=3D '__WXMSW__':
        win =3D TestPanel(nb, log, frame)
        return win
    else:
        from Main import MessagePanel
        win =3D MessagePanel(nb, 'This demo only works on Microsoft Windows=
.',
                           'Sorry', wx.ICON_WARNING)
        return win



overview =3D """\
<html><body>
<h2>wx.lib.iewin.IEHtmlWindow</h2>

The wx.lib.iewin.IEHtmlWindow class is one example of using ActiveX
controls from wxPython using the new wx.activex module.  This allows
you to use an ActiveX control as if it is a wx.Window, you can call
its methods, set/get properties, and receive events from the ActiveX
control in a very intuitive way.

<p> Using this class is simpler than ActiveXWrapper, doesn't rely on
the win32all extensions, and is more "wx\'ish", meaning that it uses
events and etc. as would be expected from any other wx window.

</body></html>
"""



if __name__ =3D=3D '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])


#----------------------------------------------------------------------

-------------- next part --------------
#!/usr/bin/env python
#--------------------------------------------------------------------------=
--
# Name:         run.py
# Purpose:      Simple framework for running individual demos
#
# Author:       Robin Dunn
#
# Created:      6-March-2000
# RCS-ID:       $Id: run.py,v 1.33.2.1 2007/03/08 19:24:13 RD Exp $
# Copyright:    (c) 2000 by Total Control Software
# Licence:      wxWindows license
#--------------------------------------------------------------------------=
--

"""
This program will load and run one of the individual demos in this
directory within its own frame window.  Just specify the module name
on the command line.
"""

import wx
import wx.lib.mixins.inspection
import sys, os

# stuff for debugging
print "wx.version:", wx.version()
print "pid:", os.getpid()
##raw_input("Press Enter...")

assertMode =3D wx.PYAPP_ASSERT_DIALOG
##assertMode =3D wx.PYAPP_ASSERT_EXCEPTION


#--------------------------------------------------------------------------=
--

class Log:
    def WriteText(self, text):
        if text[-1:] =3D=3D '\n':
            text =3D text[:-1]
        wx.LogMessage(text)
    write =3D WriteText


class RunDemoApp(wx.App, wx.lib.mixins.inspection.InspectionMixin):
    def __init__(self, name, module, useShell):
        self.name =3D name
        self.demoModule =3D module
        self.useShell =3D useShell
        wx.App.__init__(self, redirect=3DFalse)


    def OnInit(self):
        wx.Log_SetActiveTarget(wx.LogStderr())

        self.SetAssertMode(assertMode)
        self.Init()  # InspectionMixin

        frame =3D wx.Frame(None, -1, "RunDemo: " + self.name, pos=3D(50,50)=
, size=3D(200,100),
                        style=3Dwx.DEFAULT_FRAME_STYLE, name=3D"run a sampl=
e")
        frame.CreateStatusBar()

        menuBar =3D wx.MenuBar()
        menu =3D wx.Menu()
        item =3D menu.Append(-1, "E&xit\tCtrl-Q", "Exit demo")
        self.Bind(wx.EVT_MENU, self.OnExitApp, item)
        menuBar.Append(menu, "&File")

        ns =3D {}
        ns['wx'] =3D wx
        ns['app'] =3D self
        ns['module'] =3D self.demoModule
        ns['frame'] =3D frame
        =

        frame.SetMenuBar(menuBar)
        frame.Show(True)
        frame.Bind(wx.EVT_CLOSE, self.OnCloseFrame)

        win =3D self.demoModule.runTest(frame, frame, Log())

        # a window will be returned if the demo does not create
        # its own top-level window
        if win:
            # so set the frame to a good size for showing stuff
            frame.SetSize((640, 480))
            win.SetFocus()
            self.window =3D win
            ns['win'] =3D win
            frect =3D frame.GetRect()

        else:
            # It was probably a dialog or something that is already
            # gone, so we're done.
            frame.Destroy()
            return True

        self.SetTopWindow(frame)
        self.frame =3D frame
        #wx.Log_SetActiveTarget(wx.LogStderr())
        #wx.Log_SetTraceMask(wx.TraceMessages)

        if self.useShell:
            # Make a PyShell window, and position it below our test window
            from wx import py
            shell =3D py.shell.ShellFrame(None, locals=3Dns)
            frect.OffsetXY(0, frect.height)
            frect.height =3D 400
            shell.SetRect(frect)
            shell.Show()

            # Hook the close event of the test window so that we close
            # the shell at the same time
            def CloseShell(evt):
                if shell:
                    shell.Close()
                evt.Skip()
            frame.Bind(wx.EVT_CLOSE, CloseShell)
                    =

        return True


    def OnExitApp(self, evt):
        self.frame.Close(True)


    def OnCloseFrame(self, evt):
        if hasattr(self, "window") and hasattr(self.window, "ShutdownDemo"):
            self.window.ShutdownDemo()
        evt.Skip()


#--------------------------------------------------------------------------=
--


def main(argv):
    useShell =3D False
    for x in range(len(sys.argv)):
        if sys.argv[x] in ['--shell', '-shell', '-s']:
            useShell =3D True
            del sys.argv[x]
            break
            =

    if len(argv) < 2:
        print "Please specify a demo module name on the command-line"
        raise SystemExit

    name, ext  =3D os.path.splitext(argv[1])
    module =3D __import__(name)


    app =3D RunDemoApp(name, module, useShell)
    app.MainLoop()



if __name__ =3D=3D "__main__":
    main(sys.argv)


-------------- next part --------------
# -*- coding: cp936 -*-
# otherrrr at gmail.com
# =BD=ABpython=B4=F2=B0=FC=B3=C9exe
from distutils.core import setup

import py2exe

import sys

#=D4=DA=C3=FC=C1=EE=D0=D0=CF=C2=D6=B4=D0=D0=A3=BApython setup.py

if len(sys.argv) =3D=3D 1:
    sys.argv.append("py2exe")
    =

setup(       =

        windows =3D [
            {
                "script":"RQScale.py",'icon_resources':[(1,'RQScale.ico')]
                                }
                   ],
        options =3D {'py2exe': {'optimize': 2,'compressed':1,"bundle_files"=
: 1,"dll_excludes": ["w9xpopen.exe"]}},
        zipfile=3DNone,
    )

#setup(name=3D'program',
#      data_files=3D[('', ['program.bmp', 'program.jpg'])],
#      windows=3D[{'script':'program.py',
#                'icon_resources':[(1,'program.ico')]
#                }]
#      )
#
#=A1=BE =D4=DA hrpenf (rakoboa) =B5=C4=B4=F3=D7=F7=D6=D0=CC=E1=B5=BD: =A1=
=BF
#: =B5=A5=B8=F6=CE=C4=BC=FE=D5=E2=C3=B4=D0=B4=A3=ACsetup(windows=3D["bomber=
.py"])
#: =BF=C9=CA=C7=D3=D0=B6=E0=B8=F6=CE=C4=BC=FE=B2=A2=C7=D2=D3=D0jpg=A3=ACbmp=
=B5=C4=D4=F5=C3=B4=B0=EC=A3=BF


More information about the wxpython-users mailing list