-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbrowser.py
85 lines (62 loc) · 2 KB
/
browser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import sys
import ctypes
import platform
import tkinter as tk
from cefpython3 import cefpython as cef
import time
# platforms
WINDOWS = 'Windows'
browser_settings = {
"javascript": True,
}
settings = {
}
'''
if MAC:
settings["external_message_pump"] = True
'''
cef.Initialize(settings=settings)
app_url="https://www.google.com"
class BrowserFrame(tk.Frame):
global app_url
def __init__(self,url="https://www.google.com",master=None, **kw):
super().__init__(master,**kw)
self.app_url = url
self.browser = None
self.bind('<Configure>', self.on_configure)
def get_window_handle(self):
'''
if MAC:
from AppKit import NSApp
import objc
return objc.pyobjc_id(NSApp.windows()[-1].contentView())
'''
if self.winfo_id() > 0:
return self.winfo_id()
else:
raise Exception('Could not obtain window handle!')
def on_configure(self, event):
#global cef_winfo
global cef_winfo
if self.browser is None:
# create the browser and embed it in current frame
rect = [0, 0, self.winfo_width(), self.winfo_height()]
cef_winfo = cef.WindowInfo()
win_id = self.get_window_handle()
cef_winfo.SetAsChild(win_id, rect)
#print("win info is: "+ str(cef_winfo))
self.browser = cef.CreateBrowserSync(cef_winfo, url=self.app_url)
# start the browser handling loop
self.cef_loop()
# resize the browser
if WINDOWS:
ctypes.windll.user32.SetWindowPos(
self.browser.GetWindowHandle(), 0,
0, 0, event.width, event.height, 0x0002)
'''
elif LINUX:
self.browser.SetBounds(0, 0, event.width, event.height)
'''
def cef_loop(self):
cef.MessageLoopWork()
self.after(10, self.cef_loop)