Skip to content

Commit 21014a8

Browse files
committed
Update kivy_.py: fix printing, add buttons Print etc, disable context menu
1 parent 3dbcfda commit 21014a8

File tree

1 file changed

+54
-4
lines changed

1 file changed

+54
-4
lines changed

src/linux/binaries_64bit/kivy_.py

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
# Import from package
3434
from cefpython3 import cefpython
3535

36+
import pygtk
37+
pygtk.require('2.0')
38+
import gtk
39+
3640
from kivy.app import App
3741
from kivy.uix.widget import Widget
3842
from kivy.graphics import Color, Rectangle, GraphicException
@@ -50,13 +54,22 @@
5054
orientation: 'vertical'
5155
BoxLayout:
5256
size_hint_y: None
53-
width: 80
57+
height: 40
5458
Button:
5559
text: "Back"
5660
on_press: browser.go_back()
5761
Button:
5862
text: "Forward"
5963
on_press: browser.go_forward()
64+
Button:
65+
text: "Reload"
66+
on_press: browser.reload()
67+
Button:
68+
text: "Print"
69+
on_press: browser.print_page()
70+
Button:
71+
text: "DevTools"
72+
on_press: browser.devtools()
6073
CefBrowser:
6174
id: browser
6275
@@ -150,6 +163,10 @@ def start_cef(self):
150163
"browser_subprocess_path": "%s/%s" % (
151164
cefpython.GetModuleDirectory(), "subprocess"),
152165
"windowless_rendering_enabled": True,
166+
"context_menu": {
167+
# Disable context menu, popup widgets not supported
168+
"enabled": False,
169+
},
153170
}
154171

155172
#start idle
@@ -159,9 +176,15 @@ def start_cef(self):
159176
cefpython.WindowUtils.InstallX11ErrorHandlers()
160177
cefpython.Initialize(settings)
161178

179+
# CEF needs a valid window handle passed to SetAsOffscreen()
180+
# for Printing to work. There is no API to get Kivy's window
181+
# handle so creating a dummy hidden Window using GTK.
182+
gtkwin = gtk.Window()
183+
gtkwin.realize()
184+
162185
#WindowInfo offscreen flag
163186
windowInfo = cefpython.WindowInfo()
164-
windowInfo.SetAsOffscreen(0)
187+
windowInfo.SetAsOffscreen(gtkwin.window.xid)
165188

166189
#Create Broswer and naviagte to empty page <= OnPaint won't get called yet
167190
browserSettings = {}
@@ -483,14 +506,41 @@ def go_back(self):
483506
self.browser.GoBack()
484507

485508

509+
def reload(self):
510+
self.browser.Reload()
511+
512+
513+
def print_page(self):
514+
self.browser.Print()
515+
516+
517+
def devtools(self):
518+
self.browser.ShowDevTools()
519+
520+
486521
def on_touch_down(self, touch, *kwargs):
487522
if not self.collide_point(*touch.pos):
488523
return
489524
touch.grab(self)
490525

491526
y = self.height-touch.pos[1]
492-
self.browser.SendMouseClickEvent(touch.x, y, cefpython.MOUSEBUTTON_LEFT,
493-
mouseUp=False, clickCount=1)
527+
if touch.is_double_tap:
528+
# is_double_tap seems not to work in Kivy 1.7.
529+
# Context menu is currently disabled see
530+
# settings["context_menu"] in cef_start().
531+
self.browser.SendMouseClickEvent(
532+
touch.x, y, cefpython.MOUSEBUTTON_RIGHT,
533+
mouseUp=False, clickCount=1
534+
)
535+
self.browser.SendMouseClickEvent(
536+
touch.x, y, cefpython.MOUSEBUTTON_RIGHT,
537+
mouseUp=True, clickCount=1
538+
)
539+
else:
540+
self.browser.SendMouseClickEvent(touch.x, y,
541+
cefpython.MOUSEBUTTON_LEFT,
542+
mouseUp=False, clickCount=1)
543+
494544

495545

496546
def on_touch_move(self, touch, *kwargs):

0 commit comments

Comments
 (0)