Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Loading associated files

1 view
Skip to first unread message

flare...@googlemail.com

unread,
Apr 24, 2008, 11:14:31 AM4/24/08
to
I am trying to make a a simple databasing GUI interface and and have
created a module to deal with parsing the data from a file and a GUI
based program that displays this data using PyQt4, i know how to
register files in the system registry using python and also using Inno
Setup which i use to package my applications, but i cant work out how
if a file is doubled clicked on to send the path of that file to
python.

I have looked into passing command line arguments to python and can
send a specific pathname to python but ideally what i need is a
generic command that i can write to the registry that passes the
pathname of whichever file was doubled clicked!?!

am i asking too much/does it exist/is there an easier way to do this!!

CC

Mike Driscoll

unread,
Apr 24, 2008, 1:41:05 PM4/24/08
to

I did this by writing the path to me script or exe and added %1 to the
end, which basically means that my program can (or requires) a
parameter passed to it. Here's an example:

"C:\Program Files\PyMail\wxsendmail.exe" %1

That should work. Tested on Windows XP SP2 with Python 2.4/2.5.

Mike

flare...@googlemail.com

unread,
Apr 26, 2008, 8:26:58 AM4/26/08
to
I can't get this to work (I am on XP SP2 by the way and using Python
2.5),

I wrote a very simple script to test the idea:

import sys

for arg in sys.argv:
print arg

raw_input("Done") #Merely to slow the program down so i can see output

and then setup a file extension .xyz, placed it in the registry, can
get a .xyz file to work as a python script so the registry setup is
fine, but when i try and put the parameter to the above program and a
%1 (or even without) it gets the following error message from windows:

C:\...\hmm.xyz is not a valid Win32 application.

any suggestions??

Lie

unread,
Apr 27, 2008, 8:38:43 AM4/27/08
to
On Apr 24, 10:14 pm, flarefi...@googlemail.com wrote:
> I am trying to make a a simple databasing GUI interface and and have
> created a module to deal with parsing the data from a file and a GUI
> based program that displays this data using PyQt4, i know how to
> register files in the system registry using python and also using Inno
> Setup which i use to package my applications, but i cant work out how
> if a file is doubled clicked on to send the path of that file to
> python.

Do you mean: when a file with "your extension" is double clicked on,
then Windows should pass the path of that file to "your application"
that is written in Python?

(snip)

Windows seems to be trying to execute your file.xyz as an application,
this means it hasn't associated your extension (.xyz) with your
application, instead .xyz is associated as an executable.

To associate your extension with your application, see:
http://msdn2.microsoft.com/en-us/library/bb776883.aspx
It's a bit advanced

NOT TESTED:
# Create or edit Registry Key: 'HKEY_CLASSES_ROOT\.xyz'
# Change the value for the key 'HKEY_CLASSES_ROOT\.xyz:' into 'MyApp'
# Create or edit Registry Key: 'HKEY_CLASSES_ROOT\MyApp\Shell\Open
\Command'
# Change Registry Key value for 'HKEY_CLASSES_ROOT\MyApp\Shell\Open
\Command' into: '"C:\pathtomyapp\myapp.py" "%1"'

Check an existing registry key, how they do it.

flare...@googlemail.com

unread,
Apr 27, 2008, 9:21:48 AM4/27/08
to
Yep, thats pretty much exactly what i had done, those exact settings,
and it still doesnt work. As i said i looked at the other keys to
check i had done it right and a i said the settings are fine because i
can send the file to python.exe and it loads like a python file fine,
but it doesn't like passing it to my program. Have i done something
wrong with my program that simply prints the arguments??

Lie

unread,
Apr 27, 2008, 2:23:44 PM4/27/08
to

I think either I have misunderstood the situation, you misunderstood
your own situation, or you have expressed your situation incorrectly:
"it loads like a python file fine". What loads like a python file
fine? The python source or the data.xyz?

What did you put in data.xyz? Data to be fed to your python program or
python source code?

Aren't we trying to load the data.xyz to your python program? Or are
we trying to load data.xyz to python interpreter?


Anyway, try adding quotes around the "%1", to ensure that path that
contains spaces doesn't confuse the program
HKEY_CLASSES_ROOT\MyApp\Shell\Open\Command => "C:\pathtomyapp
\myapp.py" "%1"

flare...@googlemail.com

unread,
Apr 27, 2008, 6:13:06 PM4/27/08
to
No you didnt misunderstand the situation, i think i have confused
matters though!! When Ive got it working my program will read the data
within the file. But obviously for it to do that it needs to know
where the file is, hence the whole discussion. However to test things
were working, just with regards the setting up of the registry, and
since the contents of the file are essentially irrelevant for the
test, i made the test file a valid python file so that i could test
the registry setup by sending it to python.exe. It doesnt need to be
and wont be a python file, ultimately it will contain some cPickle
data which the program reads from the file. But as i said i need it to
know the path of the file it needs to unpickle.

And there are already "" around my %1 sign. It currently reads "C:\test
\test.py" "%1", where test.py is the short program that simply reads
the sys.argv that i posted further up.

Message has been deleted

Gabriel Genellina

unread,
Apr 28, 2008, 2:09:12 AM4/28/08
to pytho...@python.org
En Sun, 27 Apr 2008 19:13:06 -0300, <flare...@googlemail.com> escribió:

> No you didnt misunderstand the situation, i think i have confused
> matters though!! When Ive got it working my program will read the data
> within the file. But obviously for it to do that it needs to know
> where the file is, hence the whole discussion. However to test things

After reading the thread I'm confused as well.
Try using an installer (like InnoSetup) to install your application. It can handle the .xyz registry stuff for you, among other things.


--
Gabriel Genellina

0 new messages