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

Method get_window_handle

examples/tkinter_.py:180–212  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

178 self.message_loop_work()
179
180 def get_window_handle(self):
181 if MAC:
182 # Do not use self.winfo_id() on Mac, because of these issues:
183 # 1. Window id sometimes has an invalid negative value (Issue #308).
184 # 2. Even with valid window id it crashes during the call to NSView.setAutoresizingMask:
185 # https://github.com/cztomczak/cefpython/issues/309#issuecomment-661094466
186 #
187 # To fix it using PyObjC package to obtain window handle. If you change structure of windows then you
188 # need to do modifications here as well.
189 #
190 # There is still one issue with this solution. Sometimes there is more than one window, for example when application
191 # didn't close cleanly last time Python displays an NSAlert window asking whether to Reopen that window. In such
192 # case app will crash and you will see in console:
193 # > Fatal Python error: PyEval_RestoreThread: NULL tstate
194 # > zsh: abort python tkinter_.py
195 # Error messages related to this: https://github.com/cztomczak/cefpython/issues/441
196 #
197 # There is yet another issue that might be related as well:
198 # https://github.com/cztomczak/cefpython/issues/583
199
200 # noinspection PyUnresolvedReferences
201 from AppKit import NSApp
202 # noinspection PyUnresolvedReferences
203 import objc
204 logger.info("winfo_id={}".format(self.winfo_id()))
205 # noinspection PyUnresolvedReferences
206 content_view = objc.pyobjc_id(NSApp.windows()[-1].contentView())
207 logger.info("content_view={}".format(content_view))
208 return content_view
209 elif self.winfo_id() > 0:
210 return self.winfo_id()
211 else:
212 raise Exception("Couldn't obtain window handle")
213
214 def message_loop_work(self):
215 cef.MessageLoopWork()

Callers 1

embed_browserMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected