Skip to content

Commit

Permalink
update kivy example (#573)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
hoba87 and cztomczak authored Feb 14, 2021
1 parent 686d528 commit 8e36e82
Showing 1 changed file with 30 additions and 16 deletions.
46 changes: 30 additions & 16 deletions src/linux/binaries_64bit/kivy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@

from cefpython3 import cefpython as cef

import pygtk
import gtk
import sys
import os
import time
if sys.platform == 'linux':
import pygtk
import gtk
pygtk.require('2.0')
elif sys.platform == 'darwin':
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
elif sys.platform == 'win32':
# no gtk needed on Windows
pass

from kivy.app import App
from kivy.uix.button import Button
Expand All @@ -28,9 +37,6 @@
# Global variables
g_switches = None

# PyGTK required
pygtk.require('2.0')


class BrowserLayout(BoxLayout):

Expand Down Expand Up @@ -150,9 +156,6 @@ def start_cef(self):

# Configure CEF
settings = {
# This directories must be set on Linux
"locales_dir_path": cef.GetModuleDirectory()+"/locales",
"resources_dir_path": cef.GetModuleDirectory(),
"browser_subprocess_path": "%s/%s" % (
cef.GetModuleDirectory(), "subprocess"),
"windowless_rendering_enabled": True,
Expand All @@ -161,7 +164,15 @@ def start_cef(self):
"enabled": False,
},
"external_message_pump": False, # See Issue #246
"multi_threaded_message_loop": False,
}
if sys.platform == 'linux':
# This directories must be set on Linux
settings["locales_dir_path"] = cef.GetModuleDirectory() + "/locales"
settings["resources_dir_path"] = cef.GetModuleDirectory()
if sys.platform == 'darwin':
settings["external_message_pump"] = True # Temporary fix for Issue #246

switches = {
# Tweaking OSR performance by setting the same Chromium flags
# as in upstream cefclient (# Issue #240).
Expand Down Expand Up @@ -190,18 +201,21 @@ def start_cef(self):
# Start idle - CEF message loop work.
Clock.schedule_once(self._message_loop_work, 0)

windowInfo = cef.WindowInfo()

# TODO: For printing to work in off-screen-rendering mode
# it is enough to call gtk_init(). It is not required
# to provide window handle when calling SetAsOffscreen().
# However it still needs to be tested whether providing
# window handle is required for mouse context menu and
# popup widgets to work.
gtkwin = gtk.Window()
gtkwin.realize()

# WindowInfo offscreen flag
windowInfo = cef.WindowInfo()
windowInfo.SetAsOffscreen(gtkwin.window.xid)
if sys.platform == 'linux':
gtkwin = gtk.Window()
gtkwin.realize()
windowInfo.SetAsOffscreen(gtkwin.window.xid)
elif sys.platform == 'darwin' or sys.platform == 'win32':
windowInfo.SetAsOffscreen(0)

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

def go_forward(self, *_):
"""Going to forward in browser history."""
print "go forward"
print("go forward")
self.browser.GoForward()

def go_back(self, *_):
"""Going back in browser history."""
print "go back"
print("go back")
self.browser.GoBack()

def reload(self, *_):
Expand Down Expand Up @@ -864,7 +878,7 @@ def OnLoadingStateChange(self, is_loading, **_):
def OnPaint(self, element_type, paint_buffer, **_):
# print "OnPaint()"
if element_type != cef.PET_VIEW:
print "Popups aren't implemented yet"
print("Popups aren't implemented yet")
return

# FPS meter ("fps" arg)
Expand Down

0 comments on commit 8e36e82

Please sign in to comment.