MCPcopy Create free account
hub / github.com/cztomczak/cefpython / CefWidget

Class CefWidget

examples/qt.py:203–288  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

201
202
203class CefWidget(CefWidgetParent):
204 def __init__(self, parent=None):
205 # noinspection PyArgumentList
206 super(CefWidget, self).__init__(parent)
207 self.parent = parent
208 self.browser = None
209 self.hidden_window = None # Required for PyQt5 on Linux
210 self.show()
211
212 def focusInEvent(self, event):
213 # This event seems to never get called on Linux, as CEF is
214 # stealing all focus due to Issue #284.
215 if cef.GetAppSetting("debug"):
216 print("[qt.py] CefWidget.focusInEvent")
217 if self.browser:
218 if WINDOWS:
219 WindowUtils.OnSetFocus(self.getHandle(), 0, 0, 0)
220 self.browser.SetFocus(True)
221
222 def focusOutEvent(self, event):
223 # This event seems to never get called on Linux, as CEF is
224 # stealing all focus due to Issue #284.
225 if cef.GetAppSetting("debug"):
226 print("[qt.py] CefWidget.focusOutEvent")
227 if self.browser:
228 self.browser.SetFocus(False)
229
230 def embedBrowser(self):
231 if (PYSIDE2 or PYQT5) and LINUX:
232 # noinspection PyUnresolvedReferences
233 self.hidden_window = QWindow()
234 window_info = cef.WindowInfo()
235 rect = [0, 0, self.width(), self.height()]
236 window_info.SetAsChild(self.getHandle(), rect)
237 self.browser = cef.CreateBrowserSync(window_info,
238 url="https://www.google.com/")
239 self.browser.SetClientHandler(LoadHandler(self.parent.navigation_bar))
240 self.browser.SetClientHandler(FocusHandler(self))
241
242 def getHandle(self):
243 if self.hidden_window:
244 # PyQt5 on Linux
245 return int(self.hidden_window.winId())
246 try:
247 # PyQt4 and PyQt5
248 return int(self.winId())
249 except:
250 # PySide:
251 # | QWidget.winId() returns <PyCObject object at 0x02FD8788>
252 # | Converting it to int using ctypes.
253 if sys.version_info[0] == 2:
254 # Python 2
255 ctypes.pythonapi.PyCObject_AsVoidPtr.restype = (
256 ctypes.c_void_p)
257 ctypes.pythonapi.PyCObject_AsVoidPtr.argtypes = (
258 [ctypes.py_object])
259 return ctypes.pythonapi.PyCObject_AsVoidPtr(self.winId())
260 else:

Callers 1

setupLayoutMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected