Optimal switching between file editors in PyCharm - python

I'm coming to PyCharm from Eclipse, and something that is annoying me is how I switch between open files in the editor.
In Eclipse, I had a hotkey set up to open the previous editor. A menu would appear with the files in order of most-to-least recently viewed. If I hit the key once quickly, it would switch to the last file viewed. Whatever I had been working on recently would always be readily available.
In PyCharm, the files are listed in the editor in seemingly random order. Control+left (or right) takes you to the next file in the listing, which may be near a file unrelated in any way. I can use the mouse to select a file, but I'm not used to this, and it makes me stop and think about what the file name was, what module it was in, etc.
Natural, quick, efficient, minimum of thought -- this is what I'm looking for in navigating between open files in the PyCharm editor. Does anyone know of a way I can achieve this?
Thanks!

Ctrl-Tab switches in most-recently-used order (like Alt-Tab for the desktop). Ctrl-E will show recent files.
You should look at Help > Default Keymap Reference, under the navigation heading, for more helpful shortcuts.

Related

Set a breakpoint for all search results in PyCharm

I have made a search in PyCharm with classical Ctrl+Shift+F, and I just want to set a breakpoint at every line in result for debugging at once.
Does exists some functionality in the IDE to do this?
There's no such feature, unfortunately. Though you can place breakpoints manually in "Find in Path" preview window for a given search item.
Feel free to create a feature request in PyCharm's bug tracker https://youtrack.jetbrains.com/issues/PY

How to copy text from IDLE?

Is there a way to copy text out of Python IDLE on a Mac? When I highlight text and copy then past into a text editor, I get the same text pasted. It is some of the first text I start with in IDLE. None of the other text will copy out.
From The Things I Hate About IDLE That I Wish Someone Would Fix (from 2011):
1.2) NEW FEATURE: Auto-Copy-On-Highlight
Once we get rid of being able to move the cursor off the last line, that opens a new opportunity to implement an automatic copy-on-highlight feature that many terminal and IRC client programs implement. Since this text is read-only, the only reason a person has for highlighting it is to copy it (they can’t delete it.) As soon as the user highlights text in the shell window, it is copied to the clipboard.
Looks like the best you can do is save as a .py file. Open that in a text editor and continue working in IDLE. With each save, the text editor will refresh with all updates, including errors. At least TextWrangler will.
Sometimes in things like a linux terminal you can't do a normal copy and paste, try holding Command/Control + Shift + C after highlighting things and seeing if that works, since you're on mac i'm not sure if it would be the Command or Control key so try both
EDIT: There is an apple discussion about the exact same thing. They discuss going into the options menu, then into configuration and navigating to the keys section. Then you use a built in key-set, their suggestion is using IDLE Classic Mac.
I cannot tell from your description exactly what you did and what happened. But I can recommend that you upgrade to 3.4.4 or 3.5.1 (or 2.7.11 for 2.7 users). Among other improvements, they all contain a patch to make right-click for context menu work on Mac Aqua. This was issue 24801 on the CPython bug tracker.
If there is still an actual problem on Mac, I would like to know so it can be fixed.

How do I make pyCharm stop hiding (unfold) my Python imports?

Every time I open a Python file PyCharm will hide all imports and shows:
import ...
within the editor.
I have to manually unfold it to see the imports. Where do I find the setting to undo auto-hiding of import statements?
As this question may be useful for people who also are not looking for the term "code folding", I'll make my comment an answer.
As extracted from IntelliJ IDE Web Help, but also worked on PyCharm CE 3.4.1:
Open the IDE Settings (File > Settings, or Ctrl+Alt+S).
Under the "Editor" node, click "General" and then "Code Folding". The "Code Folding" page is displayed.
In the "Collapse by default list", select the check boxes to the left of the code constructs you want to be displayed collapsed. So here you can uncheck "Imports".
Apply changes.
The image below shows what it looks like:
Actually in pycharm 2016.1 it's Editor -> General -> Code Folding

How to turn on line numbers in IDLE?

In the main shell of IDLE, errors always return a line number but the development environment doesn't even have line numbers. Is there anyway to turn on line numbers?
Version 3.8 or newer:
To show line numbers in the current window, go to Options and click Show Line Numbers.
To show them automatically, go to Options > Configure IDLE > General and check the Show line numbers in new windows box.
Version 3.7 or older:
Unfortunately there is not an option to display line numbers in IDLE although there is an enhancement request open for this.
However, there are a couple of ways to work around this:
Under the edit menu there is a go to line option (there is a default shortcut of Alt+G for this).
There is a display at the bottom right which tells you your current line number / position on the line:
There's a set of useful extensions to IDLE called IDLEX that works with MacOS and Windows http://idlex.sourceforge.net/
It includes line numbering and I find it quite handy & free.
Otherwise there are a bunch of other IDEs some of which are free: https://wiki.python.org/moin/IntegratedDevelopmentEnvironments
If you are trying to track down which line caused an error, if you right-click in the Python shell where the line error is displayed it will come up with a "Go to file/line" which takes you directly to the line in question.
As it was mentioned by Davos you can use the IDLEX
It happens that I'm using Linux version and from all extensions I needed only LineNumbers. So I've downloaded IDLEX archive, took LineNumbers.py from it, copied it to Python's lib folder ( in my case its /usr/lib/python3.5/idlelib ) and added following lines to configuration file in my home folder which is
~/.idlerc/config-extensions.cfg:
[LineNumbers]
enable = 1
enable_shell = 0
visible = True
[LineNumbers_cfgBindings]
linenumbers-show =
Line numbers were added to the IDLE editor two days ago and will appear in the upcoming 3.8.0a3 and later 3.7.5. For new windows, they are off by default, but this can be reversed on the Setting dialog, General tab, Editor section. For existing windows, there is a new Show (Hide) Line Numbers entry on the Options menu. There is currently no hotkey. One can select a line or bloc of lines by clicking on a line or clicking and dragging.
Some people may have missed Edit / Go to Line. The right-click context menu Goto File/Line works on grep (Find in Files) output as well as on trackbacks.
As #StahlRat already answered. I would like to add another method for it. There is extension pack for Python Default idle editor Python Extensions Package.
As mentioned above (a quick way to do this) :
pip install IDLEX
Then I create a shortcut on Desktop (Win10) like this:
C:\Python\Python37\pythonw.exe "C:\Python\Python37\Scripts\idlex.pyw"
The paths may be different and need to be changed:
C:\Python\Python37
(Thanks for the great answers above)

Windows Balloon-tooltips in Python

Following the example at http://article.gmane.org/gmane.comp.python.general/541418, I've succeeded in creating a callable class for balloon tooltips, but the greater complexities of that code elude me when it comes to customization. I browsed a bit of how it works through msdn, but being a novice at more windows-esque languagues like c and vb, etc. I was unable to make much sense of it.
So I ask ye snakely academics:
Things I'd like to be able to do with that code aside from the standard icon, title, text:
Perform actions based on clicking the tooltip
Modify the tooltip that pops up over the icon in the system tray after loading it (to reflect changing values)
Multiple lines? (Not sure if this can even be done, really)
More information on other things you could do in a windows 7 environment versus XP (which seems to be what this was written for).
Ideally I'd get some sort of return value or some semblance of an event when the tooltip is clicked so that I could run some code, but currently I'm importing that code as a module and calling at various times, so I'm not sure how to handle clicks outside of the popup code itself...
Information on handling these things with python seems quite scarce. Thanks in advance.
Perform actions based on clicking the tooltip
Whats the problem OnTaskbarNotify? Hock yourself in there.
Modify the tooltip that pops up over the icon in the system tray after loading it (to reflect changing values)
Probably not, I am not sure about the WinAPI here. I haven't seen it in the wild, so...
Multiple lines? (Not sure if this can even be done, really)
With most WinAPI, just insert a \n in the string.
More information on other things you could do in a windows 7 environment versus XP (which seems to be what this was written for).
LOTS... But that is a bit vague... It depends what your needs are. But for kol feturez you need to google on your own...
On Linux and Unix systems I use the notify-send OS already implemented system.
import os
os.system('notify-send "'+title+'" "'+message+'")
Maybe in Windows there is some API32 for this.
Check this https://gist.github.com/wontoncc/1808234

Categories