88import win32gui
99import sys
1010
11-
12- #noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
1311def CloseApplication (windowID , msg , wparam , lparam ):
14-
1512 browser = cefpython .GetBrowserByWindowID (windowID )
1613 browser .CloseBrowser ()
1714 cefwindow .DestroyWindow (windowID )
1815 return 0 # If an application processes this message, it should return zero.
1916
20-
21- #noinspection PyUnusedLocal
2217def QuitApplication (windowID , msg , wparam , lparam ):
23-
2418 # If you put PostQuitMessage() in WM_CLOSE event (CloseApplication)
2519 # you will get memory errors when closing application.
2620 win32gui .PostQuitMessage (0 )
2721 return 0
2822
29-
3023def CefAdvanced ():
31-
32- # Programming API:
33- # http://code.google.com/p/cefpython/wiki/API
34-
24+ # Programming API: http://code.google.com/p/cefpython/wiki/API
3525 sys .excepthook = cefpython .ExceptHook # In case of exception display it, write to error.log, shutdown CEF and exit application.
3626 cefwindow .__debug = True # Whether to print debug output to console.
3727 cefpython .__debug = True
@@ -51,13 +41,14 @@ def CefAdvanced():
5141 windowID = cefwindow .CreateWindow ("CefAdvanced" , "cefadvanced" , 800 , 600 , None , None , "icon.ico" , wndproc )
5242
5343 browserSettings = dict () # See: http://code.google.com/p/cefpython/wiki/BrowserSettings
54- browserSettings ["history_disabled" ] = False
44+ browserSettings ["history_disabled" ] = False # Backspace key will act as "History back" action in browser.
5545 browserSettings ["universal_access_from_file_urls_allowed" ] = True
5646 browserSettings ["file_access_from_file_urls_allowed" ] = True
5747
5848 handlers = dict ()
5949 handlers ["OnLoadStart" ] = DocumentReady
6050 handlers ["OnLoadError" ] = OnLoadError
51+ handlers ["OnKeyEvent" ] = OnKeyEvent
6152
6253 browser = cefpython .CreateBrowser (windowID , browserSettings , "cefadvanced.html" , handlers )
6354
@@ -66,64 +57,62 @@ def CefAdvanced():
6657
6758
6859def DocumentReady (browser , frame ):
69-
7060 print "OnLoadStart(): frame URL: %s" % frame .GetURL ()
71- #browser.GetMainFrame().ExecuteJavascript("window.open('about:blank', '', 'width=500,height=500')")
7261 if frame .IsMain ():
7362 return
63+ #browser.GetMainFrame().ExecuteJavascript("window.open('about:blank', '', 'width=500,height=500')")
7464 #print "HidePopup(): %s" % browser.HidePopup()
7565
7666def OnLoadError (browser , frame , errorCode , failedURL , errorText ):
77-
7867 print "OnLoadError() failedURL: %s, frame = %s" % (failedURL , frame )
7968
69+ def OnKeyEvent (browser , eventType , keyCode , modifiers , isSystemKey , isAfterJavascript ):
70+ # Let's bind developer tools to F12 key.
71+ if cefpython .VK_F12 == keyCode and 0 == eventType and 1024 == modifiers and not isSystemKey :
72+ browser .ShowDevTools ()
73+ return True
74+ # Bind F5 to refresh browser window.
75+ elif cefpython .VK_F5 == keyCode and 0 == eventType and 1024 == modifiers and not isSystemKey :
76+ browser .ReloadIgnoreCache ()
77+ return True
78+ return False
8079
8180def JavascriptBindings ():
8281 # http://code.google.com/p/chromiumembedded/wiki/JavaScriptIntegration
8382 pass
8483
85-
8684def JavascriptCallbacks ():
8785 pass
8886
89-
9087def PopupWindow ():
9188 pass
9289
93-
9490def ModalWindow ():
9591 pass
9692
97-
9893def ResizeWindow ():
9994 #cefwindow.MoveWindow(windowID, width=500, height=500)
10095 pass
10196
102-
10397def MoveWindow ():
10498 #cefwindow.MoveWindow(windowID, xpos=0, ypos=0)
10599 pass
106100
107-
108101def DeveloperTools ():
109102 #browser.ShowDevTools()
110103 pass
111104
112-
113105def LoadContentFromZip ():
114106 # Allow to pack html/css/images to a zip and run content from this file.
115107 # Optionally allow to password protect this zip file.
116108 pass
117109
118-
119110def LoadContentFromEncryptedZip ():
120111 # This will be useful only if you protect your python sources by compiling them
121112 # to exe by using for example "pyinstaller", or even better you could compile sources
122113 # to a dll-like file called "pyd" by using cython extension, or you could combine them both.
123114 # See WBEA for implementation.
124115 pass
125116
126-
127117if __name__ == "__main__" :
128-
129118 CefAdvanced ()
0 commit comments