开发者

Recognizing a file

I have no idea how this works or if it is even possible but what I want to do is for example create a file type (lets imagine .test (in which a random file name would be random.test)). Now before I continue, its obviously easy to do this using for example:

filename = "random.test"
file = open(filen开发者_C百科ame, 'w')
file.write("some text here")

But now what I would like to know is if it is possible to write the file .test so if I set it to open with a wxPython program (directly (running the "random.test" from the desktop)), it recognizes it and for example opens up a Message Dialog automatically.


How this works varies by operating system, but, AFAIK, the general rule is that if you register your application with the operating system as recognizing that file type, then clicking on one or more files of that type causes the operating system to invoke your program with the names of the files as parameters, so your program will correctly handle the file opening if it has a commandline invocation of the following form:

program_name [options] <file1> [<file2> ... <fileN>]

In terms of identifying what file types your program can accept... on Mac OS X, this is done by listing the file types in the application bundle's "Info.plist" file in a dictionary with key CFBundleDocumentTypes. It is up to the user to perform the association, but the information in "Info.plist" determines which applications are considered candidates for registration. On Windows, you need to edit the registry to associate the program with the file type, you can also edit the registry to add "verbs" (right-click menu items) for your program.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜