Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"disable-gpu": "",
"disable-gpu-compositing": "",
"enable-begin-frame-scheduling": "",
}
browserSettings = {
# Tweaking OSR performance (Issue #240)
"windowless_frame_rate": 60
}
# Initialize CEF
# To shutdown all CEF processes on error
sys.excepthook = cef.ExceptHook
# noinspection PyArgumentList
cef.WindowUtils.InstallX11ErrorHandlers()
global g_switches
g_switches = switches
cef.Initialize(settings, switches)
# Start idle - CEF message loop work.
Clock.schedule_once(self._message_loop_work, 0)
# 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()
def moveEvent(self, event):
cefpython.WindowUtils.OnSize(int(self.winId()), 0, 0, 0)
def OnFocusIn(self, widget, data):
# This function is currently not called by any of code, but if you would like
# for browser to have automatic focus add such line:
# self.mainWindow.connect('focus-in-event', self.OnFocusIn)
cefpython.WindowUtils.OnSetFocus(self.container.get_window().handle, 0, 0, 0)
if DEBUG:
# cefpython debug messages in console and in log_file
appSettings["debug"] = True
cefwindow.g_debug = True
appSettings["log_file"] = GetApplicationPath("debug.log")
appSettings["log_severity"] = cefpython.LOGSEVERITY_INFO
appSettings["release_dcheck_enabled"] = True # Enable only when debugging
appSettings["browser_subprocess_path"] = "%s/%s" % (
cefpython.GetModuleDirectory(), "subprocess")
cefpython.Initialize(appSettings)
wndproc = {
win32con.WM_CLOSE: CloseWindow,
win32con.WM_DESTROY: QuitApplication,
win32con.WM_SIZE: cefpython.WindowUtils.OnSize,
win32con.WM_SETFOCUS: cefpython.WindowUtils.OnSetFocus,
win32con.WM_ERASEBKGND: cefpython.WindowUtils.OnEraseBackground
}
browserSettings = dict()
browserSettings["universal_access_from_file_urls_allowed"] = True
browserSettings["file_access_from_file_urls_allowed"] = True
if os.path.exists("icon.ico"):
icon = os.path.abspath("icon.ico")
else:
icon = ""
windowHandle = cefwindow.CreateWindow(title="pywin32 example",
className="cefpython3_example", width=1024, height=768,
icon=icon, windowProc=wndproc)
windowInfo = cefpython.WindowInfo()
def OnSetFocus(self, _):
if not self.browser:
return
if WINDOWS:
cef.WindowUtils.OnSetFocus(self.browser_panel.GetHandle(),
0, 0, 0)
self.browser.SetFocus(True)
# Example of embedding CEF browser using PyGTK library (GTK 2).
# Tested configurations:
# - GTK 2.24 on Windows/Linux/Mac
# - CEF Python v55.3+
from cefpython3 import cefpython as cef
import pygtk
import gtk
import gobject
import os
import platform
import sys
# Fix for PyCharm hints warnings when using static methods
WindowUtils = cef.WindowUtils()
# Platforms
WINDOWS = (platform.system() == "Windows")
LINUX = (platform.system() == "Linux")
MAC = (platform.system() == "Darwin")
# In CEF you can run message loop in two ways (see API ref for more details):
# 1. By calling cef.MessageLoopWork() in a timer - each call performs
# a single iteration of CEF message loop processing.
# 2. By calling cef.MessageLoop() instead of an application-provided
# message loop to get the best balance between performance and CPU
# usage. This function will block until a quit message is received by
# the system. This seem to work only on Linux in GTK example.
# NOTE: On Mac message loop timer doesn't work, so using CEF message
# loop by default.
MESSAGE_LOOP_TIMER = 1
def OnTitleChange(self, browser, title):
try:
cef.WindowUtils.SetTitle(browser, title)
except AttributeError:
print(
"**WARNING** : title changed '%s' not work on linux" % title
)
import time
import win32api
import win32con
import win32gui
import win32com.client
from alyvix.tools.screen import ScreenManager
from multiprocessing import Process
import urllib.request
import threading
# Globals
#cef.DpiAware.EnableHighDpiSupport()
WindowUtils = cef.WindowUtils()
g_multi_threaded = False
def set_foreground(window_handle):
#time.sleep(1)
"""
shell = win32com.client.Dispatch('WScript.Shell')
shell.Run(
"python.exe -c \"import win32gui; win32gui.SetForegroundWindow(" + str(window_handle) + "); win32gui.SetFocus(" + str(window_handle) + ")\"", 1, 1)
"""
if win32gui.IsIconic(window_handle) != 0: # restore first
win32gui.ShowWindow(window_handle, win32con.SW_RESTORE)