Skip to content

Commit a0fec9a

Browse files
committed
Updated Panda3D example.
Changes in API: cefpython.IsCurrentThread() renamed to IsThread().
1 parent e55aedb commit a0fec9a

File tree

8 files changed

+32
-22
lines changed

8 files changed

+32
-22
lines changed

cefpython/browser.pyx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -257,19 +257,19 @@ cdef class PyBrowser:
257257
bool(forward), bool(matchCase), bool(findNext))
258258

259259
cpdef PyFrame GetFocusedFrame(self):
260-
assert IsCurrentThread(TID_UI), (
260+
assert IsThread(TID_UI), (
261261
"Browser.GetFocusedFrame() may only be called on UI thread")
262262
return GetPyFrame(self.GetCefBrowser().get().GetFocusedFrame())
263263

264264
cpdef PyFrame GetFrame(self, py_string name):
265-
assert IsCurrentThread(TID_UI), (
265+
assert IsThread(TID_UI), (
266266
"Browser.GetFrame() may only be called on the UI thread")
267267
cdef CefString cefName
268268
PyToCefString(name, cefName)
269269
return GetPyFrame(self.GetCefBrowser().get().GetFrame(cefName))
270270

271271
cpdef list GetFrameNames(self):
272-
assert IsCurrentThread(TID_UI), (
272+
assert IsThread(TID_UI), (
273273
"Browser.GetFrameNames() may only be called on the UI thread")
274274
cdef cpp_vector[CefString] cefNames
275275
self.GetCefBrowser().get().GetFrameNames(cefNames)
@@ -317,7 +317,7 @@ cdef class PyBrowser:
317317

318318
cpdef double GetZoomLevel(self) except *:
319319
IF CEF_VERSION == 1:
320-
assert IsCurrentThread(TID_UI), (
320+
assert IsThread(TID_UI), (
321321
"Browser.GetZoomLevel() may only be called on UI thread")
322322
cdef double zoomLevel
323323
IF CEF_VERSION == 1:
@@ -349,7 +349,7 @@ cdef class PyBrowser:
349349
IF CEF_VERSION == 1:
350350

351351
cpdef py_bool IsPopupVisible(self):
352-
assert IsCurrentThread(TID_UI), (
352+
assert IsThread(TID_UI), (
353353
"Browser.IsPopupVisible() may only be called on UI thread")
354354
return self.GetCefBrowser().get().IsPopupVisible()
355355

@@ -471,7 +471,7 @@ cdef class PyBrowser:
471471
IF CEF_VERSION == 1:
472472

473473
cpdef tuple GetSize(self, PaintElementType paintElementType):
474-
assert IsCurrentThread(TID_UI), (
474+
assert IsThread(TID_UI), (
475475
"Browser.GetSize(): this method should only be called "
476476
"on the UI thread")
477477
cdef int width = 0
@@ -496,7 +496,7 @@ cdef class PyBrowser:
496496

497497
cpdef PaintBuffer GetImage(self, PaintElementType paintElementType,
498498
int width, int height):
499-
assert IsCurrentThread(TID_UI), (
499+
assert IsThread(TID_UI), (
500500
"Browser.GetImage(): this method should only be called "
501501
"on the UI thread")
502502

cefpython/cef1/windows/binaries/panda3d_.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
# This will enable your copy of python to find the panda libraries.
1616

1717
# TODO: fix the blurriness of the browser when window is resized.
18+
# TODO: add keyboard handlers.
1819

1920
import platform
2021
if platform.architecture()[0] != "32bit":
@@ -40,6 +41,8 @@
4041
class World(DirectObject):
4142
browser = None
4243
texture = None
44+
nodePath = None
45+
lastMouseMove = (-1, -1)
4346

4447
def __init__(self):
4548
wp = WindowProperties()
@@ -56,12 +59,10 @@ def __init__(self):
5659
self.texture.setCompression(Texture.CMOff)
5760
self.texture.setComponentType(Texture.TUnsignedByte)
5861
self.texture.setFormat(Texture.FRgba4)
59-
self.texture.setTexturesPower2(0)
60-
self.texture.setAutoTextureScale(0)
6162

62-
self.cardMaker = CardMaker("browser2d")
63-
self.cardMaker.setFrame(-0.75, 0.75, -0.75, 0.75)
64-
node = self.cardMaker.generate()
63+
cardMaker = CardMaker("browser2d")
64+
cardMaker.setFrame(-0.75, 0.75, -0.75, 0.75)
65+
node = cardMaker.generate()
6566
self.nodePath = render2d.attachNewNode(node)
6667
self.nodePath.setTexture(self.texture)
6768
self.nodePath.setHpr(0, 0, 5)
@@ -70,6 +71,8 @@ def __init__(self):
7071
windowInfo = cefpython.WindowInfo()
7172
windowInfo.SetAsOffscreen(windowHandle)
7273

74+
# By default window rendering is 30 fps,
75+
# let's change it to 60 for better user experience.
7376
browserSettings = {"animation_frame_rate": 60}
7477

7578
self.browser = cefpython.CreateBrowserSync(
@@ -137,6 +140,13 @@ def getMousePixelCoordinates(self, mouse):
137140
def onMouseMove(self, task):
138141
if base.mouseWatcherNode.hasMouse():
139142
mouse = base.mouseWatcherNode.getMouse()
143+
144+
(lastX, lastY) = self.lastMouseMove
145+
if lastX == mouse.getX() and lastY == mouse.getY():
146+
return Task.cont
147+
else:
148+
self.lastMouseMove = (mouse.getX(), mouse.getY())
149+
140150
if self.isMouseInsideBrowser(mouse):
141151
self.nodePath.setHpr(0, 0, 0)
142152
(x,y) = self.getMousePixelCoordinates(mouse)

cefpython/cefpython.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def Initialize(applicationSettings=None):
120120

121121
def CreateBrowserSync(windowInfo, browserSettings, navigateURL):
122122
Debug("CreateBrowserSync() called")
123-
assert IsCurrentThread(TID_UI), (
123+
assert IsThread(TID_UI), (
124124
"cefpython.CreateBrowserSync() can only be called on UI thread")
125125

126126
if not isinstance(windowInfo, WindowInfo):

cefpython/frame.pyx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ cdef class PyFrame:
101101
IF CEF_VERSION == 1:
102102

103103
cpdef object GetProperty(self, py_string name):
104-
assert IsCurrentThread(TID_UI), (
104+
assert IsThread(TID_UI), (
105105
"Frame.GetProperty() may only be called on the UI thread")
106106

107107
cdef CefRefPtr[CefV8Context] v8Context = self.GetCefFrame().get().GetV8Context()
@@ -117,13 +117,13 @@ cdef class PyFrame:
117117

118118
cpdef str GetSource(self):
119119
IF CEF_VERSION == 1:
120-
assert IsCurrentThread(TID_UI), (
120+
assert IsThread(TID_UI), (
121121
"Frame.GetSource() may only be called on the UI thread")
122122
return CefToPyString(self.GetCefFrame().get().GetSource())
123123

124124
cpdef str GetText(self):
125125
IF CEF_VERSION == 1:
126-
assert IsCurrentThread(TID_UI), (
126+
assert IsThread(TID_UI), (
127127
"Frame.GetText() may only be called on the UI thread")
128128
return CefToPyString(self.GetCefFrame().get().GetText())
129129

@@ -132,7 +132,7 @@ cdef class PyFrame:
132132

133133
cpdef py_bool IsFocused(self):
134134
IF CEF_VERSION == 1:
135-
assert IsCurrentThread(TID_UI), (
135+
assert IsThread(TID_UI), (
136136
"Frame.IsFocused() may only be called on the UI thread")
137137
return self.GetCefFrame().get().IsFocused()
138138

@@ -170,7 +170,7 @@ cdef class PyFrame:
170170
IF CEF_VERSION == 1:
171171

172172
cpdef py_void SetProperty(self, py_string name, object value):
173-
assert IsCurrentThread(TID_UI), (
173+
assert IsThread(TID_UI), (
174174
"Frame.SetProperty() may only be called on the UI thread")
175175

176176
if not JavascriptBindings.IsValueAllowed(value):

cefpython/javascript_bindings.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ cdef class JavascriptBindings:
8787
del self.frames[pyFrame.GetIdentifier()]
8888

8989
cpdef py_void Rebind(self):
90-
assert IsCurrentThread(TID_UI), (
90+
assert IsThread(TID_UI), (
9191
"JavascriptBindings.Rebind() may only be called on UI thread")
9292

9393
cdef CefRefPtr[CefBrowser] cefBrowser

cefpython/utils.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ TID_UI = cef_types.TID_UI
66
TID_IO = cef_types.TID_IO
77
TID_FILE = cef_types.TID_FILE
88

9-
cpdef py_bool IsCurrentThread(int threadID):
9+
cpdef py_bool IsThread(int threadID):
1010
return bool(CefCurrentlyOn(<CefThreadId>threadID))
1111

1212
cpdef object Debug(str msg):

cefpython/v8utils.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ IF CEF_VERSION == 1:
3636
return pyTrace
3737

3838
cpdef list GetJavascriptStackTrace(int frameLimit=100):
39-
assert IsCurrentThread(TID_UI), (
39+
assert IsThread(TID_UI), (
4040
"cefpython.GetJavascriptStackTrace() may only be called on the UI thread")
4141
cdef CefRefPtr[CefV8StackTrace] cefTrace = (
4242
cef_v8_stack_trace.GetCurrent(frameLimit))

cefpython/var/SaveImage.pyx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
cpdef py_bool SaveImage(self, py_string filePath,
66
str imageType="bitmap"):
7-
assert IsCurrentThread(TID_UI), (
7+
assert IsThread(TID_UI), (
88
"Browser.SaveImage(): this method should only be called "
99
"on the UI thread")
1010

0 commit comments

Comments
 (0)