Skip to content

Commit ac438e1

Browse files
committed
Finished refactoring Cython includes.
1 parent 3072397 commit ac438e1

21 files changed

+280
-106
lines changed

browser.pyx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
# License: New BSD License.
33
# Website: http://code.google.com/p/cefpython/
44

5-
from cef_ptr cimport *
6-
from cef_browser cimport *
5+
include "imports.pyx"
6+
include "utils.pyx"
77

88
# Global variables.
99

@@ -96,6 +96,10 @@ class PyBrowser:
9696

9797
def CloseBrowser(self):
9898

99+
global __cefBrowsers
100+
global __pyBrowsers
101+
global __browserInnerWindows
102+
99103
cdef CefRefPtr[CefBrowser] cefBrowser = GetCefBrowserByInnerWindowID(CheckInnerWindowID(self.innerWindowID))
100104
__cefBrowsers.erase(<int>self.innerWindowID)
101105
del __pyBrowsers[self.innerWindowID]

cefexample/cefadvanced.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@
66
import cefwindow
77
import win32con # pywin32 extension
88
import win32gui
9-
import os
109
import sys
11-
import traceback
12-
import time
13-
import threading
1410

1511

12+
#noinspection PyUnusedLocal,PyUnusedLocal,PyUnusedLocal
1613
def CloseApplication(windowID, msg, wparam, lparam):
1714

1815
browser = cefpython.GetBrowserByWindowID(windowID)
1916
browser.CloseBrowser()
2017
cefwindow.DestroyWindow(windowID)
2118
return 0 # If an application processes this message, it should return zero.
2219

20+
21+
#noinspection PyUnusedLocal
2322
def QuitApplication(windowID, msg, wparam, lparam):
2423

2524
# If you put PostQuitMessage() in WM_CLOSE event (CloseApplication)
@@ -37,7 +36,7 @@ def CefAdvanced():
3736
cefwindow.__debug = True # Whether to print debug output to console.
3837
cefpython.__debug = True
3938

40-
appSettings = {} # See: http://code.google.com/p/cefpython/wiki/AppSettings
39+
appSettings = dict() # See: http://code.google.com/p/cefpython/wiki/AppSettings
4140
appSettings["multi_threaded_message_loop"] = False
4241
appSettings["log_severity"] = cefpython.LOGSEVERITY_VERBOSE # LOGSEVERITY_DISABLE - will not create "debug.log" file.
4342
cefpython.Initialize(appSettings)
@@ -51,12 +50,12 @@ def CefAdvanced():
5150
}
5251
windowID = cefwindow.CreateWindow("CefAdvanced", "cefadvanced", 800, 600, None, None, "icon.ico", wndproc)
5352

54-
browserSettings = {} # See: http://code.google.com/p/cefpython/wiki/BrowserSettings
53+
browserSettings = dict() # See: http://code.google.com/p/cefpython/wiki/BrowserSettings
5554
browserSettings["history_disabled"] = False
5655
browserSettings["universal_access_from_file_urls_allowed"] = True
5756
browserSettings["file_access_from_file_urls_allowed"] = True
5857

59-
handlers = {}
58+
handlers = dict()
6059
handlers["OnLoadStart"] = DocumentReady
6160
handlers["OnLoadError"] = OnLoadError
6261

@@ -97,17 +96,17 @@ def ModalWindow():
9796

9897

9998
def ResizeWindow():
100-
cefwindow.MoveWindow(windowID, width=500, height=500)
99+
#cefwindow.MoveWindow(windowID, width=500, height=500)
101100
pass
102101

103102

104103
def MoveWindow():
105-
cefwindow.MoveWindow(windowID, xpos=0, ypos=0)
104+
#cefwindow.MoveWindow(windowID, xpos=0, ypos=0)
106105
pass
107106

108107

109108
def DeveloperTools():
110-
browser.ShowDevTools()
109+
#browser.ShowDevTools()
111110
pass
112111

113112

cefexample/cefsimple.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
import win32gui
88
import sys
99

10+
#noinspection PyUnusedLocal
1011
def CloseApplication(windowID, msg, wparam, lparam):
1112

1213
browser = cefpython.GetBrowserByWindowID(windowID)
1314
browser.CloseBrowser()
1415
cefwindow.DestroyWindow(windowID)
1516

17+
#noinspection PyUnusedLocal
1618
def QuitApplication(windowID, msg, wparam, lparam):
1719

1820
win32gui.PostQuitMessage(0)

cefexample/cefwindow.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ def CreateWindow(title, classname, width, height, xpos=None, ypos=None, icon=Non
2323
if not wndproc:
2424
wndproc = {win32con.WM_CLOSE: WM_CLOSE}
2525

26+
bigIcon = ""
27+
smallIcon = ""
28+
2629
if icon:
2730
if icon.find("/") == -1 and icon.find("\\") == -1:
2831
icon = "%s%s%s" % (os.getcwd(), os.sep, icon)
@@ -49,6 +52,7 @@ def CreateWindow(title, classname, width, height, xpos=None, ypos=None, icon=Non
4952
wndclass.hCursor = win32gui.LoadCursor(0, win32con.IDC_ARROW)
5053
wndclass.lpfnWndProc = wndproc
5154

55+
#noinspection PyUnusedLocal
5256
atomclass = win32gui.RegisterClass(wndclass)
5357

5458
if __debug:
@@ -104,10 +108,10 @@ def GetWindowClassname(windowID):
104108
def MoveWindow(windowID, xpos=None, ypos=None, width=None, height=None, center=None):
105109

106110
(left, top, right, bottom) = win32gui.GetWindowRect(windowID)
107-
if xpos == None and ypos == None:
111+
if xpos is None and ypos is None:
108112
xpos = left
109113
ypos = top
110-
if width == None and height == None:
114+
if width is None and height is None:
111115
width = right - left
112116
height = bottom - top
113117
# Case: only ypos provided
@@ -130,6 +134,7 @@ def MoveWindow(windowID, xpos=None, ypos=None, width=None, height=None, center=N
130134
win32gui.MoveWindow(windowID, xpos, ypos, width, height, 1)
131135

132136

137+
#noinspection PyUnusedLocal
133138
def WM_CLOSE(windowID, msg, wparam, lparam):
134139

135140
DestroyWindow(windowID)
@@ -141,10 +146,10 @@ def GetLastError():
141146
code = win32api.GetLastError()
142147
return "(%d) %s" % (code, win32api.FormatMessage(code))
143148

144-
149+
#noinspection PyUnusedLocal
145150
def MessageLoop(classname):
146151

147-
while win32gui.PumpWaitingMessages() == 0:
152+
while not win32gui.PumpWaitingMessages():
148153
time.sleep(0.001)
149154

150155

cefexample/debug.log

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,16 @@
3838
[0708/081433:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
3939
[0708/081458:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
4040
[0708/081920:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
41+
[0708/105327:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
42+
[0708/105800:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
43+
[0708/114617:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
44+
[0708/114800:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
45+
[0708/120146:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
46+
[0708/122430:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
47+
[0708/122618:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
48+
[0708/122652:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
49+
[0708/123137:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
50+
[0708/123414:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
51+
[0708/124025:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
52+
[0708/134004:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091
53+
[0708/134543:ERROR:network_change_notifier_win.cc(111)] WSALookupServiceBegin failed with: 10091

cefpython.pyx

Lines changed: 12 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,71 +2,36 @@
22
# License: New BSD License.
33
# Website: http://code.google.com/p/cefpython/
44

5-
import os
6-
import sys
7-
import win32con
8-
import win32gui
9-
import win32api
10-
import cython
11-
import traceback
12-
import time
13-
14-
from libcpp cimport bool as cbool
15-
from libcpp.map cimport map
16-
from libcpp.vector cimport vector
17-
from cython.operator cimport preincrement as preinc, dereference as deref # must be "as" otherwise not seen.
18-
from libc.stdlib cimport malloc, free
19-
20-
# When pyx file cimports * from a pxd file and that cimports * from another pxd
21-
# then these another names will be visible in pyx file.
22-
23-
# Circular imports are allowed in form "cimport ...",
24-
# but won't work if you do "from ... cimport *", this
25-
# is important to know in pxd files.
26-
27-
# <CefRefPtr[ClientHandler]?>new ClientHandler() # <...?> means to throw an error if the cast is not allowed
28-
29-
from windows cimport *
30-
from cef_string cimport *
31-
from cef_type_wrappers cimport *
32-
from cef_task cimport *
33-
from cef_win cimport *
34-
from cef_ptr cimport *
35-
from cef_app cimport *
36-
from cef_browser cimport *
37-
from cef_client cimport *
38-
from clienthandler cimport *
39-
from cef_frame cimport *
40-
cimport cef_types
5+
# All .pyx files need to be included here for Cython compiler.
6+
include "imports.pyx"
7+
include "browser.pyx"
8+
include "frame.pyx"
9+
include "javascriptbindings.pyx"
10+
include "loadhandler.pyx"
11+
include "settings.pyx"
12+
include "utils.pyx"
13+
include "wndproc.pyx"
4114

4215
# Global variables.
43-
4416
__debug = False
4517

46-
4718
# Client handler.
48-
cdef CefRefPtr[ClientHandler] __clientHandler = <CefRefPtr[ClientHandler]?>new ClientHandler()
19+
cdef CefRefPtr[ClientHandler] __clientHandler = <CefRefPtr[ClientHandler]>new ClientHandler()
4920

5021

5122
def ExceptHook(type, value, traceobject):
52-
23+
5324
error = "\n".join(traceback.format_exception(type, value, traceobject))
5425
if hasattr(sys, "frozen"): path = os.path.dirname(sys.executable)
5526
elif "__file__" in locals(): path = os.path.dirname(os.path.realpath(__file__))
5627
else: path = os.getcwd()
57-
with open(path+"/error.log", "a") as file:
28+
with open("%s/error.log" % path, "a") as file:
5829
file.write("\n[%s] %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S"), error))
5930
print "\n"+error+"\n"
6031
CefQuitMessageLoop()
6132
CefShutdown()
6233
os._exit(1) # so that "finally" does not execute
6334

64-
65-
def GetLastError():
66-
67-
code = win32api.GetLastError()
68-
return "(%d) %s" % (code, win32api.FormatMessage(code))
69-
7035
def __InitializeClientHandler():
7136

7237
InitializeLoadHandler()
@@ -184,17 +149,3 @@ def Shutdown():
184149
CefShutdown()
185150
if __debug: print "GetLastError(): %s" % GetLastError()
186151

187-
188-
# ------------------
189-
190-
cimport cef_types
191-
192-
TID_UI = cef_types.TID_UI
193-
TID_IO = cef_types.TID_IO
194-
TID_FILE = cef_types.TID_FILE
195-
196-
def CurrentlyOn(threadID):
197-
198-
threadID = <int>int(threadID)
199-
return CefCurrentlyOn(<CefThreadId>threadID)
200-

compile.bat

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
del "cefexample\cefpython.pyd"
2-
del "setup\cefpython.pyx"
32
del "setup\cefpython.pyd"
4-
del "setup\cefpython.cpp"
5-
rmdir /S /Q "setup/build"
63

7-
REM copy all src\*.pyx to src\setup\:
8-
for /R %~dp0\ %%f in (*.pyx) do copy %%f %~dp0\setup\
4+
for /R %~dp0setup\ %%f in (*.pyx) do del "%%f"
5+
6+
rmdir /S /Q "%dp0setup\build\"
7+
8+
REM copy all src\*.pyx to src\setup\ - commentint out, as it copies recursively from all subdirectories.
9+
REM for /R %~dp0 %%f in (*.pyx) do del "%%f"
910

1011
cd "setup"
1112

12-
call python "mergepyxfiles.py"
13+
call python "fixincludes.py"
1314
call python "setup.py" build_ext --inplace
1415

16+
for /R %~dp0setup\ %%f in (*.pyx) do del "%%f"
17+
18+
REM %~dp0 doesn't work with rmdir.
19+
rmdir /S /Q "build\"
20+
1521
@if %ERRORLEVEL% neq 0 pause
1622
@if %ERRORLEVEL% neq 0 exit
1723

frame.pyx

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
# License: New BSD License.
33
# Website: http://code.google.com/p/cefpython/
44

5+
include "imports.pyx"
6+
include "utils.pyx"
7+
58
# id: (int64 = long in python) CefFrame.GetIdentifier() - globally unique identifier.
69
# In Python 2 there is: int (32 bit) long (64 bit).
710
# In Python 3 there will be only int (64 bit).
@@ -18,6 +21,10 @@ class PyFrame:
1821

1922
self.frameID = frameID
2023

24+
def CallJavascript(self, funcName):
25+
26+
pass
27+
2128
def ExecuteJavascript(self, jsCode, scriptURL=None, startLine=None):
2229

2330
cdef CefRefPtr[CefFrame] cefFrame = GetCefFrameByFrameID(CheckFrameID(self.frameID))

imports.pyx

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Copyright (c) 2012 CefPython Authors. All rights reserved.
2+
# License: New BSD License.
3+
# Website: http://code.google.com/p/cefpython/
4+
5+
# Imports are in a separate files so that we can "include" them easily
6+
# in other pyx files, this is required for the PyCharm so that unresolved
7+
# references and other errors are fixed.
8+
9+
import os
10+
import sys
11+
import win32con
12+
import win32gui
13+
import win32api
14+
import cython
15+
import traceback
16+
import time
17+
import types
18+
19+
from libcpp cimport bool as cbool
20+
from libcpp.map cimport map
21+
from libcpp.vector cimport vector
22+
from cython.operator cimport preincrement as preinc, dereference as deref # must be "as" otherwise not seen.
23+
# from cython.operator cimport address as addr # Address of an c++ object?
24+
from libc.stdlib cimport malloc, free
25+
26+
# When pyx file cimports * from a pxd file and that cimports * from another pxd
27+
# then these another names will be visible in pyx file.
28+
29+
# Circular imports are allowed in form "cimport ...",
30+
# but won't work if you do "from ... cimport *", this
31+
# is important to know in pxd files.
32+
33+
# <CefRefPtr[ClientHandler]?>new ClientHandler() # <...?> means to throw an error if the cast is not allowed
34+
35+
from windows cimport *
36+
from cef_string cimport *
37+
from cef_type_wrappers cimport *
38+
from cef_task cimport *
39+
from cef_win cimport *
40+
from cef_ptr cimport *
41+
from cef_app cimport *
42+
from cef_browser cimport *
43+
from cef_client cimport *
44+
from clienthandler cimport *
45+
from cef_frame cimport *
46+
cimport cef_types
47+
cimport cef_types_win

javascriptbindings.pyx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import types
1+
# Copyright (c) 2012 CefPython Authors. All rights reserved.
2+
# License: New BSD License.
3+
# Website: http://code.google.com/p/cefpython/
4+
5+
include "imports.pyx"
26

37
class JavascriptBindings:
48

0 commit comments

Comments
 (0)