spyder-ide / qtawesome

Iconic fonts in PyQt and PySide applications
https://qtawesome.readthedocs.io/en/latest/index.html
MIT License
796 stars 105 forks source link

Icons are blocked because of untrusted fonts on Windows 10 #167

Closed giumas closed 1 year ago

giumas commented 2 years ago

I need to deploy an app using qtawesome on some machines where the Untrusted Font Blocking policy is set to "Block untrusted fonts and log events" (https://docs.microsoft.com/en-US/troubleshoot/windows-client/shell-experience/feature-to-block-untrusted-fonts).

With such a policy, the example.py in the root of the repository returns:

Traceback (most recent call last):
  File "C:/code/example.py", line 167, in <module>
    main()
  File "C:/code/example.py", line 162, in main
    _ = AwesomeExample()
  File "C:/code/example.py", line 18, in __init__
    fa5_icon = qta.icon('fa5.flag')
  File "C:\Users\tester\AppData\Local\test\envs\hyo2\lib\site-packages\qtawesome\__init__.py", line 173, in icon
    return _instance().icon(*names, **kwargs)
  File "C:\Users\tester\AppData\Local\test\envs\hyo2\lib\site-packages\qtawesome\__init__.py", line 77, in _instance
    'materialdesignicons-webfont-charmap.json')
  File "C:\Users\tester\AppData\Local\test\envs\hyo2\lib\site-packages\qtawesome\iconic_font.py", line 214, in __init__
    self.load_font(*fargs)
  File "C:\Users\tester\AppData\Local\test\envs\hyo2\lib\site-packages\qtawesome\iconic_font.py", line 270, in load_font
    os.path.join(directory, ttf_filename)))
qtawesome.iconic_font.FontError: Font at 'C:\Users\tester\AppData\Local\test\envs\hyo2\lib\site-packages\qtawesome\fonts\fontawesome4.7-webfont.ttf' appears to be empty. If you are on Windows 10, please read https://support.microsoft.com/en-us/kb/3053676 to know how to prevent Windows from blocking the fonts that come with QtAwesome.

The issue is present also when running the PyInstaller-based frozen version of the app: https://github.com/ausseabed/qax/issues/9

dalthviz commented 2 years ago

Hi @giumas thank you for the feedback! As described in the traceback if the font file is unable to load we suggest checking the link you describe for the user to allow/setup properly the font since from the package I think there is not much we can do (to enable the font load you either install the font or exclude the application/process using it from validation). However if you know a way to handle this from QtAwesome let us know :+1:

giumas commented 2 years ago

Thanks! Can you confirm that there is no way to get the QtAwesome icons without loading those fonts?

CC: @lachlanhurst

dalthviz commented 2 years ago

From my understanding yep, without loading the fonts there is no way for QtAwesome to be able to work. However, just in case, pinging @ccordoba12

ccordoba12 commented 2 years ago

I think a possible workaround is to install those fonts in the user AppData directory. But that only works for a recent Windows 10 build.

giumas commented 2 years ago

Interesting! It seems something that could be done/checked at the app initialization. What do you mean with 'install those fonts'? Copying them? How to then ask QTAwesome to search in that folder?

dalthviz commented 2 years ago

Checking seems like there is a way to setup/install fonts only for the current user (so without admin rights) since the Windows 10 build from 2018 (RS5): https://blogs.windows.com/windows-insider/2018/06/27/announcing-windows-10-insider-preview-build-17704/#vtHzS6SkLWyrfI4D.97 However, I'm not totally sure in the programmatic approach to do it (probably it requires copying the fonts sources in a directory under the user folder and some registry entry?)

ccordoba12 commented 2 years ago

However, I'm not totally sure in the programmatic approach to do it (probably it requires copying the fonts sources in a directory under the user folder and some registry entry?)

Yeah, I think it should be enough.

dalthviz commented 1 year ago

Note: This SO post could be useful here (needs adaptation to install for the user and not to the whole machine) - https://stackoverflow.com/a/41841088/15954282