Run Python script with path as argument from total commander - python

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.

Related

python extension for vs code

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.

Run a script in Maya by right clicking UI?

I'm fairly new to python, and I am trying to run the code I wrote when I right click the playback range windows in the timeline of maya (where you type your min or max range) . I managed to find ways to run scripts within the attribute editor / timeline / shelf items, but I cant seem to figure out how to interact with Maya's UI... Even typing a new value in there doesn't update the script editor, so I don't really have a lead on where to go. Any help would be fantastic!
you basically want to add a menu item in the timeslider ?. You can get all maya widget using OpenMayaUI.MQtUtil and here is a full repo which modify timeline control https://github.com/robertjoosten/maya-timeline-marker
Everything Maya does when using the UI logs data in the script editor.
Many items in the log are suppressed though as it would spam the log.
To enable it, activate Echo all commands (can be found in script editor under History), then clear the script editor and perform the action you want logged.
You will find that Maya executes a lot of mel script functions, which you can all find in the maya install directory under [MAYA_INSTALL_DIR]/scripts/startup and [MAYA_INSTALL_DIR]/scripts/others
To find the essential function you will have to search a little through the log.
Once you got a mel function you want to look for, I recommend using a find in files search function like the one in Notepad++, to find the corresponding .mel file in which the global proc is defined.
Also note that UI element names that are logged in script editor may have a different name the next time you start maya. So you will have to add functionality to search for the correct UI element name.
The Maya mel scripts are a good resource to find out all sorts of things about how the UI works, including contextual marking menus and the commands of tool windows.

Python IDLE Unable to Be Opened

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?

Is there a way to invoke python from Windows click?

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

Change Windows File Handler to a Python script to open a file [duplicate]

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!

Categories

Resources