Reputation: 398
I am working on a project that allows you to create your own key shortcuts. The program needs to import a list of settings from another file, I have called these .pog files. Here is an example of a .pog file:
q||tap``ctrl`l|type`docs.google.com`enter`
a||tap``alt``tab`
z||quit
Here is main.py, as you can see I just import the .pog file to use it in my program
import monitor
with monitor.Monitor.from_file('demo.pog') as monitor:
while monitor.running:
'vibe in the background'
This is a pain to work with as every time I want to use a different set of shortcuts, I have to either rewrite demo.pog, or open main.py and change the directory of the .pog file it opens.
I would like to be able to right click on a .pog file and choose "open with main.py" the same way I would open a file with notepad or idle. Is there a way to set up a python file to be able to open other files like this?
Upvotes: 0
Views: 1160
Reputation: 1447
Your best option would be to turn the python file into an executable using pyinstaller. It will basically let you turn your .py
file into a .exe
on windows or plain binary on macos/linux.
The easiest way to do this is to install it:
pip install pyinstaller
Then run it over your file specifying that you want the output to be a single .exe
file:
pyinstaller --onefile yourfile.py
There will be a folder inside wherever yourfile.py
is called /dist
and inside there will be the .exe
or binary file.
From there there's system-level ways to register binary programs as extension handlers that differ per OS.
With windows you can just right-click a file and select Open With...
:
then scroll down to find Look for another app on this PC
and browse to the new .exe
file you created with Pyinstaller:
To update the file just replace the .exe
file with new builds of your script using the same pyinstaller method from above.
I don't own a mac, but here are the first two guides I found on google:
https://www.macrumors.com/how-to/how-to-manage-file-associations-in-macos/
https://www.macworld.com/article/231567/change-default-app-macos.html
This changes by every different distribution of linux. I would recommend going to a community forum to ask this, because even across similar distributions there are custom implementations to make this "easier"
Upvotes: 1