"Simplicity is the ultimate sophistication."
|--Leonardo da Vinci|
I fell in love with Python for its elegance. I love how there are no semicolons, how you can make a block through a simple indentation, how you can make multiline strings without having to concatenate them, and how you can make lambdas in a single line. I love how readable it all is, and how the documentation (docstrings) is built right into the language.
I think we all appreciate beauty. Think about it; you have a favorite font, a favorite color-scheme, and the list can go on. In essence, the code you write needs to be beautiful in your perspective, not just the syntax, but how it looks—the colors, the font, the highlighting—everything must be just right.
In this chapter, we are going to work toward making PyCharm beautiful. We'll progress from changing the overall appearance to some of the predefined appearances available to us on PyCharm. After that, we'll get into fonts and how the highlighting/coloring works in PyCharm. With the most difficult part of this chapter under our belt, we'll dive into exporting and importing styles and themes.
If you appreciate how your code looks and how you can make it as beautiful as possible, then this chapter will equip you with all the things necessary to make PyCharm as vibrant as you want it to be. I've tried to make this chapter light so that you can experiment yourself with it, and most things are pretty self-explanatory.
The keyboard shortcuts used in this chapter are the defaults for when you install PyCharm on Windows. PyCharm supports a wide range of shortcut schemes, and hence, it is impossible to include them all here (also, you might have made your own customizations). What I've tried to do is put in the name of the action being done so that you can take a look in your Keymap (by navigating to File | Settings…).
The first time you install PyCharm, the theme will default to IntelliJ. But, if you prefer something darker, I suggest you use Darcula. I personally prefer a darker IDE, so I go with a custom version of Darcula that's tailored to my tastes.
With the color scheme set to Default, you will need to save your new color scheme with a different name before you can go about making any changes to the scheme. You can just click on Save As... and then simply enter the name of your scheme in the popup. After doing so, you are free to make any changes you wish.
The Show only monospaced fonts option is enabled by default, but you can change it to include other fonts such as Arial or Times New Roman as well. Also the choice of a secondary font is important when you're trying to import your settings to another computer that does not have your desired font.
A typical example would be Consolas; it's only available on Windows machines, so when you try to import your font settings to Ubuntu or Mac, you likely get the default monospaced font. I usually set my default font to Consolas and my secondary font to Ubuntu Mono since it's free and can be made available on all the machines.
Now that the font business is taken care of, let's get down to a couple of other features. We will revisit this part of PyCharm pretty soon.
The default PyCharm layout is quite minimal. With reference to the preceding screenshot, you get an editor in , and the list of your directories and files in . Actually,  is a sidebar, so if you click on , you get a totally different sidebar popping up.
You can show/hide it using Alt + number indicated by the underline. So, in this case, if you were to press Alt + 7, the panel indicated by  (Structure) would show up. Once you're familiar with the layout, you can hide all the panel buttons by clicking on .
So far, we can hide panels; now let's get rid of all the other distractions as well. The area highlighted with the arrow in the preceding screenshot is called the navigation bar; if you'd like to get rid of it, you can deselect the Navigation Bar option in the View option menu.
Note that with the Navigation Bar option, you also lose the Run, Debug, Coverage, and Search Anywhere buttons; but don't worry, there are plenty of shortcuts available so that you can do everything you want from your keyboard.
As for the Debug and other buttons that we got rid of, you can always get them through Find Action, Ctrl + Shift + A.
I never use this mode because with my start menu minimized, with no navigation bar, and a collapsible Project sidebar, I have plenty of screen space to get the job done.
Another tool that I really appreciate is Switcher, which can be invoked with Ctrl + Tab. It appears as a floating window:
You can quickly navigate through your open files on the right-hand side of the window, and on the left-hand side you have some commonly used tools. You can navigate by pressing Tab again, and this will proceed through the list. You can also use the arrow keys. However, note that you will need to keep the Ctrl key pressed down as long as you're using Switcher.
You can quickly get to them by pressing the key underlined. In this case, you can quickly get to Terminal through first pressing Ctrl + Tab to bring up Switcher; if, while holding down the Ctrl key, you press 4, (in the preceding screenshot, Terminal is 4, but you might get a different number), you can open up Terminal.
You can close anything, that is, a tool panel or an editor tab using Ctrl + F4.
We looked at themes briefly in the The basics section, and frankly there isn't much else left to themes in PyCharm. Right now you have your choices limited to a couple of themes if you're using IntelliJ IDEA Platform 130.* and above. In older versions of IntelliJ, there used to be a lot more.
Each language has its own color scheme under Editor; if you can't find it, just look it up in the search bar, and underneath Editor, you should be able to find Python. Most of the options here are the same for all the IDEs built using the IntelliJ Platform, so this is nothing native to PyCharm.
Underneath Colors & Fonts, you should be able to see a whole bunch of choices. We have already changed the font, and the other options will become more relevant as we progress through this chapter, but first let's make a couple of changes to the scheme for Python.
The list in  is merely the different elements in a file that can be styled. The best way to go about changing the style is not using ; however, it's clicking on the elements in , which directly takes you to the element in question. Note that you cannot change the text in .
Whenever we change any of the default schemes, we need to save it as a new scheme all together, which we can later make changes to. PyCharm will prompt you for a new theme name.
So, in this example, if you want to know the category for a decorator in Python, all you have to do is click on the decorator in , and that will lead you to the corresponding name of the said element. An interesting option is , which we will touch upon soon.
As you can see, when we clicked on
decorator, it auto-scrolled straight to Decorator in the list. However, it's not always obvious what something is called, so clicking on it again will help us identify what element it is:
PyCharm's style system can work on hierarchies; what this simply means is that a lot of the common elements in different languages are handled by central rules. This is useful since in this way, you have a common set of colors for all your languages.
For example, documentation comments are common in most languages, so PyCharm allows you to control how documentation looks in all the languages, so the colors stay consistent. Let's take a look at this:
Here it says that it does inherit from another set of styles; in this case, it is Language Defaults, which has been abbreviated by PyCharm, so let's head over there, and we can see that, yes indeed, there is a Doc comment element and its styled the same way docstring is.
Note that the editor isn't the only region that you can style; you can style just about anything. For example, if you wanted to change the colors for the in-built terminal, you'd have to change the console colors; both the terminal and console share a common style setting.
A common problem that I faced when I initially installed PyCharm was that, even though my terminal was actually styled, I did not get the styling when I opened up the Terminal in PyCharm, and this is because I did not set up my console colors correctly:
As you can see in the preceding screenshot, my ANSI colors have not been set right, and hence, all my output just comes out in blue and red; thus, I had to manually change the colors. Note that some elements can also inherit their color from within the same category.
So my terminal used to look similar to this:
However, after the change, I was able to make it look more like my real terminal, although you cannot replicate it exactly.
You can of course go ahead and choose the appropriate colors, but it's best to let the color picker (shown on the right-hand side in the following screenshot) do it for you:
If you hover over your chosen color for just a second using the color picker, PyCharm will show the color you've chosen in the color circle.
Here are a few pointers on where things are located:
General is for the different parts of the IDE that you see. For example, when you try to find something in your editor, and your editor highlights the search item in question, you determine that via Text search result in this tab. This is really handy when you want to change things such as the color of your line numbers, for example.
CSS, Python, HTML, CoffeeScript, and so on are all language-specific element stylings.
Language Defaults provides the styling for generic language elements, such as doc comments, variables, keywords, and so on.
Console Colors is for styling the terminal and console (when you run something, it opens up the Console window).
Console Font is the font used in the terminal and console.
Debugger is for debugger-specific styling (I would not change this if I were you; the defaults are pretty intuitive).
The best way to import a theme is to simply import it as a setting file; these are typically
.jar files. Remember, we mentioned that PyCharm is a derivative of the IntelliJ Platform? Well, you can use all the themes that are available to the Platform in PyCharm as well. One of the first places to look for themes is http://ideacolorthemes.org/themes/.
This gives you a good set of themes, and also shows you the languages that a theme will work with. So, we can just quickly download a theme; in this case, we will be downloading Solarized Dark (one of my all-time favorites).
To download and install Solarized Dark, perform the following steps:
Click on Import Settings… to open up a dialog box for importing the JAR file:
We covered a lot in this chapter. From fonts to styles to hierarchies, we saw a lot of what we could do with the styling system in PyCharm. We took a look at a minimalistic layout without compromising on what tools were quickly available to us, using Find Action and Search Everywhere. In the end, we showed how we can import themes and export them as well.