Is there a way to save the variable names in watches? Every time I debug, the list goes empty and I have to put in the same variables.
When you run the Debug script, there is Watches button.
Reading from a documentation about Watches:
While the Evaluate Expression command on the context menu of the Variables pane enables you to see one expression at a time, the Watches pane shows multiple expressions that persist from one debug session to another, until you remove them.
To add expression to persist from one session to another, simply click + sign and type the name of variable. Then, when you debug again, you will see it again being evaluated until you remove it (using - sign).
Related
Somehow my PyCharm's "Find Usages" scope gets changed and now it only searches in "Scratches and Consoles".
It used to be that when I typed ⌘B, PyCharm would go to the definition or usages of the object.
But now I get this popup that says usages are out of scope 'Scratches and Consoles', and I have to press ⌥⌘F7 to get to search in project files.
I tried clicking on the settings wrench and changing the scope but it does not persist.
There are a number of undocumented rules to this that can only be verified by trying it out:
If you have 2 PyCharm windows open (meaning 2 different projects simultaneously open in 2 different windows) you can only have 1 settings dialog (Ctrl + Alt + Shift + F7 or ⌥⌘F7 on Mac) open simultaneously. Meaning if you change the setting in one window while the dialog is open in the other, the same setting is changed in both windows.
If you only have the above mentioned settings dialog open in 1 window, the setting can be selected differently for both windows.
Now to the question,
If you close your current window the last find setting you chose will be saved, and it will persist when you later reopen that window/project and be used for searches. But there is one exception to this, if your last setting before closing the window was a saved costum scope then when you reopen the window the search setting will have reverted to default.
Here comes 1 important subtlety, after reopening the window if you try "Find usages" (Alt + F7 or ⌥⌘F7) the search will indeed use that last setting before you closed the window (you can see it in the search title window). But if you again press (Ctrl + Alt + Shift + F7 or ⌥⌘F7 on Mac) or the cog in the find settings, the setting you'll be shown is most times the default (sometimes not, but this behavior is not clearly consistent).
Meaning, it's not always consistent what setting is first shown in the below dialog after you reopen the IDE.
The problem you are describing should not be an issue. If you close the window the setting should persist. If you try opening the setting again most times you'll be offered with the default (after reopening the window) or your last choice if you changed it after opening the window.
There is, however, no way to change the default (this is probably to protect inexperienced users from configuring an IDE default search setting that would be difficult to revert). Meaning the first time you open the IDE if the setting doesn't revert to default automatically you'll have to set it manually but just that once.
(In these cases invalidating caches is frequently a good choice, if the cache becomes stale you can start having inexplicable results in search.)
When debugging with PyCharm, a variable list has more than 1000 data. When I go to see the value, the system just displays the first 100 data, I need to double click to see the next 100.
Is there any way to see all the data at once, or is there any way to let me see the last 100?
Open Debug window and in Variables panel click + (New Watch...) or press Insert.
Type variable_name[-100:].
That will let you see last 100 elements.
If variable is not a list an error {TypeError}'int' object is not subscriptable will be displayed instead.
Also unlike Evaluate Expression command, variables added to Watches persist from one debug session to another.
I'm debugging a python script, and I want to watch a variable and get notified whenever its value changes.
Is there a way to do this in pudb?
You can't simply ask for notification any time a value changes (that I'm aware of).
However, you can set both watch expressions and conditional breakpoints which should provide the capability that you're looking for.
First, go to the variable list (shift+V), then N to add a new watch. Enter in whatever variable you want to watch.
Now set a breakpoint at the places that your value can change - back to the main window ←, then find the lines and hit B. Then let your program run to that line or until your variable is defined.
Then shift+B to select the breakpoints window. Press enter to edit the breakpoint. Add a conditional expression - since your value should be set by now, you can see the value in your watch list. A simple <variable> != <current value> should do. Or you can enter a specific criteria.
Now ← back to the main window and let your program continue. When your conditional is true at that breakpoint, your program will stop and you will see the value in your watch list.
For an example, see the following screencast:
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.
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