2

I'm trying to get CEFPython running on my High DPI laptop screen. Currently, I call the following:

    sys.excepthook = cef.ExceptHook  # To shutdown all CEF processes on error
    cef.Initialize()
    cef.DpiAware.EnableHighDpiSupport()
    cef.CreateBrowserSync(url="http://localhost:4994",
                          window_title="Fabel")
    cef.MessageLoop()
    cef.Shutdown()

This causes the ensuing problem to occur:

enter image description here

Looking online I found a few references to the same problem from other people:

However, I don't have the knowledge to apply it directly to CEFPython. Any help would be appreciated!

Nazim Kerimbekov
  • 4,712
  • 8
  • 34
  • 58
  • Call `EnableHighDpiSupport()` before `Initialize()`. – Czarek Tomczak Apr 25 '19 at 22:01
  • @CzarekTomczak Sorry, I should have clarified that I've already tried moving the `EnableHighDpiSupport` call around! That nets me the same result unfortunately. – Parth Doshi Apr 26 '19 at 01:26
  • Does the wxpython.py example work? It has built-in High-DPI support. – Czarek Tomczak Apr 26 '19 at 06:38
  • What if you check "Disable display scaling on high DPI settings" on the python.exe process (properties > Compatibility tab)? – Czarek Tomczak Apr 26 '19 at 06:43
  • Does the issue occur by default, or only after resizing window? – Czarek Tomczak Apr 26 '19 at 06:43
  • Check "Disable display scaling on high DPI settings" also on subprocess.exe executable that can be found in cefpython3 package directory. (python/lib/site-packages/) – Czarek Tomczak Apr 26 '19 at 06:52
  • There's no 'Display display scaling on high DPI settings' but I before posting this I did try overriding high DPI scaling behavior on python.exe. Changing it to system or system (enhanced) fixed the multiple rendering problem but made the text blurry again. – Parth Doshi Apr 26 '19 at 14:02
  • I just changed subprocess.exe's high DPI scaling behavior to 'application' and it fixed the problem! – Parth Doshi Apr 26 '19 at 14:03
  • Just to document a little more, the issue occurs by default but when you load the application it looks perfect. Once you start to mouse over the application, it starts drawing the 'inner' UI depending on where you moved the mouse. This resets once you start scrolling or resizing the window but will come back as soon as you start moving the mouse again. – Parth Doshi Apr 26 '19 at 14:04
  • @CzarekTomczak, one last question: is there a way to make this subprocess.exe's default behavior? – Parth Doshi Apr 26 '19 at 14:11
  • Create "subprocess.exe.manifest" file along the executable and set "dpiAware" to true. See https://learn.microsoft.com/en-us/windows/desktop/sbscs/application-manifests and https://stackoverflow.com/questions/23551112/how-can-i-set-the-dpiaware-property-in-a-windows-application-manifest-to-per-mo for an example content. – Czarek Tomczak Apr 26 '19 at 18:53
  • It is recommended to use manifests instead of calling EnableHighDpiSupport() function, because sometimes calling it can be too late. If app includes manifest then OS knows that app is DPI aware before it's launched. You have to add manifests for both app executable and subprocess executable. – Czarek Tomczak Apr 26 '19 at 18:57
  • Would I be forced to add the manifest file in the same folder as subprocess.exe? Because this isn’t always possible especially if the user is using `pip install` to grab `CEFPython` into their python packages folder. – Parth Doshi Apr 26 '19 at 19:16
  • Is the issue reproducible with the minimal code you've provided? Try calling EnableHighDpiSupport() as soon as possible in your Python code before anything else - make it the second line of code just after import. You could make a workaround by reloading page e.g. load "about:blank" first and then reload. – Czarek Tomczak Apr 26 '19 at 20:03
  • I can reproduce it with just ``` from cefpython3 import cefpython as cef cef.DpiAware.EnableHighDpiSupport() import sys sys.excepthook = cef.ExceptHook # To shutdown all CEF processes on error cef.Initialize() cef.DpiAware.EnableHighDpiSupport() cef.CreateBrowserSync(url="https://google.com", window_title="Fabel") cef.MessageLoop() cef.Shutdown() ``` – Parth Doshi Apr 27 '19 at 03:06
  • Sorry, I can't format it and it won't allow me to move this to chat because I don't have enough rep. Here's some random host I found online that makes it look at least a little better haha: https://justpaste.it/3w33e – Parth Doshi Apr 27 '19 at 03:09
  • Oh and reloading the page doesn't solve the problem unfortunately – Parth Doshi Apr 27 '19 at 03:10
  • Does the issue reproduce in wxpython.py example? That example has built-in high dpi support. – Czarek Tomczak Apr 27 '19 at 12:39
  • Put MessageLoop and Shutdown calls to a separate func and call that func with a 100ms delay with the use of cef.PostTask. Does that help? – Czarek Tomczak Apr 27 '19 at 12:42
  • How did you try the reload? You have to wait until browser is actually created. Try reloading with the use of cef.PostTask with some delay or use LoadHandler.OnLoadEnd. – Czarek Tomczak Apr 27 '19 at 12:43

1 Answers1

0

With the help of @CzarekTomczak, the solution for me was to navigate to cefpython3's site-package directory, right click subprocess.exe -> properties -> Compatibility -> Change high DPI settings -> Override high DPI scaling behavior. Scaling performed by: -> Application.

Here's a picture that might make it simpler: subprocess.exe compatibility settings

(Sorry, can't embed pictures yet due to my low rep)