@@ -76,16 +76,31 @@ def __init__(self, start_url='http://www.google.com', **kwargs):
7676
7777 #Workaround for flexible size:
7878 #start browser when the height has changed (done by layout)
79- #This has to be done like this because I wasn't able to change the texture size
79+ #This has to be done like this because I wasn't able to change
80+ #the texture size
8081 #until runtime without core-dump.
8182 self .bind (size = self .size_changed )
82-
8383
84+
85+ starting = True
8486 def size_changed (self , * kwargs ):
8587 '''When the height of the cefbrowser widget got changed, create the browser
8688 '''
87- if self .height != 100 :
88- self .start_cef (self .start_url )
89+ if self .starting :
90+ if self .height != 100 :
91+ self .start_cef (self .start_url )
92+ self .starting = False
93+ else :
94+ self .texture = Texture .create (
95+ size = self .size , colorfmt = 'rgba' , bufferfmt = 'ubyte' )
96+ self .texture .flip_vertical ()
97+ with self .canvas :
98+ Color (1 , 1 , 1 )
99+ # This will cause segmentation fault:
100+ # | self.rect = Rectangle(size=self.size, texture=self.texture)
101+ # Update only the size:
102+ self .rect .size = self .size
103+ self .browser .WasResized ()
89104
90105
91106 def _cef_mes (self , * kwargs ):
@@ -105,12 +120,13 @@ def start_cef(self, start_url='http://google.com'):
105120 '''Starts CEF.
106121 '''
107122 # create texture & add it to canvas
108- self .texture = Texture .create (size = self .size , colorfmt = 'rgba' , bufferfmt = 'ubyte' )
123+ self .texture = Texture .create (
124+ size = self .size , colorfmt = 'rgba' , bufferfmt = 'ubyte' )
109125 self .texture .flip_vertical ()
110126 with self .canvas :
111127 Color (1 , 1 , 1 )
112128 self .rect = Rectangle (size = self .size , texture = self .texture )
113-
129+
114130 #configure cef
115131 cefpython .g_debug = True
116132 cefpython .g_debugFile = "debug.log"
@@ -153,7 +169,7 @@ def start_cef(self, start_url='http://google.com'):
153169 self .browser .SendFocusEvent (True )
154170
155171 #Create RenderHandler (in ClientHandler)
156- CH = ClientHandler (self . texture , self )
172+ CH = ClientHandler (self )
157173 self .browser .SetClientHandler (CH )
158174
159175 jsBindings = cefpython .JavascriptBindings (
@@ -452,15 +468,14 @@ def on_touch_up(self, touch, *kwargs):
452468
453469class ClientHandler :
454470
455- def __init__ (self , texture , parent ):
456- self .texture = texture
457- self .parent = parent
471+ def __init__ (self , browserWidget ):
472+ self .browserWidget = browserWidget
458473
459474
460475 def OnLoadStart (self , browser , frame ):
461- print ("OnLoadStart(): injecting focus listeners for text controls" )
462476 browserWidget = browser .GetUserData ("browserWidget" )
463477 if browserWidget and browserWidget .keyboard_mode == "local" :
478+ print ("OnLoadStart(): injecting focus listeners for text controls" )
464479 # The logic is similar to the one found in kivy-berkelium:
465480 # https://github.com/kivy/kivy-berkelium/blob/master/berkelium/__init__.py
466481 jsCode = """
@@ -511,7 +526,8 @@ def OnLoadingStateChange(self, browser, isLoading, canGoBack,
511526 pass
512527
513528
514- def OnPaint (self , browser , paintElementType , dirtyRects , buffer , width , height ):
529+ def OnPaint (self , browser , paintElementType , dirtyRects , buffer , width ,
530+ height ):
515531 # print "OnPaint()"
516532 if paintElementType != cefpython .PET_VIEW :
517533 print "Popups aren't implemented yet"
@@ -521,18 +537,20 @@ def OnPaint(self, browser, paintElementType, dirtyRects, buffer, width, height):
521537 buffer = buffer .GetString (mode = "bgra" , origin = "top-left" )
522538
523539 #update texture of canvas rectangle
524- self .texture .blit_buffer (buffer , colorfmt = 'bgra' , bufferfmt = 'ubyte' )
525- self .parent ._update_rect ()
540+ self .browserWidget .texture .blit_buffer (buffer , colorfmt = 'bgra' ,
541+ bufferfmt = 'ubyte' )
542+ self .browserWidget ._update_rect ()
526543
527544 return True
528545
529546
530547 def GetViewRect (self , browser , rect ):
531- width , height = self .texture .size
548+ width , height = self .browserWidget . texture .size
532549 rect .append (0 )
533550 rect .append (0 )
534551 rect .append (width )
535552 rect .append (height )
553+ # print("GetViewRect(): %s x %s" % (width, height))
536554 return True
537555
538556
0 commit comments