Skip to content

Commit 8e36e82

Browse files
hoba87cztomczak
andauthored
update kivy example (cztomczak#573)
* update old print syntax * remove pygtk, gtk dependencies * restore kivy pygtk dependency for linux, add platform dependent conditional statements * kivy example macos keyboard working * external pump message only for macos * Update kivy_.py Co-authored-by: Czarek Tomczak <cztomczak@users.noreply.github.com>
1 parent 686d528 commit 8e36e82

File tree

1 file changed

+30
-16
lines changed

1 file changed

+30
-16
lines changed

src/linux/binaries_64bit/kivy_.py

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@
88

99
from cefpython3 import cefpython as cef
1010

11-
import pygtk
12-
import gtk
1311
import sys
1412
import os
1513
import time
14+
if sys.platform == 'linux':
15+
import pygtk
16+
import gtk
17+
pygtk.require('2.0')
18+
elif sys.platform == 'darwin':
19+
import gi
20+
gi.require_version("Gtk", "3.0")
21+
from gi.repository import Gtk
22+
elif sys.platform == 'win32':
23+
# no gtk needed on Windows
24+
pass
1625

1726
from kivy.app import App
1827
from kivy.uix.button import Button
@@ -28,9 +37,6 @@
2837
# Global variables
2938
g_switches = None
3039

31-
# PyGTK required
32-
pygtk.require('2.0')
33-
3440

3541
class BrowserLayout(BoxLayout):
3642

@@ -150,9 +156,6 @@ def start_cef(self):
150156

151157
# Configure CEF
152158
settings = {
153-
# This directories must be set on Linux
154-
"locales_dir_path": cef.GetModuleDirectory()+"/locales",
155-
"resources_dir_path": cef.GetModuleDirectory(),
156159
"browser_subprocess_path": "%s/%s" % (
157160
cef.GetModuleDirectory(), "subprocess"),
158161
"windowless_rendering_enabled": True,
@@ -161,7 +164,15 @@ def start_cef(self):
161164
"enabled": False,
162165
},
163166
"external_message_pump": False, # See Issue #246
167+
"multi_threaded_message_loop": False,
164168
}
169+
if sys.platform == 'linux':
170+
# This directories must be set on Linux
171+
settings["locales_dir_path"] = cef.GetModuleDirectory() + "/locales"
172+
settings["resources_dir_path"] = cef.GetModuleDirectory()
173+
if sys.platform == 'darwin':
174+
settings["external_message_pump"] = True # Temporary fix for Issue #246
175+
165176
switches = {
166177
# Tweaking OSR performance by setting the same Chromium flags
167178
# as in upstream cefclient (# Issue #240).
@@ -190,18 +201,21 @@ def start_cef(self):
190201
# Start idle - CEF message loop work.
191202
Clock.schedule_once(self._message_loop_work, 0)
192203

204+
windowInfo = cef.WindowInfo()
205+
193206
# TODO: For printing to work in off-screen-rendering mode
194207
# it is enough to call gtk_init(). It is not required
195208
# to provide window handle when calling SetAsOffscreen().
196209
# However it still needs to be tested whether providing
197210
# window handle is required for mouse context menu and
198211
# popup widgets to work.
199-
gtkwin = gtk.Window()
200-
gtkwin.realize()
201-
202212
# WindowInfo offscreen flag
203-
windowInfo = cef.WindowInfo()
204-
windowInfo.SetAsOffscreen(gtkwin.window.xid)
213+
if sys.platform == 'linux':
214+
gtkwin = gtk.Window()
215+
gtkwin.realize()
216+
windowInfo.SetAsOffscreen(gtkwin.window.xid)
217+
elif sys.platform == 'darwin' or sys.platform == 'win32':
218+
windowInfo.SetAsOffscreen(0)
205219

206220
# Create Broswer and naviagte to empty page <= OnPaint won't get
207221
# called yet
@@ -519,12 +533,12 @@ def get_windows_key_code(self, kivycode):
519533

520534
def go_forward(self, *_):
521535
"""Going to forward in browser history."""
522-
print "go forward"
536+
print("go forward")
523537
self.browser.GoForward()
524538

525539
def go_back(self, *_):
526540
"""Going back in browser history."""
527-
print "go back"
541+
print("go back")
528542
self.browser.GoBack()
529543

530544
def reload(self, *_):
@@ -864,7 +878,7 @@ def OnLoadingStateChange(self, is_loading, **_):
864878
def OnPaint(self, element_type, paint_buffer, **_):
865879
# print "OnPaint()"
866880
if element_type != cef.PET_VIEW:
867-
print "Popups aren't implemented yet"
881+
print("Popups aren't implemented yet")
868882
return
869883

870884
# FPS meter ("fps" arg)

0 commit comments

Comments
 (0)