python-3.xdpichromium-embeddedhighdpicefpython

How can i set up high dpi on cefpython running on python3 without display bugs?


I have a code that used to run fine on python2. This code is a cefpython browser very similar to wxpython example located on git repository of cefpython. Now i moved to python3 and I am facing display bugs like the one of this picture:

diaply bug

The code regarding dpi is the following:

def main():
   ...
     if WINDOWS:
        # noinspection PyUnresolvedReferences, PyArgumentList
        cef.DpiAware.EnableHighDpiSupport()
    cef.Initialize(settings=settings)

class MainFrame(wx.Frame):
     def __init__(self):
        wx.Frame.__init__(self, parent=None, id=wx.ID_ANY,
                      title='', size=(WIDTH, HEIGHT))
        self.browser = None

      ...
      global g_count_windows
      g_count_windows += 1

      if WINDOWS:
          # noinspection PyUnresolvedReferences, PyArgumentList
          print("[wxpython.py] System DPI settings: %s"
             % str(cef.DpiAware.GetSystemDpi()))
       if hasattr(wx, "GetDisplayPPI"):
          print("[wxpython.py] wx.GetDisplayPPI = %s" % wx.GetDisplayPPI())
       print("[wxpython.py] wx.GetDisplaySize = %s" % wx.GetDisplaySize())

       print("[wxpython.py] MainFrame declared size: %s"
          % str((WIDTH, HEIGHT)))
       size = scale_window_size_for_high_dpi(WIDTH, HEIGHT)
       print("[wxpython.py] MainFrame DPI scaled size: %s" % str(size))

    wx.Frame.__init__(self, parent=None, id=wx.ID_ANY,
                      title='wxPython example', size=size)

    print("[wxpython.py] MainFrame actual size: %s" % self.GetSize())

And the output prints related to dpi and versions are:

[wxpython.py] CEF Python 66.0
[wxpython.py] Python 3.7.3 32bit
[wxpython.py] wxPython 4.0.6 msw (phoenix) wxWidgets 3.0.5
[wxpython.py] System DPI settings: (120, 120)
[wxpython.py] wx.GetDisplayPPI = (157, 158)
[wxpython.py] wx.GetDisplaySize = (1920, 1080)
[wxpython.py] MainFrame declared size: (800, 600)
[wxpython.py] MainFrame DPI scaled size: (1000, 750)

How can I run this example on python3?

Thank you for any further help. Ricardo


Solution

  • The solution to my problem was pointed by Czarek Tomczak on a comment to my question: https://github.com/cztomczak/cefpython/issues/530#issuecomment-505066492

    Adding the parameter {'disable-gpu': ''} to the switches solved my problem.

    cef.Initialize(settings={}, switches={'disable-gpu': ""})
    

    On the thread available on the link, it says that this is not the right solution. It worked for me, and I am not having problems until now. But if anyone knows another solution I can try it.