Quickly switching between run configurations in PyCharm - python

Two actions that I perform on a regular basis are "run my tests" and "run my application". Unfortunately, PyCharm uses the same keystroke (Shift+F10, i.e., "Run") for both, and that keystroke uses my "current" run/debug configuration. I have to do a separate step to change configurations, and that step involves finding and selecting the right option from a longish list -- and it also requires taking the time to think about whether I need to switch configurations.
With as frequently as I run both the tests and the app (I'm still relatively new to Python, so I want to check frequently to make sure I haven't broken anything), this is pretty cumbersome -- especially since my usual pattern is "run the tests, and if they pass, then run the app", so I'm switching configurations all the time.
Is there an easier way to run a given configuration? Ideally I'd like to be able to bind a single keystroke to "select and run my 'main.py' configuration", and another single keystroke to "select and run my 'py.test' configuration" -- but anything that means I'm not constantly hunting through a list of configurations would be helpful.
I've tried recording a macro that switches configurations and then runs, but the macro recorder doesn't actually record the "change configurations" step -- all that ends up in the macro is "run". And there doesn't appear to be a macro editor that would let me manually add that step.
I also know about the pop-up "select configuration and run" list (F9), but that still requires me to read which configuration is selected in the list, decide whether it's the one I want, and cursor up or down in the list before hitting Enter. It's not all that complicated, but it still interrupts my train of thought pretty thoroughly every time I do it. Running -- both the tests and the app -- should be simpler than this.

I know this question is super old, but to anybody with the same problem.. here it is.
I had the same problem, because I had lots and lots of scripts on the same project, and I wanted to run a script individually.
What you need to do is, open up the script (by double-clicking), and then once it is open, right-click on anything, and you will see "run [the script]" with a green play button.
here is the photo

Related

What does it mean to "restart" a program (in my case IDLE)?

This answer on Stack Overflow offers a solution I am trying to implement. In particular, see the sections "Installation Instructions" and "How to Use".
Can anyone tell me the steps required to "restart" IDLE?
New Information:
Just as people have suggested I thought this simply meant closing the program and opening it back up again...but I already tried that.
The other twist to my situation is that I'm working on a virtual machine so I was unable to do the installation of IDLE2HTML.py myself. My work's Help Desk had to do it so I cannot speak for the accuracy of their work. For now I'm assuming they did it correctly, but when I go to the "Options" menu there is no option to "Save as HTML".
My only guess at this point is that I still need to "restart IDLE".
Just wanted to double check if there was something else I could do before going back to my Help Desk department.
IDLE reads the idlelib/config-xyz.def files, including config-extensions.def, just once, when it starts. So any changes to config-extensions.def only takes effect the next time you start IDLE.
If you do not see 'Save as HTML' after starting IDLE, the extension is not installed properly.
It means you need to close the IDLE so that any changes made by the script can affect the IDLE
Simply close the IDLE either via the X, Ctrl+Q or File>Exit, then open the IDLE again.
If you are using idlelib module from a Python program then close your program and run it again.

How to access the Maya main menu and toolbar?

I use Autodesk Maya 2016 + Python.
I had a problem. I need to replace the functions of standard menu items and toolbars. For example, you must add the function to save a recording function. And because different people use different functionality, you have to change everything at once. Someone presses Ctrl+S, others go to the menu File->Save, and some press icon on the toolbar. In all areas it is necessary to replace the functionality. I understand that the problem boils down to in order to access the menus, toolbars and keyboard shortcuts. Next, find the associates item on the estate to know what function is now called. Then replace it with their cause and at the end of the function that invoked earlier in this menu.
how to get Maya main menu (like File and other)?
how to get Maya main toolbar?
how to get Maya hotkeys?
Maya is based on QT. So just need to get the objects, and then have the standard means of QT can do everything.
How to do it?
All three ways of doing this call the runTimeCommand named SaveScene. Override that command and you have hijacked all of the three ways you describe. This is a bit tricky since the command is marked with the flag -default which makes it impossible to change them on the fly. You can hook them where they are first defined. They are defined in the file:
Mayadir/scripts/startup/defaultRunTimeCommands.mel
Copy this file to your user profile maya script directory or studio script directry. These will get precedence of factory script due to resolution order. Do not overwrite the factory file. Then change -command in the lines,
runTimeCommand -default true
-annotation (uiRes("m_defaultRunTimeCommands.kSaveSceneAnnot"))
-category ("File")
-command ("checkForUnknownNodes(); FileMenu_SaveItem")
SaveScene;
to something else. Best would be just to add a hook here.
Obviously, you can also change the button/menuitem and hotkey too. So what you do is run following mel (it's easier to do this in mel since the bulk of the commands are built that way, port to python or c++ if you must):
runTimeCommand
-annotation "Print the word \"Hello\""
-command ("print \"foo\"")
MySave;
nameCommand
-annotation "Print the word \"Hello\""
-command ("print \"foo\"")
MySaveNamed;
buildFileMenu();
menuItem -e -c "MySave" "MayaWindow|mainFileMenu|saveItem";
iconTextButton -e -c "MySave2" openSceneButton;
hotkey -keyShortcut "s" -ctl -name ("MySaveNamed");
Warning: The hotkey will be permanent in prefs, until you change it back or reset prefs.
Please note: There are at least two other ways user could save and you could not have full control of those even if you wanted to.

Disable automatically starting unit tests in PyCharm

With the latest version of PyCharm, every time I make a change, PyCharm automatically runs my unit tests for me. Much of the time, this is very convenient. Sometimes, however, I need to turn this feature off, so that my tests only run when I explicitly invoke them. How can I do that?
There was similar questions asked before: PyCharm - run a corresponding unit test each time a file is saved
Simply, turn off feature below green arrow on the left side.
From https://www.jetbrains.com/pycharm/help/test-runner-tab.html
"AutoTest Toggle auto-test If this button is pressed, the autotest-like runner is turned on. It means that the test in the current run configuration tab will automatically rerun on changing its source code. Otherwise, to rerun such test, you have to click the rerun button"

AppleScript: How to create and communicate with a singleton Terminal.app window

I want to programmatically create one and only one Terminal.app window that's uniquely identified by a literal Terminal.app window title (let's call it 'MyConsole1') and send bash commands to said window for the life of the Terminal.app process.
Can this be done with Terminal.app, and if so, how?
Details
My program probably needs to check if 'MyConsole1' is already open before I go try to create a new one. And of course, start Terminal.app if it's not already running. I also want the commands issued to and over the life of 'MyConsole1' (by my program) to be bash-command-history retrievable by a human user; ie, the user can interact with 'MyConsole1' if desired. I'm not concerned about user-vs-program "conflicts" that might arise for use of the 'MyConsole1'.
I presume I need AppleScript to do this. I will be running the AppleScript as part of a much-larger Python application, possibly via a method like this, in case that matters.
I see how Terminal.app window/tab title(s) can be set like this, but this solution doesn't work for my requirements above. Further, I only want 1 tab in the window, and the title to apply to the entire window, and not just the tab.
I'm not sure if this is what you mean, but you can try this:
tell app "Terminal"
activate
do script ""
end tell

Eric4 Python IDE - autosave and quick script/project start, run

I've got 2 problems with Eric4 IDE.
Can't find an option in preferences to autosave my changed files before running script. It's very annoying that I have to save my file and then run script.
Second problem is running a script. I can't find any button to run a script/project instantly. 'Run Script' button always opens a setting window.
One way to get around this, as it seems there is no built in way is to bind a key to save the file (ctrl+s), then run the script (F2), and finally hit enter (to close the settings window and run the code).
This bothered me a lot too, and I know this is 2 years late but it might help some else who comes here looking for this very solution, like I did. Here are the actual answers, ERIC v4.4:
Press F4 instead of F2.
The first time you have to use F2 to 'Start' the script, so dismiss the settings window. After that you can use F4 'Restart' and it will run with the settings you chose initially.
The Autosave option is well hidden unfortunately:
Settings-->Preferences-->Debugger-->General-->!Scroll down to!-->Start Debugging-->Autosave changed scripts
And you were spot on - these two things do have a huge impact on productivity.

Categories