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

Class RenderHandler

examples/screenshot.py:213–244  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211
212
213class RenderHandler(object):
214 def __init__(self):
215 self.OnPaint_called = False
216
217 def GetViewRect(self, rect_out, **_):
218 """Called to retrieve the view rectangle which is relative
219 to screen coordinates. Return True if the rectangle was
220 provided."""
221 # rect_out --> [x, y, width, height]
222 rect_out.extend([0, 0, VIEWPORT_SIZE[0], VIEWPORT_SIZE[1]])
223 return True
224
225 def OnPaint(self, browser, element_type, paint_buffer, **_):
226 """Called when an element should be painted."""
227 if self.OnPaint_called:
228 sys.stdout.write(".")
229 sys.stdout.flush()
230 else:
231 sys.stdout.write("[screenshot.py] OnPaint")
232 self.OnPaint_called = True
233 if element_type == cef.PET_VIEW:
234 # Buffer string is a huge string, so for performance
235 # reasons it would be better not to copy this string.
236 # I think that Python makes a copy of that string when
237 # passing it to SetUserData.
238 buffer_string = paint_buffer.GetBytes(mode="rgba",
239 origin="top-left")
240 # Browser object provides GetUserData/SetUserData methods
241 # for storing custom data associated with browser.
242 browser.SetUserData("OnPaint.buffer_string", buffer_string)
243 else:
244 raise Exception("Unsupported element_type in OnPaint")
245
246
247if __name__ == '__main__':

Callers 1

create_browserFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected