Re: [Tutor] how do I find where my program is installed?

2006-09-07 Thread Bill Burns
[Jeff]
> I read the link you sent, and I am not sure what they mean by "You 
> cannot rely on __file__, because __file__ is not there in the py2exed 
> main-script." can't I use _file_ in my application though? This is what 
> I just added to my application and it seems to do the trick... is there 
> an exception that I am not aware of?

[Bill]
Apparently, py2exe does something (when it freezes the script), which
makes __file__ break or at least makes it unreliable. What that
something is, I have know idea. Someone else on the list may know...

[Jeff]
> using your method, what do you do with 'installDir' in py2exe?
> 

[Bill]
The documentation for my program lives in a sub-directory of the program
directory.

Example: C:\Program Files\FilePrinter\documentation

But the 'program directory' could be anywhere the user felt like 
installing it, so...

when a user wants to open the docs, they click on a menu item in the GUI
and this code gets fired:

def on_openDocs_command(self, event):
 """Opens the documention."""
 installDir = os.path.dirname(os.path.abspath(sys.argv[0]))
 docs = r'documentation\FilePrinter.html'
 webbrowser.open(os.path.join(installDir, docs))


and no matter where they installed my program, it's possible for me to
find the file 'FilePrinter.html' and open it.

HTH

Bill


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how do I find where my program is installed?

2006-09-07 Thread Jeff Peery
Thanks Bill, I read the link you sent, and I am not sure what they mean by "You cannot rely on __file__, because __file__ is not there in the py2exed main-script." can't I use _file_ in my application though? This is what I just added to my application and it seems to do the trick... is there an exception that I am not aware of?using your method, what do you do with 'installDir' in py2exe?thanks for the help. [EMAIL PROTECTED] wrote: > way. so I need to tell my program to set the working directory back to the> installation directory... but where is this?>Here's what I do in my py2exe app:installDir = os.path.dirname(os.path.abspath(sys.argv[0]))and take a look at this
 link:http://www.py2exe.org/index.cgi/WhereAmIHTH,Bill 
		Do you Yahoo!? 
Get on board. You're invited to try the new Yahoo! Mail.___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how do I find where my program is installed?

2006-09-07 Thread billburns


> way. so I need to tell my program to set the working directory back to the
> installation directory... but where is this?
>

Here's what I do in my py2exe app:

installDir = os.path.dirname(os.path.abspath(sys.argv[0]))

and take a look at this link:

http://www.py2exe.org/index.cgi/WhereAmI

HTH,

Bill
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how do I find where my program is installed?

2006-09-07 Thread Alan Gauld
> hello, I created an executable using py2exe and innosetup for 
> windows.
> I need to figure out where the user has installed my program
> so that I can direct the program to the installation files that it 
> needs to run.

The location of the installation files - I assume you mean some
kind of config file? - should not be hard coded in that way, much
better to store the files in a flexible location and use an
environment variable or registry setting to point to it.

> when this file type is double clicked my application is launched.
> when this happens my program thinks the working directory
> is the directory where that registered file was located...

Interesting, I didn't know Windows would do that.

> the working directory back to the installation directory...
> but where is this?

If the current working directory is not set to the home location
of your program but rather to the target file then I don't know!
Another good reason for setting an environment variable or
registry entry.

However the sys module contains two functions that might help:
exec_prefix()
and
executable()

Not sure how they play with py2exe however.

HTH,

Alan Gauld
Author of the Learn to Program web site
http://www.freenetpages.co.uk/hp/alan.gauld


___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] how do I find where my program is installed?

2006-09-06 Thread Kent Johnson
Jeff Peery wrote:
> hello, I created an executable using py2exe and innosetup for windows. I 
> need to figure out where the user has installed my program so that I can 
> direct the program to the installation files that it needs to run. I ran 
> into this problem because I have a file type that my program reads and I 
> have registered this type in the windows registry so that when this file 
> type is double clicked my application is launched. when this happens my 
> program thinks the working directory is the directory where that 
> registered file was located... not the installation directory where it 
> should be working in needless to say that lots of things go wrong 
> when my program is launched this way. so I need to tell my program to 
> set the working directory back to the installation directory... but 
> where is this?

Try the __file__ variable in your main module; it should have the path 
to the .py file. os.path.dirname(__file__) will give you the directory. 
Then use os.chdir() to change the working dir.

Kent

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] how do I find where my program is installed?

2006-09-06 Thread Jeff Peery
hello, I created an executable using py2exe and innosetup for windows. I need to figure out where the user has installed my program so that I can direct the program to the installation files that it needs to run. I ran into this problem because I have a file type that my program reads and I have registered this type in the windows registry so that when this file type is double clicked my application is launched. when this happens my program thinks the working directory is the directory where that registered file was located... not the installation directory where it should be working in needless to say that lots of things go wrong when my program is launched this way. so I need to tell my program to set the working directory back to the installation directory... but where is this?thanks!Jeff 
		Stay in the know. Pulse on the new Yahoo.com.  Check it out. 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor