Register a python script as default for file type

2019-05-20 16:24发布

I am making an application with python which will need to be associated with a file type. I need a cross platform solution (can be different for different platforms) that includes setting the icon for the file type, having my application open when a file of that type is double-clicked and being able to reference that file when my application is opened.

To clarify
Lets say that I have an application called FooEdit, that edits .foo files. .foo files have the mime type of text/plain. Here is the process that happens when a user first gets FooEdit:

  • A user obtains the executable for my application, whether it be on Linux, Windows, or OS X.
  • A python script runs that:
    1. Sets FooEdit (the executable) as the default application for .foo file extensions.
    2. Sets the icon for .foo files to foofileicon.png (or foofileicon.ico if that works better).
  • The same user double clicks a .foo file.
  • FooEdit opens with the path to the file in it's argv array (I'm using PyQt4)

I have seen this question, but it only refers to Mac OS X and the user must do it manually, I want the solution to work on all three of the major platforms (Linux, Windows, OS X) and I want it to be done automatically by the python script.
I have also heard about inserting values into the windows registry for such a purpose and I am fine with doing that for the windows version of my program. However that still leaves me clueless as to how to do the same on Mac and Linux.
I would like a single solution that works on all platforms, though I accept that it might well not be possible.

0条回答
登录 后发表回答