Register a python script as default for file type

纵然是瞬间 提交于 2019-12-10 11:05:22

问题


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.

来源:https://stackoverflow.com/questions/15603334/register-a-python-script-as-default-for-file-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!