1212import gtk
1313import sys
1414import os
15+ import time
1516
1617from kivy .app import App
1718from kivy .uix .button import Button
@@ -80,6 +81,7 @@ def __init__(self, start_url='https://www.google.com/', **kwargs):
8081 # This has to be done like this because I wasn't able to change
8182 # the texture size
8283 # until runtime without core-dump.
84+ # noinspection PyArgumentList
8385 self .bind (size = self .size_changed )
8486
8587 self .browser = None
@@ -158,6 +160,7 @@ def start_cef(self):
158160 # Disable context menu, popup widgets not supported
159161 "enabled" : False ,
160162 },
163+ "external_message_pump" : False , # See Issue #246
161164 }
162165 switches = {
163166 # Tweaking OSR performance by setting the same Chromium flags
@@ -276,7 +279,7 @@ def change_url(self, *_):
276279 _keyboard = None
277280
278281 def request_keyboard (self ):
279- print ("request_keyboard()" )
282+ print ("[kivy_.py] request_keyboard()" )
280283 self ._keyboard = EventLoop .window .request_keyboard (
281284 self .release_keyboard , self )
282285 self ._keyboard .bind (on_key_down = self .on_key_down )
@@ -303,7 +306,7 @@ def release_keyboard(self):
303306 self .is_alt2 = False
304307 if not self ._keyboard :
305308 return
306- print ("release_keyboard()" )
309+ print ("[kivy_.py] release_keyboard()" )
307310 self ._keyboard .unbind (on_key_down = self .on_key_down )
308311 self ._keyboard .unbind (on_key_up = self .on_key_up )
309312 self ._keyboard .release ()
@@ -615,16 +618,16 @@ def on_touch_up(self, touch, *kwargs):
615618 y = - 1
616619 if y == self .height - 1 :
617620 y = self .height
618- print ("~~ DragSourceEndedAt" )
619- print ("~~ current_drag_operation=%s"
621+ print ("[kivy_.py] ~~ DragSourceEndedAt" )
622+ print ("[kivy_.py] ~~ current_drag_operation=%s"
620623 % self .current_drag_operation )
621624 self .browser .DragSourceEndedAt (x , y ,
622625 self .current_drag_operation )
623626 self .drag_ended ()
624627 else :
625- print ("~~ DragTargetDrop" )
626- print ("~~ DragSourceEndedAt" )
627- print ("~~ current_drag_operation=%s"
628+ print ("[kivy_.py] ~~ DragTargetDrop" )
629+ print ("[kivy_.py] ~~ DragSourceEndedAt" )
630+ print ("[kivy_.py] ~~ current_drag_operation=%s"
628631 % self .current_drag_operation )
629632 self .browser .DragTargetDrop (touch .x , y )
630633 self .browser .DragSourceEndedAt (touch .x , y ,
@@ -667,19 +670,19 @@ def on_touch_move(self, touch, *kwargs):
667670 # print("on_touch_move=%s/%s" % (touch.x, y))
668671 if self .is_inside_web_view (touch .x , y ):
669672 if self .is_drag_leave :
670- print ("~~ DragTargetDragEnter" )
673+ print ("[kivy_.py] ~~ DragTargetDragEnter" )
671674 self .browser .DragTargetDragEnter (
672675 self .drag_data , touch .x , y ,
673676 cef .DRAG_OPERATION_EVERY )
674677 self .is_drag_leave = False
675- print ("~~ DragTargetDragOver" )
678+ print ("[kivy_.py] ~~ DragTargetDragOver" )
676679 self .browser .DragTargetDragOver (
677680 touch .x , y , cef .DRAG_OPERATION_EVERY )
678681 self .update_drag_icon (touch .x , y )
679682 else :
680683 if not self .is_drag_leave :
681684 self .is_drag_leave = True
682- print ("~~ DragTargetDragLeave" )
685+ print ("[kivy_.py] ~~ DragTargetDragLeave" )
683686 self .browser .DragTargetDragLeave ()
684687
685688 def is_inside_web_view (self , x , y ):
@@ -696,7 +699,7 @@ def drag_ended(self):
696699 del self .drag_data
697700 self .current_drag_operation = cef .DRAG_OPERATION_NONE
698701 self .update_drag_icon (None , None )
699- print ("~~ DragSourceSystemDragEnded" )
702+ print ("[kivy_.py] ~~ DragSourceSystemDragEnded" )
700703 self .browser .DragSourceSystemDragEnded ()
701704
702705 drag_icon = None
@@ -765,12 +768,12 @@ def _fix_select_boxes(self, frame):
765768 # --
766769 # Cannot use "file://" urls to load local resources, error:
767770 # | Not allowed to load local resource
768- print ("_fix_select_boxes()" )
771+ print ("[kivy_.py] _fix_select_boxes()" )
769772 resources_dir = os .path .join (
770773 os .path .dirname (os .path .abspath (__file__ )),
771774 "kivy-select-boxes" )
772775 if not os .path .exists (resources_dir ):
773- print ("The kivy-select-boxes directory does not exist, "
776+ print ("[kivy_.py] The kivy-select-boxes directory does not exist, "
774777 "select boxes fix won't be applied." )
775778 return
776779 js_file = os .path .join (resources_dir , "kivy-selectBox.js" )
@@ -796,10 +799,12 @@ def _fix_select_boxes(self, frame):
796799 "kivy_.py > ClientHandler > OnLoadStart > _fix_select_boxes()" )
797800
798801 def OnLoadStart (self , browser , frame , ** _ ):
802+ self .load_start_time = time .time ()
799803 self ._fix_select_boxes (frame )
800804 browserWidget = browser .GetUserData ("browserWidget" )
801805 if browserWidget and browserWidget .keyboard_mode == "local" :
802- print ("OnLoadStart(): injecting focus listeners for text controls" )
806+ print ("[kivy_.py] OnLoadStart(): injecting focus listeners for"
807+ " text controls" )
803808 # The logic is similar to the one found in kivy-berkelium:
804809 # https://github.com/kivy/kivy-berkelium/blob/master/berkelium/__init__.py
805810 jsCode = """
@@ -849,15 +854,31 @@ def OnLoadEnd(self, browser, **_):
849854 browser .SendFocusEvent (True )
850855
851856 def OnLoadingStateChange (self , is_loading , ** _ ):
852- print ("OnLoadingStateChange() : isLoading = %s" % is_loading )
857+ print ("[kivy_.py] OnLoadingStateChange: isLoading = %s" % is_loading )
853858 # browserWidget = browser.GetUserData("browserWidget")
859+ if self .load_start_time :
860+ print ("[kivy_.py] OnLoadingStateChange: load time = {time}"
861+ .format (time = time .time ()- self .load_start_time ))
862+ self .load_start_time = None
854863
855864 def OnPaint (self , element_type , paint_buffer , ** _ ):
856865 # print "OnPaint()"
857866 if element_type != cef .PET_VIEW :
858867 print "Popups aren't implemented yet"
859868 return
860869
870+ # FPS meter ("fps" arg)
871+ if "fps" in sys .argv :
872+ if not hasattr (self , "last_paints" ):
873+ self .last_paints = []
874+ self .last_paints .append (time .time ())
875+ while len (self .last_paints ) > 30 :
876+ self .last_paints .pop (0 )
877+ if len (self .last_paints ) > 1 :
878+ fps = len (self .last_paints ) / \
879+ (self .last_paints [- 1 ] - self .last_paints [0 ])
880+ print ("[kivy_.py] FPS={fps}" .format (fps = fps ))
881+
861882 # update buffer
862883 paint_buffer = paint_buffer .GetString (mode = "bgra" , origin = "top-left" )
863884
@@ -915,7 +936,7 @@ def OnBeforeUnloadJavascriptDialog(self, callback, **_):
915936 return True
916937
917938 def StartDragging (self , drag_data , x , y , ** _ ):
918- print ("~~ StartDragging" )
939+ print ("[kivy_.py] ~~ StartDragging" )
919940 # Succession of d&d calls:
920941 # DragTargetDragEnter
921942 # DragTargetDragOver - in touch move event
@@ -924,7 +945,7 @@ def StartDragging(self, drag_data, x, y, **_):
924945 # DragTargetDrop - on mouse up
925946 # DragSourceEndedAt - on mouse up
926947 # DragSourceSystemDragEnded - on mouse up
927- print ("~~ DragTargetDragEnter" )
948+ print ("[kivy_.py] ~~ DragTargetDragEnter" )
928949 self .browserWidget .browser .DragTargetDragEnter (
929950 drag_data , x , y , cef .DRAG_OPERATION_EVERY )
930951 self .browserWidget .is_drag = True
0 commit comments