I have a python app that I'd like to call on some images, by something like this:
right clicking on images in windows
menu pops up => shows the python application in the list of items
when clicked, batch runs on the images
Can this be done w/o using Visual Studio?
That "list of items" is called the context menu. That is controlled by "The Registry", which is only accessible by the computer's administrator.
MANDATORY WARNING: THE REGISTRY IS NOT A TOY, AND WILL BREAK YOUR COMPUTER IF YOU DO NOT KNOW WHAT YOU ARE DOING. IF YOU ARE NOT AT LEAST 80% CONFIDENT, DON'T TOUCH IT. I TAKE NO RESPONSIBILITY IF YOU BREAK YOUR COMPUTER.
That's not to say you will though. If you still want to continue, you should definitely back it up:
Open the registry
Press (Windows key) + R to open the run dialog
Type in "regedit.exe" and then enter
Enter you Administrative approval when prompted
Once in the registry, look at the panel on the left and all the way at the top there should be a "folder" (called "key" in the registry) called "HKEY_CLASSES_ROOT". Click on it. (If you can't find it, it might be under "Computer". Just expand it.). You should now see a lot of keys.
Backup the registry (optional but recommended)
Click on "File" (top) => "Export".
On the bottom, choose "Selected branch". If you want though, you could export the whole registry by selecting "All" just to be safe (it's a HUGE file though, and probably not necessary)
Choose a file to save it to and click "Save". Wait for the loading to finish.
Decide which file type you want. You said: image. That could be: ".jpg", ".png", ".bmp", etc. Just repeat the following steps for all desired file types.
Find the "file type association"
Under your selected key, find the key with the file extension you want (eg. ".jpg"). Click on it
There will be a couple of "values" on the side. Check the one called "(Default)". This has the name of the file. (eg: "jpegfile")
Navigate to the file. Still in the same key as the extension (".jpg"), locate the key with the name from step 5. Open it.
Make a new command.
Right-Click the "shell" key, select "New" => "key"
Name this new key with a logical, one word name (eg "process").
This new key has a "(Default") value. Change it's value (not the name) to what you want to appear on the right click menu.
Under your new key, make a new key called "command".
Set this key's default value to the full path of your Python installation, a space, then the script path, including any arguments. You can pass "%L%" as an argument to have the registry replace it with the path to the right-clicked file. (eg. "path/to/python.exe path/to/script.py %L%"). Just make sure your Python script can take arguments.
Done!
Feel free to comment with questions
Related
I have a problem with python autocomplete in visual studio code. The only way I can trigger the autocomplete function is with the Tab or Enter key. Brackets and dot does not have any effect (or better it just hides the suggestion box and puts the bracket in place on the unfinished word e.g. -> typing pr in the editor would display the suggestion box with print as the first choice, if i then press bracket i end up with pr() instead of print())
I presume there should be some settings so autocomplete would act "normally" but I can't find it.
This is set by the shortcut key. Open the Default Keyboard Shortcuts (File > Preferences > Keyboard Shortcuts) and search for "acceptSelectedSuggestion". You will see that there are only two settings by default, the Tab and Enter keys.
If you want to add other buttons to trigger typing intellisense, right-click on one of the settings and select Add Keybinding,
then press the button you want to set, and press Enter to save.
I think you don't need to use the python autocomplete extension. You can just use the Python extension.
Tab or enter is required to actually make a selection. Otherwise, you could have custom function printStuff, and typing pr( would not necessarily pick the right one.
From what I can tell, PyCharm works the exact same way, so unclear what "acts normal" means in this context.
When I try to select all of the text in a file, I receive a notification that says:
(Ctrl + A) was pressed. Waiting for second key of chord...
Here is a screenshot of my "select all" keyboard shortcuts. How can I use Ctrl + A to select all text instead of getting a chord notification?
You have another key binding that begins with Ctrl+A, something like this:
A sequence of multiple keystrokes pressed one after another (rather than simultaneously) is called a "chord".
You might have accidentally created it, or might have recently installed an extension that adds the problematic binding. To find it, do like I have done in the screenshot and type "ctrl a" into the Keyboard Shortcuts search box (that tab can be opened by typing Ctrl+K then Ctrl+S). Then look for a binding that begins with Ctrl+A but has something else after it (in my case, another Ctrl+A, but it could be almost anything).
When you find the offending binding, right-click on it, and either remove or change it. Then Ctrl+A alone will resume working.
Note: This question and its answer pertain to Visual Studio Code, which is different from Visual Studio. See this question for information about the equivalent situation in Visual Studio.
You might be in a situation where you want to keep the chorded keybindings that are causing you the problem with your original keybinding. A potential workaround to this issue is turning your original keybinding into a chord as well. For example, you could having a 'stop' character that exits your chord. For example, "Ctrl+A ." where "." is your stop character.
So if for some reason you really liked "Ctrl+A" as the beginning keystroke for a bunch of chorded keybindings, then rebinding all current "Ctrl+A" keybindings to "Ctrl+A ." would free up that keystroke for any manner of other, chorded keybindings.
I was in a situation where Ctrl+x did not work and was considered the start of a keychord. Every time I pressed Ctrl+x, instead of cutting the selected text, the editor told me that it was waiting for the second key of the chord.
Looking at "Preferences->Keyboard shortcuts" did not help. Searching for Ctrl+X in the list showed that only the "Cut" command was mapped to this key.
I had to edit the file $HOME/.config/Code/User/keybindings.json (under Linux) and search for CTRL+x. It turned out another command was mapped to a keychord starting with this key combination. I am not sure know how I got in this situation.
In my case, reloading VS Code with extensions disabled fixed it, so I knew it was an extension. Took a while, but eventually figured out it was https://github.com/phsantos/nano-id-generator.
A little context
I'm using Windows. I installed Python and wrote a script for it. Before long, it became necessary to install packages. To do so, I needed to know what was the location of my Python folder, so that I could enter this location in the command prompt as in this video at 7:55. My idea for how to achieve this was to go into the "This PC" app (as in, enter the words "This PC" into the search bar which is next to the start symbol in the lower left-hand (LLH) corner of the screen) and search within that app the phrase "Python" (as in, enter "Python" into the search bar which is in the URH corner of the window which is opened when the symbol "This PC" is clicked). Then, I just made a new folder titled 'Python 3.7' on my desktop and dragged all of the search results into that new folder.
Slightly more detailed explanation of the problem
Now, everything can be found in that folder, and I find it to be reasonably organized, but most things no longer function if I attempt to click on them. For example, clicking on the 'IDLE (Python 3.7 32-bit)' shortcut has no effect whatsoever. The shortcut which I have pinned to my taskbar also inexplicably no longer does anything when it is clicked. Going to the .py script I wrote, right clicking, and selecting "Open" has no effect; on that same menu, selecting "edit with IDLE" opens a window asking "How do you want to open this .py file?" I select the option "Python" and click OK, and nothing happens.
What I expect to be the most relevant information
The thing titled 'IDLE (Python 3.7 32-bit)' which I click on is categorized as a Shortcut. When I right-click and go into the properties, it says the Target Location is
Python37-32
which is a folder. It further says Target:
\Programs\Python\Python37-32\Lib\idlelib\idle.pyw"
and Start in:
"C:\Users\Myname\Desktop\Python 3.7\python\Python37-32\"
whereas the current location of the Shortcut is
C:\Users\Myname\Desktop\Python 3.7
Essentially, I have rearranged folders without much thought, and inadvertently messed something up?
Does someone happen to know, at least, what this issue is - or, perhaps, to be so gracious as to refer me to a help page on the subject - so that I may research the issue?
I want to do the following:
Save numeric data in a CSV-like formatting, with a ".foo" extension;
Associate the ".foo" file extension with some python script, which in turns opens the .foo file, reads its content, and plots something with a plotting library (matplotlib most probably).
The use-case would be: double-click the file, and its respective plot pops up right away.
I wonder how I should write a python script in order to do that.
Besides, the windows "open with" dialog only allows me to choose executables (*.exe). If I choose "fooOpener.py", it doesn't work.
This isn't really a programming question, but what you need to do is to figure out how to get the Python executable into the registry key that opens your data file.
For example, I created a little Python script called opener.py that looks like this:
import sys
print(sys.argv)
input()
Then I created a testfile.foo and used the "change" button in that file's property dialog to choose opener.py. (You can do this if you click Browse and change the Open With dialog's file filter to "All Files".)
Of course this didn't work (as you noticed). So I opened regedit and searched for opener.py and found it at the following registry key:
HKEY_CURRENT_USER\Software\Classes\Applications\opener.py\shell\open\command
The default value of this key was "C:\opener.py" %1. I changed it to python "C:\opener.py" %1. It worked!
Long story short, to do this properly you need to custom-edit the registry. Actually setting up the file association is more complex than just editing that one key (you have to also indicate that .foo is associated with opener.py).
An alternative approach would be to turn your Python script into a standalone executable using one of the several tools available for that purpose, or write a small executable in C that launches the script.
press the windows key
type cmd
right click the result and choose "run as administrator"
assoc .foo=foofile
ftype foofile="C:\Users\<user>\AppData\Local\Programs\Python\PYTHON~1\python.exe" "C:\<whatever>\fooOpener.py" "%1" %*
Use pythonw.exe if it's a .pyw file (to prevent a cmd window from spawning).
If you want to use an existing file type, you can find its alias by not assigning anything. For example, assoc .txt returns .txt=txtfile.
instead of editing registry, you can create batch file
opener.cmd
with content
python "C:\<whatever>\fooOpener.py" %1
and associate extension with this file.
It works!
I've got a script that accepts a path as an external argument and I would like to attach it to Total Commander.
So I need a script/plugin for TC that would pass a path of opened directory as an argument and run a Python script which is located for example at C:/Temp
How can I achieve this?
Best Regards,
Marek
Ok, I managed to do it. You don't quite have to pass a path as an argument.
You just need to add a quick button at the top of the TC.
As a Query just place python and location to Python script.
You can either pass any argument if you want (but in this case you don't need this).
As an initial path you set cm_AddPathToCmdline which returns a path to currently opened directory.
And that's it. :)
import os
os.makedirs("TEST")
You can add a new button to the button bar.
Right-click on an existing Icon and copy the icon by choosing "copy" from drop-down menu.
Paste it into the button bar by right-clicking on it, choosing "paste" from the menu.
Right-click on this copied icon and choose "modify" (or similar). This opens a window that allows you the choose a program and a parameter.
Note: My version is set to a different language so the names of the menu items might be a bit different.