Django - suing font awersome in unicode form - django

I want to use font awersome in my project in the way, that user can choose which icon he wants. I found django-fontawesome-5 but there is one problem - there is no access to icon's unicode and I need it for one javascript component (html doesn't work there, and unicode does). I was looking all over the internet, but I coundn't find anything that would allow me to add font-awersome icons, with their unicodes somhow stored. My question is do you know how to get this feature?

The unicode codes are stored in icons.json and in icons_semantic_ui.json
Since you've got the codes source you can define a custom templatetag or a model/mixin method or a function which just gets a code from one of those json files using icon name
You can see example in fontawesome_5/utils.py

Related

Get app icon URL in Qt on Linux

I am trying to get the icon of an app (doesn't matter which one). I noticed Qt doesn't have something like GDesktopAppInfo and therefore I tried getting it through QSettings from /usr/share/applications/appname.desktop. That's already a problem, because the desktop file might not be there. Anyway, going further to extract the Icon key. Now I dunno how to find the url (notice that I need the url, sure I could make a QIcon, but I need to export it to QML, which would mean another QQuickImageProvider class, anyway, I don't wanna go that way). Is it possible, or is the aforementioned QQuickImageProvider my only solution?
Here is a little guide that might help you find your way. Keep one thing in mind: start with the basic case, get code running and extend it to more difficult cases later.
For now, lets assume the following:
.desktop file is in /usr/share/applications
App icon is in SVG or PNG format
App icon path is absolute
App name is lower case and does not contain whitespace
Input: App name "git-cola"
Read /usr/share/applications/git-cola.desktop
Use a QRegularExpression to get the Icon value
You get an absolute iconPath, e.g. /usr/share/git-cola/icons/git.svg
Have an invokable C++ function that exposes a QUrl to QML
In QML, set the source property of an Image to getIconUrl("Target App")
where 4. looks something like
QUrl MyClass::getIconUrl(QString appName)
{
// get iconPath from appName
return QUrl::​fromLocalFile(iconPath);
}
If things are running, you can add support for
Multiple .desktop locations (there might be a handful or so)
Add support for relative paths
Add support for XPM files
You can use QIcon::fromTheme(QString iconName) to find the icon. It works most of the time but it's not as reliable as gtk

Path shortener with MFC

I need to display paths in the context menu in my app and need to find a way to shorted them. For instance, what Microsoft apps do in their "Recently Used" list, if the original path is c:\ClientName\ProjectName\ProgramName\ComponentName\SomeFileName.cpp I need it to be converted into something like c:\ClientName\...\SomeFileName.cpp.
So I'm curious if there's any built-in means to do this with C++/MFC or maybe a WinAPI?
Use PathCompacPathEx that will truncate a path by replacing path components with ellipses.
There is Win32 API to get short path name called GetShortPathName, read below. It may help.
http://msdn.microsoft.com/en-us/library/windows/desktop/aa364989(v=vs.85).aspx

Inkscape inx param defaults

I am developing a extension for Inkscape and would like to set a param value based on a value that is set on a object. For example if the ID of the selected object is set to "myRect" how would I display that value in the extension dialog? Seems to me that there should be a way to tell Inkscape that I want a value displayed here from attribute "id", I have read through the documentation on Inkscapes wiki and searched the web but couldn't find any answers.
I don't think it's possible.
The extension UI is built from the static .inx file. There's no way for your extension code to modify that AFAIK.
It might be possible to have your extension rewrite the .inx file all the time. But I imagine that this would be a horrible horrible approach. Also I'm not sure how frequently inkscape reloads the .inx file.

Django Mezzanine Unicode Error

i get an unicode error when trying url like www.mysite.com/blog/category/πρακτικα/ or www.mysite.com/blog/πρακτικα/
but i dont get the error when trying www.mysite.com/blog/tag/πρακτικα/
UnicodeEncodeError at /blog/category/πρακτικα/ 'latin-1' codec can't encode characters in >position 58-65: ordinal not in range(256)
Exception Location: /home/vagrant/sullogos-venv/local/lib/python2.7/site-packages/django/template/loaders/filesystem.py in load_template_source, line 37
seems it haves different behavior at categories and at tags
The difference is that categories can have a custom template and tags can't. So in the category case, a template name is searched for using the category slug - the error you're getting is due to an incorrectly configured locale which doesn't support utf8.
This is not a problem with Mezzanine or Django, but with the environment used to deploy them. See this issue and this documentation for more details. It's not enough for Python to support a specific locale, but it's also necessary for the webserver to be able to handle Unicode files correctly.
How to fix it will depend on the webserver used. If you're using Apache, for instance, you need to set LANG and LC_ALL to Unicode-compatible values (on *NIX systems at least you should find them at /etc/apache2/envvars). An example would be:
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
Feel free to replace the language/country codes with another one more suitable for your needs (I used pt_BR instead of en_US and things worked fine for me). From the error message you're seeing, these settings in your system are probably using ISO-Latin (ISO-8859-1) instead of UTF-8 (which I assume can't handle cyrillic).
If you're using a different webserver, check its documentation on localization/internationalization to see what needs to be changed. The important thing is to offer support to Unicode file names, as I understood.

Get a font filename based on Font Name and Style (Bold/Italic)

This has been driving me crazy all day.
I need to get a font filename (eg. Arial.ttf) based on its name (Arial in this case) and whether it is bold, italic or both. Using those pieces of information, I need to find the font file so I can use it for rendering.
Some more examples:
Calibri, Bold would resolve to calibrib.ttf.
Calibri, Italic would resolve to calibrii.ttf.
Any ideas on how I could achieve this in C++ (Win32)
First, to my knowledge, there is no reliable way to do that.
The Windows API deals with font families and mappings, not with font files, which are dealt with at a lower level. Also note that even if you manage to get the file name of a font, no rendering function (that I know of) will accept it, so what will you do with it?
That said, you can look in the registry key HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts in order to obtain the file name of a font from its logical name. An implementation of that solution can be found here.
Related to the earlier posts, this seems to be a reliable way:
1) Read the registered Windows font list from
HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts\
You will obtain file names and alternate file paths here.
The Font names are not useful as they can change with user's locale.
2) Load the TrueType files (.ttf, .ttc, .otf):
Use FreeType https://www.freetype.org/). Just initialize the freetype library and load face with FT_New_Face(library, path, 0, &face).
3) Obtain the font Family name using FreeType.
Use FT_Get_Sfnt_Name_Count() and FT_Get_Sfnt_Name() to obtain the string table.
You will need to check if the encoding is Ansi, UTF16 or other, as some strings will be in multiple different languages and encodings.
4) Obtain the OS2 TrueType properties.
Use (TT_OS2 *) FT_Get_Sfnt_Table (face, ft_sfnt_os2) to get the OS2 structure.
Interpret the structure using docs like https://www.microsoft.com/typography/otspec/os2.htm#fc
5) Now you have font file path, family name, style properties and other information. Build a list of these and function to search for a file based on font family and style.
This Code Project project does what you want. As-is it fails on Windows 7 because the GetWinVer function stops at XP. It is trivial to add the case for Windows 7.
You normally do this by calling CreateFontIndirect and then getting the system to render. Perhaps you could explain why you can't use this standard approach.
One solution would be to access the font files and extract the name from the name table to create your own lookup (an STL map would be a simple way of doing that). Details of the TTF file format can be found here.