Skip to content

Commit 77c506b

Browse files
committed
Fix Printing in the hello_world.py and tkinter_.py examples.
Minor fixes. Added some code for testing CEF views.
1 parent 4301258 commit 77c506b

File tree

16 files changed

+208
-29
lines changed

16 files changed

+208
-29
lines changed

docs/Migration-guide.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Table of contents:
2727
* [v50+ Build instructions and build tools](#v50-build-instructions-and-build-tools)
2828
* [v51+ Off-screen-rendering: new option "windowless_rendering_enabled"](#v51-off-screen-rendering-new-option-windowless_rendering_enabled)
2929
* [v51+ Remove LifespanHandler.RunModal](#v51-remove-lifespanhandlerrunmodal)
30-
* [v51+: BrowserSettings options removed](#v51-browsersettings-options-removed)
30+
* [v51+ BrowserSettings options removed](#v51-browsersettings-options-removed)
3131
* [v51+ cef.Request.Flags changed](#v51-cefrequestflags-changed)
3232
* [v51+ Request.GetHeaderMap and SetHeaderMap change](#v51-requestgetheadermap-and-setheadermap-change)
3333
* [v54+ GTK 3 example doesn't work anymore on Linux](#v54-gtk-3-example-doesnt-work-anymore-on-linux)
@@ -157,7 +157,7 @@ http://opensource.spotify.com/cefbuilds/index.html
157157

158158
## v50+ Build instructions and build tools
159159

160-
Many changes in regards to building CEF and CEF Python has changed.
160+
There were many changes in regards to building CEF and CEF Python.
161161
There are now new tools in the tools/ root directory that fully
162162
automate building CEF and CEF Python. CEF Python now provides
163163
upstream CEF prebuilt binaries and libraries on GitHub Releases
@@ -180,7 +180,7 @@ API ref: ApplicationSettings.[windowless_rendering_enabled](../api/ApplicationSe
180180
LifespanHandler.RunModal callback is no more available.
181181

182182

183-
## v51+: BrowserSettings options removed
183+
## v51+ BrowserSettings options removed
184184

185185
The following options were removed from BrowserSettings:
186186
- user_style_sheet_location

examples/gtk2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ def main():
4949

5050

5151
def check_versions():
52-
print("[gkt2.py] CEF Python {ver}".format(ver=cef.__version__))
53-
print("[gkt2.py] Python {ver} {arch}".format(
52+
print("[gtk2.py] CEF Python {ver}".format(ver=cef.__version__))
53+
print("[gtk2.py] Python {ver} {arch}".format(
5454
ver=platform.python_version(), arch=platform.architecture()[0]))
55-
print("[gkt2.py] GTK {ver}".format(ver='.'.join(
55+
print("[gtk2.py] GTK {ver}".format(ver='.'.join(
5656
map(str, list(gtk.gtk_version)))))
5757
assert cef.__version__ >= "55.3", "CEF Python v55.3+ required to run this"
5858
pygtk.require('2.0')
@@ -64,11 +64,11 @@ def configure_message_loop():
6464
print("[gtk2.py] Force --message-loop-cef flag on Mac")
6565
sys.argv.append("--message-loop-cef")
6666
if "--message-loop-cef" in sys.argv:
67-
print("[gkt2.py] Message loop mode: CEF (best performance)")
67+
print("[gtk2.py] Message loop mode: CEF (best performance)")
6868
g_message_loop = MESSAGE_LOOP_CEF
6969
sys.argv.remove("--message-loop-cef")
7070
else:
71-
print("[gkt2.py] Message loop mode: TIMER")
71+
print("[gtk2.py] Message loop mode: TIMER")
7272
g_message_loop = MESSAGE_LOOP_TIMER
7373

7474

src/browser.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ cdef PyBrowser GetPyBrowser(CefRefPtr[CefBrowser] cefBrowser,
4242

4343
global g_pyBrowsers
4444

45-
# This probably ain't needed, but just to be sure.
4645
if <void*>cefBrowser == NULL or not cefBrowser.get():
4746
raise Exception("{caller}: CefBrowser reference is NULL"
4847
.format(caller=callerIdStr))

src/cefpython.pyx

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ cdef extern from *:
384384
# cannot cimport *, that would cause name conflicts with constants
385385
# noinspection PyUnresolvedReferences
386386
from cef_types cimport (
387-
CefSettings, CefBrowserSettings, CefRect, CefPoint,
387+
CefSettings, CefBrowserSettings, CefRect, CefSize, CefPoint,
388388
CefKeyEvent, CefMouseEvent, CefScreenInfo,
389389
PathKey, PK_DIR_EXE, PK_DIR_MODULE,
390390
int32, uint32, int64, uint64,
@@ -433,6 +433,8 @@ from cef_path_util cimport *
433433
from cef_drag_data cimport *
434434
from cef_image cimport *
435435
from main_message_loop cimport *
436+
# noinspection PyUnresolvedReferences
437+
from cef_views cimport *
436438

437439
# -----------------------------------------------------------------------------
438440
# GLOBAL VARIABLES
@@ -775,6 +777,46 @@ def CreateBrowserSync(windowInfo=None,
775777
assert IsThread(TID_UI), (
776778
"cefpython.CreateBrowserSync() may only be called on the UI thread")
777779

780+
"""
781+
# CEF views
782+
# noinspection PyUnresolvedReferences
783+
cdef CefRefPtr[CefWindow] cef_window
784+
# noinspection PyUnresolvedReferences
785+
cdef CefRefPtr[CefBoxLayout] cef_box_layout
786+
cdef CefBoxLayoutSettings cef_box_layout_settings
787+
cdef CefRefPtr[CefPanel] cef_panel
788+
if not windowInfo and browserSettings \
789+
and "window_title" in browserSettings:
790+
# noinspection PyUnresolvedReferences
791+
cef_window = CefWindow.CreateTopLevelWindow(
792+
<CefRefPtr[CefWindowDelegate]?>NULL)
793+
Debug("CefWindow.GetChildViewCount = "
794+
+str(cef_window.get().GetChildViewCount()))
795+
796+
cef_window.get().CenterWindow(CefSize(800, 600))
797+
cef_window.get().SetBounds(CefRect(0, 0, 800, 600))
798+
# noinspection PyUnresolvedReferences
799+
#cef_box_layout = cef_window.get().SetToBoxLayout(
800+
# cef_box_layout_settings)
801+
#cef_box_layout.get().SetFlexForView(cef_window, 1)
802+
cef_window.get().SetToFillLayout()
803+
# noinspection PyUnresolvedReferences
804+
cef_panel = CefPanel.CreatePanel(<CefRefPtr[CefPanelDelegate]?>NULL)
805+
cef_window.get().AddChildView(cef_panel)
806+
cef_window.get().Layout()
807+
cef_window.get().SetVisible(True)
808+
cef_window.get().Show()
809+
cef_window.get().RequestFocus()
810+
windowInfo = WindowInfo()
811+
windowInfo.SetAsChild(cef_window.get().GetWindowHandle())
812+
Debug("CefWindow handle = "+str(cef_window.get().GetWindowHandle()))
813+
"""
814+
815+
# Only title was set in hello_world.py example
816+
if windowInfo and not windowInfo.windowType:
817+
windowInfo.SetAsChild(0)
818+
819+
# No window info provided
778820
if not windowInfo:
779821
windowInfo = WindowInfo()
780822
windowInfo.SetAsChild(0)
@@ -831,6 +873,9 @@ def CreateBrowserSync(windowInfo=None,
831873
else:
832874
Debug("CefBrowser::CreateBrowserSync() succeeded")
833875

876+
Debug("CefBrowser window handle = "
877+
+str(cefBrowser.get().GetHost().get().GetWindowHandle()))
878+
834879
# Request context - part 2/2.
835880
if g_applicationSettings["unique_request_context_per_browser"]:
836881
requestContextHandler.get().SetBrowser(cefBrowser)
@@ -842,6 +887,21 @@ def CreateBrowserSync(windowInfo=None,
842887
pyBrowser.SetUserData("__outerWindowHandle",
843888
int(windowInfo.parentWindowHandle))
844889

890+
"""
891+
if cef_window.get():
892+
cef_window.get().ReorderChildView(cef_panel, -1)
893+
cef_window.get().Layout()
894+
cef_window.get().Show()
895+
cef_window.get().RequestFocus()
896+
"""
897+
898+
if windowInfo.parentWindowHandle == 0 and windowInfo.windowType == "child":
899+
# Set window title in hello_world.py example
900+
IF UNAME_SYSNAME == "Linux":
901+
pass
902+
ELIF UNAME_SYSNAME == "Darwin":
903+
pass
904+
845905
return pyBrowser
846906

847907
def MessageLoop():

src/client_handler/dialog_handler_gtk.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
#include <libgen.h>
1212
#include <sys/stat.h>
1313
#include <X11/Xlib.h>
14+
#include <gtk/gtk.h>
1415
#include <gdk/gdkx.h>
1516

1617
#include "include/cef_browser.h"
1718
#include "include/cef_parser.h"
1819
#include "include/wrapper/cef_helpers.h"
1920

21+
#include "LOG_DEBUG.h"
22+
2023
#include "dialog_handler_gtk.h"
2124
#include "x11.h"
2225

@@ -156,6 +159,7 @@ GtkWindow* GetWindow(CefRefPtr<CefBrowser> browser) {
156159
// internally, so GTK wasn't yet initialized and must do it
157160
// now, so that display is available. Also must install X11
158161
// error handlers to avoid 'BadWindow' errors.
162+
LOG_DEBUG << "Initialize GTK";
159163
gtk_init(0, NULL);
160164
InstallX11ErrorHandlers();
161165
// Now the display is available

src/common/cefpython_public_api.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
#ifndef CEFPYTHON_PUBLIC_API_H
1010
#define CEFPYTHON_PUBLIC_API_H
1111

12+
// Includes required by "cefpython_fixed.h".
13+
#include "include/cef_client.h"
14+
#include "include/cef_urlrequest.h"
15+
#include "include/cef_command_line.h"
16+
#include "util.h"
17+
1218
#if defined(OS_WIN)
1319
#pragma warning(disable:4190) // cefpython API extern C-linkage warnings
1420
#endif
@@ -24,12 +30,6 @@
2430
#define DL_EXPORT(RTYPE) RTYPE
2531
#endif
2632

27-
// Includes required by "cefpython_fixed.h".
28-
#include "include/cef_client.h"
29-
#include "include/cef_urlrequest.h"
30-
#include "include/cef_command_line.h"
31-
#include "util.h"
32-
3333
#if PY_MAJOR_VERSION == 2
3434
#if PY_MINOR_VERSION == 7
3535
#include "../../build/build_cefpython/cefpython_py27_fixed.h"

src/compile_time_constants.pxi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# This file was generated by setup.py
2-
DEF UNAME_SYSNAME = "Darwin"
3-
DEF PY_MAJOR_VERSION = 3
2+
DEF UNAME_SYSNAME = "Linux"
3+
DEF PY_MAJOR_VERSION = 2

src/extern/cef/cef_types.pxd

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,13 @@ from libc.limits cimport UINT_MAX
1515

1616
cdef extern from "include/internal/cef_types.h":
1717

18+
# noinspection PyUnresolvedReferences
1819
ctypedef int32_t int32
20+
# noinspection PyUnresolvedReferences
1921
ctypedef uint32_t uint32
22+
# noinspection PyUnresolvedReferences
2023
ctypedef int64_t int64
24+
# noinspection PyUnresolvedReferences
2125
ctypedef uint64_t uint64
2226

2327
IF UNAME_SYSNAME == "Windows":
@@ -97,6 +101,11 @@ cdef extern from "include/internal/cef_types.h":
97101
CefRect()
98102
CefRect(int x, int y, int width, int height)
99103

104+
cdef cppclass CefSize:
105+
int width, height
106+
CefSize()
107+
CefSize(int width, int height)
108+
100109
cdef cppclass CefPoint:
101110
pass
102111

src/extern/cef/cef_views.pxd

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Copyright (c) 2017 CEF Python, see the Authors file.
2+
# All rights reserved. Licensed under BSD 3-clause license.
3+
# Project website: https://github.com/cztomczak/cefpython
4+
5+
from cef_ptr cimport CefRefPtr
6+
from cef_browser cimport CefWindowHandle
7+
from cef_types cimport CefRect, CefSize
8+
from libcpp cimport bool as cpp_bool
9+
10+
11+
cdef extern from "include/internal/cef_types.h":
12+
ctypedef struct cef_insets_t:
13+
int top;
14+
int left;
15+
int bottom;
16+
int right;
17+
18+
ctypedef enum cef_main_axis_alignment_t:
19+
CEF_MAIN_AXIS_ALIGNMENT_START,
20+
CEF_MAIN_AXIS_ALIGNMENT_CENTER,
21+
CEF_MAIN_AXIS_ALIGNMENT_END,
22+
23+
ctypedef enum cef_cross_axis_alignment_t:
24+
CEF_CROSS_AXIS_ALIGNMENT_STRETCH,
25+
CEF_CROSS_AXIS_ALIGNMENT_START,
26+
CEF_CROSS_AXIS_ALIGNMENT_CENTER,
27+
CEF_CROSS_AXIS_ALIGNMENT_END,
28+
29+
ctypedef struct CefBoxLayoutSettings:
30+
int horizontal;
31+
int inside_border_horizontal_spacing;
32+
int inside_border_vertical_spacing;
33+
cef_insets_t inside_border_insets;
34+
int between_child_spacing;
35+
cef_main_axis_alignment_t main_axis_alignment;
36+
cef_cross_axis_alignment_t cross_axis_alignment;
37+
int minimum_cross_axis_size;
38+
int default_flex;
39+
40+
cdef extern from "include/views/cef_box_layout.h":
41+
cdef cppclass CefBoxLayout:
42+
void SetFlexForView(CefRefPtr[CefWindow] view, int flex)
43+
44+
cdef extern from "include/views/cef_window_delegate.h":
45+
cdef cppclass CefWindowDelegate:
46+
pass
47+
48+
cdef extern from "include/views/cef_view.h":
49+
cdef cppclass CefView:
50+
pass
51+
52+
cdef extern from "include/views/cef_panel_delegate.h":
53+
cdef cppclass CefPanelDelegate:
54+
pass
55+
56+
cdef extern from "include/views/cef_panel.h":
57+
cdef cppclass CefPanel:
58+
@staticmethod
59+
CefRefPtr[CefPanel] CreatePanel(CefRefPtr[CefPanelDelegate] delegate)
60+
61+
62+
cdef extern from "include/views/cef_fill_layout.h":
63+
cdef cppclass CefFillLayout:
64+
pass
65+
66+
cdef extern from "include/views/cef_window.h":
67+
cdef cppclass CefWindow:
68+
@staticmethod
69+
CefRefPtr[CefWindow] CreateTopLevelWindow(
70+
CefRefPtr[CefWindowDelegate] delegate)
71+
void Show()
72+
CefWindowHandle GetWindowHandle()
73+
void SetBounds(const CefRect& bounds)
74+
void CenterWindow(const CefSize& size)
75+
void SetVisible(cpp_bool visible)
76+
void Layout()
77+
CefRefPtr[CefFillLayout] SetToFillLayout()
78+
CefRefPtr[CefBoxLayout] SetToBoxLayout(
79+
const CefBoxLayoutSettings& settings)
80+
void RequestFocus()
81+
void RemoveAllChildViews()
82+
size_t GetChildViewCount()
83+
void AddChildView(CefRefPtr[CefPanel] view)
84+
void ReorderChildView(CefRefPtr[CefPanel] view, int index)

src/frame.pyx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ cdef PyFrame GetPyFrameById(int browserId, object frameId):
1919
cdef PyFrame GetPyFrame(CefRefPtr[CefFrame] cefFrame):
2020
global g_pyFrames
2121

22-
# This code probably ain't needed, but just to be sure.
2322
if <void*>cefFrame == NULL or not cefFrame.get():
2423
raise Exception("GetPyFrame(): CefFrame reference is NULL")
2524

0 commit comments

Comments
 (0)