Live templates file does not exist in pycharm templates folder? - python

I wanted to insert multiple live templates. For example whenever I type prop and press tab, then pycharm would write the full property for python.
I wanted to import the following list:
https://github.com/hoffmann/PyCharm-Python-Templates
But I can not find the templates folder in <your home directory>\.<product name><version number>\config\templates, as said in https://www.jetbrains.com/help/pycharm/2016.1/live-templates.html
Also I am using the community edition 2016.1.4.

I got this to work on Windows when I used the path <your home directory>\.PyCharm2018.3\config\jba_config\templates\user.xml (my version of PyCharm is 2018.3.4)
In case this doesn't work for you, you may find where the file belong by following what I did.
Open File | Settings | Editor | Live Templates in PyCharm, created a new template called MyNewUniqueLiveTemplate
On the command line in the directory <user directory>\.PyCharm2018.3\config "grep"ed for the string MyNewUniqueLiveTemplate.

I've had the same issue and found that there is one simplest way to insert multiple live templates.
Just copy desired template code from *.XML file,
open PyCharm's Live Templates Settings (Ctrl+Alt+S -> Editor / Live Templates),
select Template Group (such as Python or create your own like a 'user'),
and paste in the value. That's all!
It works fine dependless of the operating system, PyCharm version and you shouldn't worry about PyCharm config files location.
You can insert in that way multiply live templates at once.

Related

Adding Flask support to an existing Pycharm project

I'm working on a small project where it would be helpful to display trivial web pages. It's being developed in PyCharm, the pro edition.
This is an existing project, so it wasn't created as a Flask app to begin with.
I've added Flask to my requirements.txt and ensured that its installed. However, I don't get autocompletion of any Jinja templates - essentially, the HTML file I created is treated like dumb HTML.
How do I get PyCharm to recognize that I'm using Flask and to act accordingly?
You have to tell PyCharm which folders contain your templates.
Go to Settings/Project: NAME/Project Structure
Click on the folder containing your templates and click the purple Templates button.
It will probably warn you that no template language is specified. If that is the case
go to Settings/Language & Frameworks/Python Template Languages
In the combobox Template Language: select your template language (jinja?)
Under Template file types select the file type (probably HTML)
When you create a project ( File->New Project ) to choose:
After the creation of the project to select the appropriate file:
Creating a new Flask Project will just set the python template language as Jinja2 and give you a skeleton (a web server which respond 'Hello World' to client).
Therefore, if you have a existing project, press Prefences -> Search Python Template Languages -> and now you can change it to Jinja2

PyCharm3 Live template not working at all

I just switched from Eclipse/PyDev to PyCharm 3 CE. I can't get the live templates working any ways. Followed every documentation I can find online like this:
http://www.jetbrains.com/pycharm/webhelp/live-templates.html
And the builtin python template super(Generates a 'super' call) does not work either.
By "not working", I meant that when editing a python file in PyCharm and typing the abbreviation, the popup snippets list does not include the live templates, even though they are under the Python template group.
Am I missing something?
I am using PyCharm 3.1 Professional (evaluation version) and am having the same issue.
However, using Ctrl+J will bring up templates as will Code -> Insert Live Template. It is also possible to start typing a code snippet and then press Ctrl+J to see a filtered list of templates.
Don't forget to also select the "context"...

PythonWebkit default directory listing

I want to change the default directory listing of the pythonwebkit(the one imported from gi.repository) for an application I am working on. Is there any function/script in webkit that does the job?
EDIT
The code for styling the default directory listing is in the file net/base/dir_header.html and ends up in chrome.pak and chrome_100_percent.pak.
The python module data_pack.py can work with these files.
If you want to filter certain file types from the list, you can probably do that in addRow()
You will have to use os.chdir() to change the current directory for the whole process. AFAIK, WebKit doesn't keep an internal environment for things like the current folder.

writing my first Trac macro

Ok, I've looked all over, and I think I'm doing this right, but I'm not getting any results. Is there anyone out there who's written Trac macros that can guide me through the first steps? Here's what I've written:
from trac.wiki.macros import WikiMacroBase
from genshi.builder import tag
class MyMacro(WikiMacroBase):
"""Proof of concept"""
revision = "$Rev$"
url = "$URL$"
def expand_macro(self, formatter, name, args):
return tag.b("Hello world.")
I've saved it as a .py file and put it in my Trac project's /plugins directory. Do I need to restart apache? Am I correct in expecting [[MyMacro]] to output a Hello world. on the page?
When creating macros using that format, Trac expects your class to be named "<name>Macro". For example, if you wanted a macro named JustASample, you would name the class JustASampleMacro. Since you named your class MyMacro, Trac thinks that you want your macro to be named My. Try using [[My]] on a wiki page and see if you get the output you're expecting.
After you copy the file into the plugins directory, you will indeed want to restart the web server. Before doing so, delete any .pyc files that were created for your plugin. Also, ensure that the file is readable by the account under which the web server runs.

Google App Engine, ReportLab and True Type Fonts

All!
I'm writing an application that would run on Google App Engine. I'm using ReportLab for PDF files generation. However, the application needs to be able to generate PDF with cyrilic text. So I need to load some True Type Font. I should write something like this
pdfmetrics.registerFont(TTFont('Verdana', 'verdana.ttf'))
I tried to copy 'verdana.ttf' file to /reportlab/fonts but registerFont failed again. However in desktop environment it works fine.
How can I load True Type Font from application running on GAE?
Thanks in advance
if you use docker container to do this job, or any linux environment just use
pdfmetrics.registerFont(TTFont('Verdana', 'Vera.ttf'))
or
pdfmetrics.registerFont(TTFont('Verdana-Bold', 'VeraBd.ttf'))
instead of
pdfmetrics.registerFont(TTFont('Verdana', 'verdana.ttf'))
it worked for me.
According to the documentation:
In Marius' original patch the filename was supposed to be exactly correct, but we have modified things so that if the filename is relative then a search for the corresponding file is done in the current directory and then in directories specified by reportlab.rl_config.TTFSearchpath!
Since when you upload you won't be able to modify /reportlab/fonts, what you need to do is just upload it and then specify the location relative to the current working directory (should be the same directory as your Python code resides in, but if that doesn't work you might need to check the GAE documentation on where you can place support files like a font on the server).
But maybe I misunderstand and that's what you tried to do and failed?
The answer below is good but does not work on Google App Engine i don't know why! Here is a simple example based on the app directory for flask developers:
~/myapp
|-- mymodule.py
|-- myfont.ttf
So your code will be:
font = r"myfont.ttf"
pdfmetrics.registerFont(TTFont("myfont", font))

Categories

Resources