wxPRE initial test

Hi

win98, Py234, wxPy2515

I take a look at your project. If I undestand correctly, wxPRE
(wx Python Running Environment ???) is a runtime machine to run
Python scripts using wx without having Python and/or wxPython on
the user's platform. The goal is an easy deployment of wxPy
applications.

I only downloaded the script file and start testing.

1) Running wxPRE.py from the DOS prompt works fine.

python wxPRE.py application.py

2) May I suggest the .pth files may contains more than
one lines? See my version.

3) Thinks became more complicated when I created an
wxPRE.exe. wxPRE.exe -because it is frozen- does not
recognize its own path. Therefore it can not find the
.pth files. This is the main reason, why I started to
code my own test script. See my version.

4) Please add a coding info in the Pyhton script.
All users are not american.

o My test version (of course, the project is yours)
See code below. This basic version assumes only one
multiline .pth in the wxPRE directory.

o Creation of wxrun.exe
With py2exe

o Test of wxrun.exe
- In the wxrun.exe dir, I have a single .pth file
- Copy ..\site-packages\wx\*.* to c:\wx. I removed
all subdirs except \lib.
- c:\ is in my .pth file
- I renamed c:\python23 to c:\python23xxx
- Start playing with wxrun.exe from different dirs
having small.py in different test dirs.
- It works fine. (I have some problems with applications
searching for some files in their own homedir).

o small.py
A small application displaying the sys.path

o Open questions / proposals / comments

- It seems such a runtime machine is feasible.
- Should the runtime machine contains the wx part
only or also python?
- Vesioning? A runtime application for every wxPython/Python
couple version or a machine that tests Py/wxPy version.
- Ability to include/add .pth files and/or paths at the prompt.
- An application should be able to be run from the run time
machine and as a "normal way" without modifications.
- What should the distribution contain, dll, pyd, ...
  Q. to Robin Dunn.

o My test scripts are below

Jean-Michel Fauth, Switzerland

#-*- coding: iso-8859-1 -*-

···

#-------------------------------------------------------------------
# wxrun.py
# win98, Py234, wxPy2515
# Jean-Michel Fauth, Switzerland
# 2 June 2004
#
# Based on the work of David Fraser and Stephen Emslie
# http://lists.wxwidgets.org/cgi-bin/ezmlm-cgi?11:mss:29180:200406:ebcedgebogcgmncmllim
#
#-------------------------------------------------------------------

import sys
import os
import os.path

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

def showsyspath(s):
    r = sys.path
    print '--' + s + '-------------------------'
    print len(r), 'pathes'
    i = 1
    for e in r:
        print i, ':', e
        i += 1
    print '-------------------------------'

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

if __name__ == '__main__':

    msg = 'usage: [path]wxrun[.exe] [path]the-wx-app.py'

    if len(sys.argv) > 1:

        #~ showsyspath('at start'

        #this is a .py script
        scripttorun = os.path.abspath(sys.argv[1])

        #as this file is an exe, add its path to sys.path
        path = os.path.abspath(sys.argv[0])
        homedir, homescript = os.path.split(path)
        #~ print homedir
        #~ print homescript
        if homedir not in sys.path:
            sys.path.append(homedir)

        #check for the existence of a pth file
        #for simplicity, I assume only one .pth file in the home dir,
        #the wxrun.exe dir.
        #however this .pth file may contain several path entries
        hit = False
        r = os.listdir(homedir)
        for e in r:
            if os.path.splitext(e)[1] == '.pth':
                pthfilename = e
                hit = True

        #.pth file found
        if hit:
            #read file
            pthfilename = os.path.join(homedir, pthfilename)
            #~ print pthfilename
            f = open(pthfilename, 'rU')
            alllines = f.readlines()
            f.close()
            #add path to sys.path
            for e in alllines:
                sys.path.append(e.strip())
        else:
            print 'no .pth file found'

        #~ showsyspath('at start'

        #run the wxapp, defined as script
        try:
            execfile(scripttorun)
        except:
            print 'missing script name (.py file)'
            print
            print msg
            print
            raw_input('Press <enter> to quit')
    else:
        print msg
        print
        raw_input('Press <enter> to quit')

#eof-------------------------------------------------------------------

#-*- coding: iso-8859-1 -*-
#-------------------------------------------------------------------
# small.py
# win98, Py234, wxPy2515
# Frame + panel + différent widhgets
#-------------------------------------------------------------------

import sys
import wx

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

class MyFrame(wx.Frame):

    def __init__(self, parent, id):
        sty = wx.DEFAULT_FRAME_STYLE
        #~ s = __file__
        s = 'small'
        wx.Frame.__init__(self, parent, id, s, (10, 10), (500, 500), style=sty)

        self.statxt = wx.StaticText(self, 1001, 'asdf', wx.DefaultPosition, wx.DefaultSize, wx.ST_NO_AUTORESIZE)
        self.statxt.SetFont(wx.Font(10, wx.DEFAULT, wx.NORMAL, wx.NORMAL, False))
        self.statxt.SetBackgroundColour(wx.WHITE)

        r = sys.path
        r = '\n'.join(r)
        self.statxt.SetLabel(r)

        self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)

    def OnCloseWindow(self, event):
        self.Destroy()

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

class MyApp(wx.App):

    def OnInit(self):
        frame = MyFrame(None, -1)
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

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

def main():
    print 'main is running...'
    app = MyApp(0)
    app.MainLoop()

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

if __name__ == "__main__" :
    main()

#eof-------------------------------------------------------------------

Jean-Michel Fauth wrote:

Hi

win98, Py234, wxPy2515

I take a look at your project. If I undestand correctly, wxPRE
(wx Python Running Environment ???) is a runtime machine to run
Python scripts using wx without having Python and/or wxPython on
the user's platform. The goal is an easy deployment of wxPy
applications.

I only downloaded the script file and start testing.

Thanks, appreciate this!

1) Running wxPRE.py from the DOS prompt works fine.

python wxPRE.py application.py
   
2) May I suggest the .pth files may contains more than
one lines? See my version.

Yes, I had thought of this, and will probably add this in... although they are then not standard Python .pth files

3) Thinks became more complicated when I created an
wxPRE.exe. wxPRE.exe -because it is frozen- does not
recognize its own path. Therefore it can not find the
.pth files. This is the main reason, why I started to
code my own test script. See my version.

Unfortunately we'd just posted a new version that has improved handling of path files etc, a few minutes before you sent your message!
It now looks in the current directory and the directory of the script that you call.
I'm not sure about handling .pth files in the wxPRE directory.
The issue here is, we intend to keep wxPRE as a simple Python + wxPython without anything else
Then when you package your application to run with wxPRE, you will include any extra packages your application needs with the application, so the .pth files belong in the application folder.
This is worth discussing though.

4) Please add a coding info in the Pyhton script.
All users are not american.

Neither am I :slight_smile: but the file is actually 7-bit ASCII which is assumed by Python if no encoding is specified.
Since there are no Unicode string identifiers I don't think it's neccessary to include this but please explain if it is...

o My test version (of course, the project is yours)
See code below. This basic version assumes only one
multiline .pth in the wxPRE directory.

Thanks.

o Creation of wxrun.exe
With py2exe

o Test of wxrun.exe
- In the wxrun.exe dir, I have a single .pth file
- Copy ..\site-packages\wx\*.* to c:\wx. I removed
all subdirs except \lib.
- c:\ is in my .pth file
- I renamed c:\python23 to c:\python23xxx
- Start playing with wxrun.exe from different dirs
having small.py in different test dirs.
- It works fine. (I have some problems with applications
searching for some files in their own homedir).

With version 0.2, all the wx files will be included automatically... so this step should be unneccessary with the version you used you needed to go python setup.py py2exe -p wx -c ... glad that it runs though.

o small.py
A small application displaying the sys.path

o Open questions / proposals / comments

- It seems such a runtime machine is feasible.
- Should the runtime machine contains the wx part
only or also python?

The runtime machine should contain both the Python interpreter and the wxPython libraries

- Vesioning? A runtime application for every wxPython/Python
couple version or a machine that tests Py/wxPy version.

Since wxPython and Python are bundled together I guess you could include the Python and wxPython version numbers.
But wxPRE-0.2-wx2.5.1.5-py2.3 seems unwieldy ... I think as we go on this will become clearer

- Ability to include/add .pth files and/or paths at the prompt.

Probably the best way to do this would be via environment variables ala PYTHONPATH.

- An application should be able to be run from the run time
machine and as a "normal way" without modifications.

Yes, this is important...

- What should the distribution contain, dll, pyd, ...
Q. to Robin Dunn.

We're busy working these things out... if you can test each new version and give feedback that would be great

o My test scripts are below

Thanks Jean-Michel

David