| 1 |
import json |
| 2 |
import logging |
| 3 |
import os |
| 4 |
import pathlib |
| 5 |
import sys |
| 6 |
import webbrowser |
| 7 |
from threading import Semaphore, Thread, main_thread |
| 8 |
from typing import Any |
| 9 |
from uuid import uuid1 |
| 10 |
|
| 11 |
from webview import FileDialog, _state, settings, windows |
| 12 |
from webview.dom import _dnd_state |
| 13 |
from webview.menu import Menu, MenuAction, MenuSeparator |
| 14 |
from webview.models import Request, Response |
| 15 |
from webview.screen import Screen |
| 16 |
from webview.util import ( |
| 17 |
DEFAULT_HTML, |
| 18 |
create_cookie, |
| 19 |
inject_pywebview, |
| 20 |
js_bridge_call, |
| 21 |
parse_file_type, |
| 22 |
) |
| 23 |
from webview.window import FixPoint, Window |
| 24 |
|
| 25 |
logger = logging.getLogger('pywebview') |
| 26 |
os.environ['EGL_LOG_LEVEL'] = 'fatal' |
| 27 |
|
| 28 |
import gi # noqa: E402 |
| 29 |
|
| 30 |
gi.require_version('Gtk', '3.0') |
| 31 |
gi.require_version('Gdk', '3.0') |
| 32 |
|
| 33 |
try: |
| 34 |
gi.require_version('WebKit2', '4.1') |
| 35 |
gi.require_version('Soup', '3.0') |
| 36 |
except ValueError: |
| 37 |
logger.debug('WebKit2 4.1 not found. Using 4.0.') |
| 38 |
gi.require_version('WebKit2', '4.0') |
| 39 |
gi.require_version('Soup', '2.4') |
| 40 |
|
| 41 |
from gi.repository import Gdk, Gio # noqa: E402 |
| 42 |
from gi.repository import GLib as glib # noqa: E402 |
| 43 |
from gi.repository import Gtk as gtk # noqa: E402 |
| 44 |
from gi.repository import WebKit2 as webkit # noqa: E402 |
| 45 |
|
| 46 |
renderer = 'gtkwebkit2' |
| 47 |
webkit_ver = webkit.get_major_version(), webkit.get_minor_version(), webkit.get_micro_version() |
| 48 |
|
| 49 |
_app = None |
| 50 |
_app_actions = {} # action_label: function |
| 51 |
|
| 52 |
cert = None |
| 53 |
|
| 54 |
|
| 55 |
class BrowserView: |
| 56 |
instances = {} |
| 57 |
|
| 58 |
class JSBridge: |
| 59 |
def __init__(self, window: Window) -> None: |
| 60 |
self.window = window |
| 61 |
self.uid = uuid1().hex[:8] |
| 62 |
|
| 63 |
def call(self, func_name: str, param: Any, value_id: str): |
| 64 |
if param == 'undefined': |
| 65 |
param = None |
| 66 |
return js_bridge_call(self.window, func_name, param, value_id) |
| 67 |
|
| 68 |
def __init__(self, window: Window) -> None: |
| 69 |
# Note: _app won't be None because BrowserView() is called after _app is made in `create_window` |
| 70 |
global _app |
| 71 |
|
| 72 |
BrowserView.instances[window.uid] = self |
| 73 |
self.uid = window.uid |
| 74 |
self.pywebview_window = window |
| 75 |
|
| 76 |
self.is_fullscreen = False |
| 77 |
self.js_results = {} |
| 78 |
|
| 79 |
self.window = gtk.ApplicationWindow(title=window.title, application=_app) |
| 80 |
self.pywebview_window.native = self.window |
| 81 |
|
| 82 |
self.shown = window.events.shown |
| 83 |
self.loaded = window.events.loaded |
| 84 |
|
| 85 |
self.localization = window.localization |
| 86 |
|
| 87 |
self._last_width = window.initial_width |
| 88 |
self._last_height = window.initial_height |
| 89 |
|
| 90 |
if window.screen: |
| 91 |
self.screen = window.screen.frame |
| 92 |
else: |
| 93 |
display = Gdk.Display.get_default() |
| 94 |
monitor = Gdk.Display.get_monitor(display, 0) |
| 95 |
self.screen = Gdk.Monitor.get_geometry(monitor) |
| 96 |
|
| 97 |
if window.resizable: |
| 98 |
self.window.set_size_request(window.min_size[0], window.min_size[1]) |
| 99 |
self.window.resize(window.initial_width, window.initial_height) |
| 100 |
else: |
| 101 |
self.window.set_size_request(window.initial_width, window.initial_height) |
| 102 |
|
| 103 |
if window.maximized: |
| 104 |
self.window.maximize() |
| 105 |
elif window.minimized: |
| 106 |
self.window.iconify() |
| 107 |
|
| 108 |
if window.initial_x is not None and window.initial_y is not None: |
| 109 |
self.move(window.initial_x, window.initial_y) |
| 110 |
else: |
| 111 |
window_width, window_height = self.window.get_size() |
| 112 |
x = (self.screen.width - window_width) // 2 |
| 113 |
y = (self.screen.height - window_height) // 2 |
| 114 |
self.move(x, y) |
| 115 |
|
| 116 |
self.window.set_resizable(window.resizable) |
| 117 |
self.window.set_accept_focus(window.focus) |
| 118 |
|
| 119 |
# Set window background color |
| 120 |
style_provider = gtk.CssProvider() |
| 121 |
style_provider.load_from_data( |
| 122 |
f'GtkWindow {{ background-color: {window.background_color}; }}'.encode() |
| 123 |
) |
| 124 |
gtk.StyleContext.add_provider_for_screen( |
| 125 |
Gdk.Screen.get_default(), style_provider, gtk.STYLE_PROVIDER_PRIORITY_APPLICATION |
| 126 |
) |
| 127 |
|
| 128 |
# Also set background color directly on ScrolledWindow |
| 129 |
self.background_rgba = self._hex_to_rgba(window.background_color) |
| 130 |
|
| 131 |
if window.menu: |
| 132 |
logger.warning('Window specific menu is not supported on GTK') |
| 133 |
|
| 134 |
scrolled_window = gtk.ScrolledWindow() |
| 135 |
scrolled_window.set_policy(gtk.PolicyType.NEVER, gtk.PolicyType.NEVER) |
| 136 |
|
| 137 |
# Set scrolled window background color using CSS |
| 138 |
scrolled_style_provider = gtk.CssProvider() |
| 139 |
scrolled_style_provider.load_from_data( |
| 140 |
f'* {{ background-color: {window.background_color}; }}'.encode() |
| 141 |
) |
| 142 |
scrolled_window.get_style_context().add_provider( |
| 143 |
scrolled_style_provider, gtk.STYLE_PROVIDER_PRIORITY_APPLICATION |
| 144 |
) |
| 145 |
|
| 146 |
self.window.add(scrolled_window) |
| 147 |
|
| 148 |
self.window.connect('delete-event', self.close_window) |
| 149 |
|
| 150 |
self.window.connect('window-state-event', self.on_window_state_change) |
| 151 |
self.window.connect('size-allocate', self.on_window_resize) |
| 152 |
self.window.connect('configure-event', self.on_window_configure) |
| 153 |
|
| 154 |
self.js_bridge = BrowserView.JSBridge(window) |
| 155 |
|
| 156 |
if _state['private_mode']: |
| 157 |
# Create ephemeral context for private mode |
| 158 |
web_context = webkit.WebContext.new_ephemeral() |
| 159 |
elif _state['storage_path']: |
| 160 |
storage_path = _state['storage_path'] |
| 161 |
|
| 162 |
# Create storage directory if it doesn't exist |
| 163 |
if not os.path.exists(storage_path): |
| 164 |
os.makedirs(storage_path) |
| 165 |
|
| 166 |
# Create website data manager with storage directories |
| 167 |
self.website_data_manager = webkit.WebsiteDataManager( |
| 168 |
base_data_directory=storage_path, |
| 169 |
base_cache_directory=os.path.join(storage_path, 'cache'), |
| 170 |
local_storage_directory=os.path.join(storage_path, 'localstorage'), |
| 171 |
indexeddb_directory=os.path.join(storage_path, 'indexeddb'), |
| 172 |
websql_directory=os.path.join(storage_path, 'websql'), |
| 173 |
hsts_cache_directory=os.path.join(storage_path, 'hsts'), |
| 174 |
itp_directory=os.path.join(storage_path, 'itp'), |
| 175 |
service_worker_registrations_directory=os.path.join(storage_path, 'serviceworkers'), |
| 176 |
dom_cache_directory=os.path.join(storage_path, 'domcache'), |
| 177 |
) |
| 178 |
web_context = webkit.WebContext.new_with_website_data_manager(self.website_data_manager) |
| 179 |
else: |
| 180 |
web_context = webkit.WebContext.get_default() |
| 181 |
|
| 182 |
self.cookie_manager = web_context.get_cookie_manager() |
| 183 |
|
| 184 |
if not _state['private_mode']: |
| 185 |
script_name = pathlib.Path(sys.argv[0]).name |
| 186 |
if script_name in ['python', 'python3', '-c', '']: |
| 187 |
script_name = 'pywebview' |
| 188 |
storage_path = _state['storage_path'] or os.path.expanduser(f'~/.cache/{script_name}/') |
| 189 |
|
| 190 |
self.cookie_manager.set_persistent_storage( |
| 191 |
os.path.join(storage_path, 'cookies'), webkit.CookiePersistentStorage.TEXT |
| 192 |
) |
| 193 |
|
| 194 |
if cert: |
| 195 |
web_context.allow_tls_certificate_for_host(cert, '127.0.0.1') |
| 196 |
|
| 197 |
self.manager = webkit.UserContentManager() |
| 198 |
self.manager.register_script_message_handler('jsBridge') |
| 199 |
self.manager.connect('script-message-received', self.on_js_bridge_call) |
| 200 |
|
| 201 |
self.request_headers_mutated = False |
| 202 |
|
| 203 |
# Create WebView with the configured context |
| 204 |
self.webview = webkit.WebView(user_content_manager=self.manager, web_context=web_context) |
| 205 |
self.webview.connect('notify::visible', self.on_webview_ready) |
| 206 |
self.webview.connect('load_changed', self.on_load_finish) |
| 207 |
self.webview.connect('decide-policy', self.on_navigation) |
| 208 |
self.webview.connect('drag-data-received', self.on_drag_data) |
| 209 |
self.webview.connect('resource-load-started', self.on_request) |
| 210 |
|
| 211 |
if settings['IGNORE_SSL_ERRORS']: |
| 212 |
web_context.set_tls_errors_policy(webkit.TLSErrorsPolicy.IGNORE) |
| 213 |
|
| 214 |
if settings['ALLOW_DOWNLOADS']: |
| 215 |
web_context.connect('download-started', self.on_download_started) |
| 216 |
|
| 217 |
webkit_settings = self.webview.get_settings().props |
| 218 |
user_agent = settings.get('user_agent') or _state['user_agent'] |
| 219 |
if user_agent: |
| 220 |
webkit_settings.user_agent = user_agent |
| 221 |
|
| 222 |
webkit_settings.enable_media_stream = True |
| 223 |
webkit_settings.enable_mediasource = True |
| 224 |
webkit_settings.enable_webaudio = True |
| 225 |
webkit_settings.enable_webgl = True |
| 226 |
webkit_settings.javascript_can_access_clipboard = True |
| 227 |
webkit_settings.allow_file_access_from_file_urls = settings['ALLOW_FILE_URLS'] |
| 228 |
|
| 229 |
if window.frameless: |
| 230 |
self.window.set_decorated(False) |
| 231 |
if window.easy_drag: |
| 232 |
self.move_progress = False |
| 233 |
self.webview.connect('button-release-event', self.on_mouse_release) |
| 234 |
self.webview.connect('button-press-event', self.on_mouse_press) |
| 235 |
self.window.connect('motion-notify-event', self.on_mouse_move) |
| 236 |
|
| 237 |
if window.on_top: |
| 238 |
self.window.set_keep_above(True) |
| 239 |
|
| 240 |
self.transparent = window.transparent |
| 241 |
if window.transparent: |
| 242 |
configure_transparency(self.window) |
| 243 |
configure_transparency(scrolled_window) |
| 244 |
configure_transparency(self.webview) |
| 245 |
wvbg = self.webview.get_background_color() |
| 246 |
wvbg.alpha = 0.0 |
| 247 |
self.webview.set_background_color(wvbg) |
| 248 |
else: |
| 249 |
# Set webview background color for non-transparent windows |
| 250 |
self.webview.set_background_color(self.background_rgba) |
| 251 |
|
| 252 |
if _state['debug']: |
| 253 |
webkit_settings.enable_developer_extras = True |
| 254 |
|
| 255 |
if settings['OPEN_DEVTOOLS_IN_DEBUG']: |
| 256 |
self.webview.get_inspector().show() |
| 257 |
else: |
| 258 |
self.webview.connect('context-menu', lambda a, b, c, d: True) # Disable context menu |
| 259 |
|
| 260 |
if _state['private_mode']: |
| 261 |
webkit_settings.enable_html5_database = False |
| 262 |
webkit_settings.enable_html5_local_storage = False |
| 263 |
|
| 264 |
self.webview.set_opacity(0.0) |
| 265 |
scrolled_window.add(self.webview) |
| 266 |
|
| 267 |
if _state['icon']: |
| 268 |
self.window.set_icon_from_file(_state['icon']) |
| 269 |
self.window.set_default_icon_from_file(_state['icon']) |
| 270 |
|
| 271 |
self.pywebview_window.events.before_show.set() |
| 272 |
|
| 273 |
if window.fullscreen: |
| 274 |
self.toggle_fullscreen() |
| 275 |
|
| 276 |
if window.real_url is not None: |
| 277 |
self.webview.load_uri(window.real_url) |
| 278 |
elif window.html: |
| 279 |
self.webview.load_html(window.html, '') |
| 280 |
else: |
| 281 |
self.webview.load_html(DEFAULT_HTML, '') |
| 282 |
|
| 283 |
def close_window(self, *data): |
| 284 |
should_cancel = self.pywebview_window.events.closing.set() |
| 285 |
|
| 286 |
if should_cancel: |
| 287 |
return True |
| 288 |
|
| 289 |
if self.pywebview_window.confirm_close: |
| 290 |
dialog = gtk.MessageDialog( |
| 291 |
parent=self.window, |
| 292 |
flags=gtk.DialogFlags.MODAL & gtk.DialogFlags.DESTROY_WITH_PARENT, |
| 293 |
type=gtk.MessageType.QUESTION, |
| 294 |
buttons=gtk.ButtonsType.OK_CANCEL, |
| 295 |
message_format=self.localization['global.quitConfirmation'], |
| 296 |
) |
| 297 |
result = dialog.run() |
| 298 |
dialog.destroy() |
| 299 |
if result == gtk.ResponseType.CANCEL: |
| 300 |
return True |
| 301 |
|
| 302 |
for res in self.js_results.values(): |
| 303 |
res['semaphore'].release() |
| 304 |
|
| 305 |
self.window.destroy() |
| 306 |
del BrowserView.instances[self.uid] |
| 307 |
|
| 308 |
if self.pywebview_window in windows: |
| 309 |
windows.remove(self.pywebview_window) |
| 310 |
|
| 311 |
self.pywebview_window.events.closed.set() |
| 312 |
|
| 313 |
return False |
| 314 |
|
| 315 |
def on_drag_data(self, widget, drag_context, x, y, data, info, time): |
| 316 |
text = data.get_text() |
| 317 |
if _dnd_state['num_listeners'] > 0 and text: |
| 318 |
files = [] |
| 319 |
for value in text.split('\n'): |
| 320 |
value = value.strip() |
| 321 |
if value.startswith('file://'): |
| 322 |
# Handle 'file://' URIs (e.g., `file:///home/user/file.txt`) |
| 323 |
path = value.replace('file://', '') |
| 324 |
files.append((os.path.basename(path), path)) |
| 325 |
elif value.startswith('/') and os.path.exists(value): |
| 326 |
# Handle direct paths (e.g., `/home/user/file.txt`) |
| 327 |
files.append((os.path.basename(value), value)) |
| 328 |
|
| 329 |
_dnd_state['paths'] += files |
| 330 |
|
| 331 |
return False |
| 332 |
|
| 333 |
def on_window_state_change(self, window, window_state): |
| 334 |
if window_state.changed_mask == Gdk.WindowState.ICONIFIED: |
| 335 |
if ( |
| 336 |
Gdk.WindowState.ICONIFIED & window_state.new_window_state |
| 337 |
== Gdk.WindowState.ICONIFIED |
| 338 |
): |
| 339 |
self.pywebview_window.events.minimized.set() |
| 340 |
else: |
| 341 |
self.pywebview_window.events.restored.set() |
| 342 |
|
| 343 |
elif window_state.changed_mask == Gdk.WindowState.MAXIMIZED: |
| 344 |
if ( |
| 345 |
Gdk.WindowState.MAXIMIZED & window_state.new_window_state |
| 346 |
== Gdk.WindowState.MAXIMIZED |
| 347 |
): |
| 348 |
self.pywebview_window.events.maximized.set() |
| 349 |
else: |
| 350 |
self.pywebview_window.events.restored.set() |
| 351 |
|
| 352 |
def on_js_bridge_call(self, manager, message): |
| 353 |
body = json.loads(message.get_js_value().to_string()) |
| 354 |
|
| 355 |
if body['funcName'] == '_pywebviewAlert': |
| 356 |
self.message_box(body['params']) |
| 357 |
else: |
| 358 |
js_bridge_call(self.pywebview_window, body['funcName'], body['params'], body['id']) |
| 359 |
|
| 360 |
def on_window_resize(self, window, allocation): |
| 361 |
if allocation.width != self._last_width or allocation.height != self._last_height: |
| 362 |
self._last_width = allocation.width |
| 363 |
self._last_height = allocation.height |
| 364 |
self.pywebview_window.events.resized.set(allocation.width, allocation.height) |
| 365 |
|
| 366 |
def on_window_configure(self, window, event): |
| 367 |
self.pywebview_window.events.moved.set(event.x, event.y) |
| 368 |
|
| 369 |
def on_webview_ready(self, arg1, arg2): |
| 370 |
# in webkit2 notify:visible fires after the window was closed and BrowserView object destroyed. |
| 371 |
# for a lack of better solution we check that BrowserView has 'webview_ready' attribute |
| 372 |
if 'shown' in dir(self): |
| 373 |
self.shown.set() |
| 374 |
|
| 375 |
def on_response(self, resource, _): |
| 376 |
response = resource.get_response() |
| 377 |
headers = response.get_http_headers() |
| 378 |
original_headers = self._headers_to_dict(headers) |
| 379 |
url = resource.get_uri() |
| 380 |
|
| 381 |
response_ = Response(url, response.get_status_code(), original_headers) |
| 382 |
self.pywebview_window.events.response_received.set(response_) |
| 383 |
|
| 384 |
def on_request(self, webview, resource, request): |
| 385 |
if len(self.pywebview_window.events.response_received) > 0: |
| 386 |
resource.connect('notify::response', self.on_response) |
| 387 |
|
| 388 |
if len(self.pywebview_window.events.request_sent) == 0: |
| 389 |
return |
| 390 |
|
| 391 |
headers = request.get_http_headers() |
| 392 |
original_headers = self._headers_to_dict(headers) |
| 393 |
url = request.get_uri() |
| 394 |
method = request.get_http_method() |
| 395 |
|
| 396 |
request_ = Request(url, method, original_headers) |
| 397 |
self.pywebview_window.events.request_sent.set(request_) |
| 398 |
|
| 399 |
if ( |
| 400 |
request_.headers == original_headers |
| 401 |
or not headers |
| 402 |
or self.request_headers_mutated |
| 403 |
or url != self.pywebview_window.real_url |
| 404 |
): |
| 405 |
return |
| 406 |
|
| 407 |
missing_headers = { |
| 408 |
k: v |
| 409 |
for k, v in request_.headers.items() |
| 410 |
if k not in original_headers or original_headers[k] != v |
| 411 |
} |
| 412 |
extra_headers = { |
| 413 |
k: str(v) for k, v in original_headers.items() if k not in request_.headers |
| 414 |
} |
| 415 |
|
| 416 |
for k, v in missing_headers.items(): |
| 417 |
headers.append(k, v) |
| 418 |
|
| 419 |
for k in extra_headers: |
| 420 |
headers.remove(k) |
| 421 |
|
| 422 |
# headers.append('X-Handled', 'true') |
| 423 |
webview.stop_loading() |
| 424 |
self.request_headers_mutated = True |
| 425 |
webview.load_request(request) |
| 426 |
|
| 427 |
def on_load_finish(self, webview, status): |
| 428 |
# Show the webview if it's not already visible |
| 429 |
if not webview.props.opacity: |
| 430 |
glib.idle_add(webview.set_opacity, 1.0) |
| 431 |
|
| 432 |
if status == webkit.LoadEvent.FINISHED and not self.request_headers_mutated: |
| 433 |
inject_pywebview(renderer, self.js_bridge.window) |
| 434 |
|
| 435 |
if self.request_headers_mutated: |
| 436 |
self.request_headers_mutated = False |
| 437 |
|
| 438 |
def on_download_started(self, session, download): |
| 439 |
download.connect('decide-destination', self.on_download_decide_destination) |
| 440 |
|
| 441 |
def on_download_decide_destination(self, download, suggested_filename): |
| 442 |
destination = self.create_file_dialog( |
| 443 |
FileDialog.SAVE, |
| 444 |
glib.get_user_special_dir(glib.UserDirectory.DIRECTORY_DOWNLOAD), |
| 445 |
False, |
| 446 |
suggested_filename, |
| 447 |
(), |
| 448 |
) |
| 449 |
|
| 450 |
if destination: |
| 451 |
destination_uri = glib.filename_to_uri(destination[0]) |
| 452 |
download.set_destination(destination_uri) |
| 453 |
else: |
| 454 |
download.cancel() |
| 455 |
|
| 456 |
def on_navigation(self, webview, decision, decision_type): |
| 457 |
if type(decision) is webkit.NavigationPolicyDecision: |
| 458 |
uri = decision.get_navigation_action().get_request().get_uri() |
| 459 |
|
| 460 |
if decision.get_navigation_action().get_frame_name() == '_blank': |
| 461 |
if settings['OPEN_EXTERNAL_LINKS_IN_BROWSER']: |
| 462 |
webbrowser.open(uri, 2, True) |
| 463 |
decision.ignore() |
| 464 |
else: |
| 465 |
self.load_url(uri) |
| 466 |
elif type(decision) is webkit.ResponsePolicyDecision: |
| 467 |
if not decision.is_mime_type_supported(): |
| 468 |
self._download_filename = decision.get_response().get_suggested_filename() |
| 469 |
decision.download() |
| 470 |
else: |
| 471 |
decision.use() |
| 472 |
|
| 473 |
def on_mouse_release(self, sender, event): |
| 474 |
self.move_progress = False |
| 475 |
|
| 476 |
def on_mouse_press(self, _, event): |
| 477 |
self.point_diff = [ |
| 478 |
x - y for x, y in zip(self.window.get_position(), [event.x_root, event.y_root]) |
| 479 |
] |
| 480 |
self.move_progress = True |
| 481 |
|
| 482 |
def on_mouse_move(self, _, event): |
| 483 |
if self.move_progress: |
| 484 |
point = [x + y for x, y in zip((event.x_root, event.y_root), self.point_diff)] |
| 485 |
self.window.move(point[0], point[1]) |
| 486 |
|
| 487 |
def show(self): |
| 488 |
self.window.show_all() |
| 489 |
|
| 490 |
if gtk.main_level() == 0: |
| 491 |
if self.pywebview_window.hidden: |
| 492 |
self.window.hide() |
| 493 |
else: |
| 494 |
glib.idle_add(self.window.show_all) |
| 495 |
|
| 496 |
def hide(self): |
| 497 |
glib.idle_add(self.window.hide) |
| 498 |
|
| 499 |
def destroy(self): |
| 500 |
self.window.emit('delete-event', Gdk.Event()) |
| 501 |
|
| 502 |
def set_title(self, title): |
| 503 |
self.window.set_title(title) |
| 504 |
|
| 505 |
def toggle_fullscreen(self): |
| 506 |
if self.is_fullscreen: |
| 507 |
self.window.unfullscreen() |
| 508 |
else: |
| 509 |
self.window.fullscreen() |
| 510 |
|
| 511 |
self.is_fullscreen = not self.is_fullscreen |
| 512 |
|
| 513 |
def resize(self, width, height, fix_point): |
| 514 |
if fix_point & FixPoint.NORTH and fix_point & FixPoint.WEST: |
| 515 |
self.window.set_gravity(Gdk.Gravity.NORTH_WEST) |
| 516 |
elif fix_point & FixPoint.NORTH and fix_point & FixPoint.EAST: |
| 517 |
self.window.set_gravity(Gdk.Gravity.NORTH_EAST) |
| 518 |
elif fix_point & FixPoint.SOUTH and fix_point & FixPoint.EAST: |
| 519 |
self.window.set_gravity(Gdk.Gravity.SOUTH_EAST) |
| 520 |
elif fix_point & FixPoint.SOUTH and fix_point & FixPoint.WEST: |
| 521 |
self.window.set_gravity(Gdk.Gravity.SOUTH_WEST) |
| 522 |
elif fix_point & FixPoint.SOUTH: |
| 523 |
self.window.set_gravity(Gdk.Gravity.SOUTH) |
| 524 |
elif fix_point & FixPoint.NORTH: |
| 525 |
self.window.set_gravity(Gdk.Gravity.NORTH) |
| 526 |
elif fix_point & FixPoint.WEST: |
| 527 |
self.window.set_gravity(Gdk.Gravity.WEST) |
| 528 |
elif fix_point & FixPoint.EAST: |
| 529 |
self.window.set_gravity(Gdk.Gravity.EAST) |
| 530 |
|
| 531 |
self.window.resize(width, height) |
| 532 |
|
| 533 |
def move(self, x, y): |
| 534 |
self.window.move(self.screen.x + x, self.screen.y + y) |
| 535 |
|
| 536 |
def maximize(self): |
| 537 |
glib.idle_add(self.window.maximize) |
| 538 |
|
| 539 |
def minimize(self): |
| 540 |
glib.idle_add(self.window.iconify) |
| 541 |
|
| 542 |
def restore(self): |
| 543 |
def _restore(): |
| 544 |
self.window.deiconify() |
| 545 |
self.window.present() |
| 546 |
|
| 547 |
glib.idle_add(_restore) |
| 548 |
|
| 549 |
def create_confirmation_dialog(self, title, message): |
| 550 |
dialog = gtk.MessageDialog( |
| 551 |
parent=self.window, |
| 552 |
flags=gtk.DialogFlags.MODAL & gtk.DialogFlags.DESTROY_WITH_PARENT, |
| 553 |
type=gtk.MessageType.QUESTION, |
| 554 |
text=title, |
| 555 |
message_format=message, |
| 556 |
buttons=gtk.ButtonsType.OK_CANCEL, |
| 557 |
) |
| 558 |
response = dialog.run() |
| 559 |
dialog.destroy() |
| 560 |
if response == gtk.ResponseType.OK: |
| 561 |
return True |
| 562 |
|
| 563 |
return False |
| 564 |
|
| 565 |
def create_file_dialog(self, dialog_type, directory, allow_multiple, save_filename, file_types): |
| 566 |
if dialog_type == FileDialog.FOLDER: |
| 567 |
gtk_dialog_type = gtk.FileChooserAction.SELECT_FOLDER |
| 568 |
title = self.localization['linux.openFolder'] |
| 569 |
button = gtk.STOCK_OPEN |
| 570 |
elif dialog_type == FileDialog.OPEN: |
| 571 |
gtk_dialog_type = gtk.FileChooserAction.OPEN |
| 572 |
if allow_multiple: |
| 573 |
title = self.localization['linux.openFiles'] |
| 574 |
else: |
| 575 |
title = self.localization['linux.openFile'] |
| 576 |
|
| 577 |
button = gtk.STOCK_OPEN |
| 578 |
elif dialog_type == FileDialog.SAVE: |
| 579 |
gtk_dialog_type = gtk.FileChooserAction.SAVE |
| 580 |
title = self.localization['global.saveFile'] |
| 581 |
button = gtk.STOCK_SAVE |
| 582 |
|
| 583 |
dialog = gtk.FileChooserDialog( |
| 584 |
title, |
| 585 |
self.window, |
| 586 |
gtk_dialog_type, |
| 587 |
(gtk.STOCK_CANCEL, gtk.ResponseType.CANCEL, button, gtk.ResponseType.OK), |
| 588 |
) |
| 589 |
|
| 590 |
dialog.set_select_multiple(allow_multiple) |
| 591 |
dialog.set_current_folder(directory) |
| 592 |
self._add_file_filters(dialog, file_types) |
| 593 |
|
| 594 |
if dialog_type == FileDialog.SAVE: |
| 595 |
dialog.set_current_name(save_filename) |
| 596 |
|
| 597 |
response = dialog.run() |
| 598 |
|
| 599 |
if response == gtk.ResponseType.OK: |
| 600 |
if dialog_type == FileDialog.SAVE: |
| 601 |
file_name = (dialog.get_filename(),) |
| 602 |
else: |
| 603 |
file_name = dialog.get_filenames() |
| 604 |
else: |
| 605 |
file_name = None |
| 606 |
|
| 607 |
dialog.destroy() |
| 608 |
|
| 609 |
return file_name |
| 610 |
|
| 611 |
def _add_file_filters(self, dialog, file_types): |
| 612 |
for s in file_types: |
| 613 |
description, extensions = parse_file_type(s) |
| 614 |
|
| 615 |
f = gtk.FileFilter() |
| 616 |
f.set_name(description) |
| 617 |
for e in extensions.split(';'): |
| 618 |
f.add_pattern(e) |
| 619 |
|
| 620 |
dialog.add_filter(f) |
| 621 |
|
| 622 |
def clear_cookies(self): |
| 623 |
def _clear_cookies(): |
| 624 |
self.cookie_manager.delete_all_cookies() |
| 625 |
|
| 626 |
glib.idle_add(_clear_cookies) |
| 627 |
|
| 628 |
def get_cookies(self): |
| 629 |
def _get_cookies(): |
| 630 |
self.cookie_manager.get_cookies(self.webview.get_uri(), None, callback, None) |
| 631 |
|
| 632 |
def callback(source, task, data): |
| 633 |
results = source.get_cookies_finish(task) |
| 634 |
|
| 635 |
for c in results: |
| 636 |
cookie = create_cookie(c.to_set_cookie_header()) |
| 637 |
cookies.append(cookie) |
| 638 |
|
| 639 |
semaphore.release() |
| 640 |
|
| 641 |
cookies = [] |
| 642 |
semaphore = Semaphore(0) |
| 643 |
glib.idle_add(_get_cookies) |
| 644 |
semaphore.acquire() |
| 645 |
|
| 646 |
return cookies |
| 647 |
|
| 648 |
def get_current_url(self): |
| 649 |
uri = self.webview.get_uri() |
| 650 |
return uri if uri != 'about:blank' else None |
| 651 |
|
| 652 |
def load_url(self, url): |
| 653 |
self.webview.load_uri(url) |
| 654 |
|
| 655 |
def load_html(self, content, base_uri): |
| 656 |
self.webview.load_html(content, base_uri) |
| 657 |
|
| 658 |
def evaluate_js(self, script, parse_json): |
| 659 |
def _evaluate_js(): |
| 660 |
try: |
| 661 |
self.webview.evaluate_javascript( |
| 662 |
script=script, |
| 663 |
length=len(script), |
| 664 |
world_name=None, |
| 665 |
source_uri=None, |
| 666 |
cancellable=None, |
| 667 |
callback=_callback, |
| 668 |
) |
| 669 |
except Exception: |
| 670 |
logger.exception('Error evaluating JavaScript') |
| 671 |
result_semaphore.release() |
| 672 |
|
| 673 |
def _callback(webview, task): |
| 674 |
nonlocal result |
| 675 |
try: |
| 676 |
value = webview.evaluate_javascript_finish(task) |
| 677 |
res = self._convert_js_value(value) |
| 678 |
|
| 679 |
if parse_json and res: |
| 680 |
try: |
| 681 |
result = json.loads(res) |
| 682 |
except Exception: |
| 683 |
pass |
| 684 |
else: |
| 685 |
result = res |
| 686 |
|
| 687 |
except Exception as e: |
| 688 |
logger.exception(e) |
| 689 |
|
| 690 |
result_semaphore.release() |
| 691 |
|
| 692 |
result_semaphore = Semaphore(0) |
| 693 |
result = None |
| 694 |
glib.idle_add(_evaluate_js) |
| 695 |
result_semaphore.acquire() |
| 696 |
|
| 697 |
return result |
| 698 |
|
| 699 |
def message_box(self, message): |
| 700 |
dialog = gtk.MessageDialog( |
| 701 |
parent=self.window, |
| 702 |
flags=gtk.DialogFlags.MODAL & gtk.DialogFlags.DESTROY_WITH_PARENT, |
| 703 |
type=gtk.MessageType.INFO, |
| 704 |
buttons=gtk.ButtonsType.OK, |
| 705 |
message_format=message, |
| 706 |
) |
| 707 |
dialog.run() |
| 708 |
dialog.destroy() |
| 709 |
|
| 710 |
def _convert_js_value(self, js_value): |
| 711 |
if not js_value or js_value.is_null() or js_value.is_undefined(): |
| 712 |
return None |
| 713 |
elif js_value.is_boolean(): |
| 714 |
return js_value.to_boolean() |
| 715 |
elif js_value.is_number(): |
| 716 |
return js_value.to_double() |
| 717 |
elif js_value.is_string(): |
| 718 |
return js_value.to_string() |
| 719 |
elif js_value.is_object(): |
| 720 |
return json.loads(js_value.to_json(2)) |
| 721 |
else: |
| 722 |
logger.error(f'Unsupported JavaScriptCore.Value type: {js_value}') |
| 723 |
return js_value.to_string() |
| 724 |
|
| 725 |
def _headers_to_dict(self, headers): |
| 726 |
def _assign(k, v): |
| 727 |
headers_dict[k] = v |
| 728 |
|
| 729 |
headers_dict = {} |
| 730 |
|
| 731 |
if headers: |
| 732 |
headers.foreach(_assign) |
| 733 |
return headers_dict |
| 734 |
|
| 735 |
def _hex_to_rgba(self, hex_color): |
| 736 |
"""Convert hex color (#RRGGBB or #RGB) to Gdk.RGBA object.""" |
| 737 |
hex_color = hex_color.lstrip('#') |
| 738 |
|
| 739 |
# Convert 3-digit to 6-digit format |
| 740 |
if len(hex_color) == 3: |
| 741 |
hex_color = ''.join([c * 2 for c in hex_color]) |
| 742 |
|
| 743 |
# Parse hex values |
| 744 |
r = int(hex_color[0:2], 16) / 255.0 |
| 745 |
g = int(hex_color[2:4], 16) / 255.0 |
| 746 |
b = int(hex_color[4:6], 16) / 255.0 |
| 747 |
|
| 748 |
return Gdk.RGBA(r, g, b, 1.0) |
| 749 |
|
| 750 |
|
| 751 |
def setup_app(): |
| 752 |
def set_menubar(app): |
| 753 |
app.set_menubar(app_menu) |
| 754 |
|
| 755 |
global _app |
| 756 |
if _app is not None: |
| 757 |
return |
| 758 |
|
| 759 |
_app = gtk.Application.new(None, 0) |
| 760 |
|
| 761 |
if _state['menu']: |
| 762 |
app_menu = create_menu(_state['menu']) |
| 763 |
_app.connect('startup', set_menubar) |
| 764 |
|
| 765 |
|
| 766 |
def create_window(window): |
| 767 |
global _app |
| 768 |
|
| 769 |
def create(): |
| 770 |
browser = BrowserView(window) |
| 771 |
browser.show() |
| 772 |
|
| 773 |
def create_master_callback(app): |
| 774 |
create() |
| 775 |
|
| 776 |
if window.uid == 'master': |
| 777 |
main_thread().pydev_do_not_trace = True # vs code debugger hang fix |
| 778 |
_app.connect('activate', create_master_callback) |
| 779 |
_app.run() |
| 780 |
_app = None |
| 781 |
else: |
| 782 |
# _app will already have been activated by this point |
| 783 |
glib.idle_add(create) |
| 784 |
|
| 785 |
|
| 786 |
def set_title(title, uid): |
| 787 |
def _set_title(): |
| 788 |
i.set_title(title) |
| 789 |
|
| 790 |
i = BrowserView.instances.get(uid) |
| 791 |
if i: |
| 792 |
glib.idle_add(_set_title) |
| 793 |
|
| 794 |
|
| 795 |
def destroy_window(uid): |
| 796 |
def _destroy_window(): |
| 797 |
i.close_window() |
| 798 |
|
| 799 |
i = BrowserView.instances.get(uid) |
| 800 |
if i: |
| 801 |
glib.idle_add(_destroy_window) |
| 802 |
|
| 803 |
|
| 804 |
def toggle_fullscreen(uid): |
| 805 |
def _toggle_fullscreen(): |
| 806 |
i.toggle_fullscreen() |
| 807 |
|
| 808 |
i = BrowserView.instances.get(uid) |
| 809 |
if i: |
| 810 |
glib.idle_add(_toggle_fullscreen) |
| 811 |
|
| 812 |
|
| 813 |
def add_tls_cert(certfile): |
| 814 |
global cert |
| 815 |
cert = Gio.TlsCertificate.new_from_file(certfile) |
| 816 |
|
| 817 |
|
| 818 |
def set_on_top(uid, top): |
| 819 |
def _set_on_top(): |
| 820 |
i.window.set_keep_above(top) |
| 821 |
|
| 822 |
i = BrowserView.instances.get(uid) |
| 823 |
if i: |
| 824 |
glib.idle_add(_set_on_top) |
| 825 |
|
| 826 |
|
| 827 |
def resize(width, height, uid, fix_point): |
| 828 |
def _resize(): |
| 829 |
i.resize(width, height, fix_point) |
| 830 |
|
| 831 |
i = BrowserView.instances.get(uid) |
| 832 |
if i: |
| 833 |
glib.idle_add(_resize) |
| 834 |
|
| 835 |
|
| 836 |
def move(x, y, uid): |
| 837 |
def _move(): |
| 838 |
i.move(x, y) |
| 839 |
|
| 840 |
i = BrowserView.instances.get(uid) |
| 841 |
if i: |
| 842 |
glib.idle_add(_move) |
| 843 |
|
| 844 |
|
| 845 |
def hide(uid): |
| 846 |
i = BrowserView.instances.get(uid) |
| 847 |
if i: |
| 848 |
glib.idle_add(i.hide) |
| 849 |
|
| 850 |
|
| 851 |
def show(uid): |
| 852 |
i = BrowserView.instances.get(uid) |
| 853 |
if i: |
| 854 |
glib.idle_add(i.show) |
| 855 |
|
| 856 |
|
| 857 |
def maximize(uid): |
| 858 |
i = BrowserView.instances.get(uid) |
| 859 |
if i: |
| 860 |
glib.idle_add(i.maximize) |
| 861 |
|
| 862 |
|
| 863 |
def minimize(uid): |
| 864 |
i = BrowserView.instances.get(uid) |
| 865 |
if i: |
| 866 |
glib.idle_add(i.minimize) |
| 867 |
|
| 868 |
|
| 869 |
def restore(uid): |
| 870 |
i = BrowserView.instances.get(uid) |
| 871 |
if i: |
| 872 |
glib.idle_add(i.restore) |
| 873 |
|
| 874 |
|
| 875 |
def clear_cookies(uid): |
| 876 |
i = BrowserView.instances.get(uid) |
| 877 |
if i: |
| 878 |
i.clear_cookies() |
| 879 |
|
| 880 |
|
| 881 |
def get_cookies(uid): |
| 882 |
i = BrowserView.instances.get(uid) |
| 883 |
if i: |
| 884 |
cookies = i.get_cookies() |
| 885 |
return cookies |
| 886 |
|
| 887 |
|
| 888 |
def get_current_url(uid): |
| 889 |
def _get_current_url(): |
| 890 |
result['url'] = i.get_current_url() |
| 891 |
semaphore.release() |
| 892 |
|
| 893 |
result = {} |
| 894 |
semaphore = Semaphore(0) |
| 895 |
|
| 896 |
i = BrowserView.instances.get(uid) |
| 897 |
if not i: |
| 898 |
return |
| 899 |
|
| 900 |
glib.idle_add(_get_current_url) |
| 901 |
semaphore.acquire() |
| 902 |
|
| 903 |
return result['url'] |
| 904 |
|
| 905 |
|
| 906 |
def load_url(url, uid): |
| 907 |
def _load_url(): |
| 908 |
i.load_url(url) |
| 909 |
|
| 910 |
i = BrowserView.instances.get(uid) |
| 911 |
if i: |
| 912 |
glib.idle_add(_load_url) |
| 913 |
|
| 914 |
|
| 915 |
def load_html(content, base_uri, uid): |
| 916 |
def _load_html(): |
| 917 |
i.load_html(content, base_uri) |
| 918 |
|
| 919 |
i = BrowserView.instances.get(uid) |
| 920 |
if i: |
| 921 |
glib.idle_add(_load_html) |
| 922 |
|
| 923 |
|
| 924 |
def create_confirmation_dialog(title, message, uid): |
| 925 |
def _create(): |
| 926 |
nonlocal result |
| 927 |
result = i.create_confirmation_dialog(title, message) |
| 928 |
result_semaphore.release() |
| 929 |
|
| 930 |
i = BrowserView.instances.get(uid) |
| 931 |
result_semaphore = Semaphore(0) |
| 932 |
result = -1 |
| 933 |
|
| 934 |
if i: |
| 935 |
glib.idle_add(_create) |
| 936 |
result_semaphore.acquire() |
| 937 |
|
| 938 |
return result |
| 939 |
|
| 940 |
|
| 941 |
def create_menu(app_menu_list): |
| 942 |
def action_callback(action, parameter): |
| 943 |
function = _app_actions.get(action.get_name()) |
| 944 |
if function is None: |
| 945 |
return |
| 946 |
# Don't run action function on main thread |
| 947 |
Thread(target=function).start() |
| 948 |
|
| 949 |
def create_submenu(title, line_items, supermenu, action_prepend=''): |
| 950 |
m = Gio.Menu.new() |
| 951 |
current_section = Gio.Menu.new() |
| 952 |
action_prepend = f'{action_prepend}_{title}' |
| 953 |
for menu_line_item in line_items: |
| 954 |
if isinstance(menu_line_item, MenuSeparator): |
| 955 |
m.append_section(None, current_section) |
| 956 |
current_section = Gio.Menu.new() |
| 957 |
elif isinstance(menu_line_item, MenuAction): |
| 958 |
action_label = f'{action_prepend}_{menu_line_item.title}'.replace(' ', '_') |
| 959 |
while action_label in _app_actions.keys(): |
| 960 |
action_label += '_' |
| 961 |
_app_actions[action_label] = menu_line_item.function |
| 962 |
new_action = Gio.SimpleAction.new(action_label, None) |
| 963 |
new_action.connect('activate', action_callback) |
| 964 |
_app.add_action(new_action) |
| 965 |
current_section.append(menu_line_item.title, 'app.' + action_label) |
| 966 |
elif isinstance(menu_line_item, Menu): |
| 967 |
create_submenu( |
| 968 |
menu_line_item.title, |
| 969 |
menu_line_item.items, |
| 970 |
current_section, |
| 971 |
action_prepend=action_prepend, |
| 972 |
) |
| 973 |
|
| 974 |
m.append_section(None, current_section) |
| 975 |
|
| 976 |
supermenu.append_submenu(title, m) |
| 977 |
|
| 978 |
menubar = Gio.Menu() |
| 979 |
|
| 980 |
for app_menu in app_menu_list: |
| 981 |
# Ignore '__app__' menus (macOS-only feature) |
| 982 |
if app_menu.title == '__app__': |
| 983 |
continue |
| 984 |
create_submenu(app_menu.title, app_menu.items, menubar) |
| 985 |
|
| 986 |
return menubar |
| 987 |
|
| 988 |
|
| 989 |
def get_active_window(): |
| 990 |
active_window = None |
| 991 |
try: |
| 992 |
active_window = _app.get_active_window() |
| 993 |
except Exception: |
| 994 |
return None |
| 995 |
|
| 996 |
active_window_number = active_window.get_id() |
| 997 |
|
| 998 |
for uid, browser_view_instance in BrowserView.instances.items(): |
| 999 |
if browser_view_instance.window.get_id() == active_window_number: |
| 1000 |
return browser_view_instance.pywebview_window |
| 1001 |
|
| 1002 |
return None |
| 1003 |
|
| 1004 |
|
| 1005 |
def create_file_dialog(dialog_type, directory, allow_multiple, save_filename, file_types, uid): |
| 1006 |
i = BrowserView.instances.get(uid) |
| 1007 |
file_name_semaphore = Semaphore(0) |
| 1008 |
file_names = [] |
| 1009 |
|
| 1010 |
def _create(): |
| 1011 |
result = i.create_file_dialog( |
| 1012 |
dialog_type, directory, allow_multiple, save_filename, file_types |
| 1013 |
) |
| 1014 |
if result is None: |
| 1015 |
file_names.append(None) |
| 1016 |
else: |
| 1017 |
file_names.append(tuple(result)) |
| 1018 |
|
| 1019 |
file_name_semaphore.release() |
| 1020 |
|
| 1021 |
glib.idle_add(_create) |
| 1022 |
file_name_semaphore.acquire() |
| 1023 |
|
| 1024 |
return file_names[0] |
| 1025 |
|
| 1026 |
|
| 1027 |
def evaluate_js(script, uid, parse_json=True): |
| 1028 |
i = BrowserView.instances.get(uid) |
| 1029 |
|
| 1030 |
if i: |
| 1031 |
return i.evaluate_js(script, parse_json) |
| 1032 |
|
| 1033 |
|
| 1034 |
def get_position(uid): |
| 1035 |
def _get_position(): |
| 1036 |
result['position'] = i.window.get_position() |
| 1037 |
semaphore.release() |
| 1038 |
|
| 1039 |
i = BrowserView.instances.get(uid) |
| 1040 |
if not i: |
| 1041 |
return |
| 1042 |
|
| 1043 |
result = {} |
| 1044 |
semaphore = Semaphore(0) |
| 1045 |
|
| 1046 |
glib.idle_add(_get_position) |
| 1047 |
semaphore.acquire() |
| 1048 |
|
| 1049 |
return result['position'] |
| 1050 |
|
| 1051 |
|
| 1052 |
def get_size(uid): |
| 1053 |
def _get_size(): |
| 1054 |
result['size'] = i.window.get_size() |
| 1055 |
semaphore.release() |
| 1056 |
|
| 1057 |
i = BrowserView.instances.get(uid) |
| 1058 |
if not i: |
| 1059 |
return |
| 1060 |
|
| 1061 |
result = {} |
| 1062 |
semaphore = Semaphore(0) |
| 1063 |
|
| 1064 |
glib.idle_add(_get_size) |
| 1065 |
semaphore.acquire() |
| 1066 |
|
| 1067 |
return result['size'] |
| 1068 |
|
| 1069 |
|
| 1070 |
def get_screens(): |
| 1071 |
display = Gdk.Display.get_default() |
| 1072 |
n = display.get_n_monitors() |
| 1073 |
monitors = [Gdk.Display.get_monitor(display, i) for i in range(n)] |
| 1074 |
geometries = [Gdk.Monitor.get_geometry(m) for m in monitors] |
| 1075 |
scales = [Gdk.Monitor.get_scale_factor(m) for m in monitors] |
| 1076 |
screens = [ |
| 1077 |
Screen(geom.x, geom.y, geom.width, geom.height, geom, scale) |
| 1078 |
for geom, scale in zip(geometries, scales) |
| 1079 |
] |
| 1080 |
|
| 1081 |
return screens |
| 1082 |
|
| 1083 |
|
| 1084 |
def configure_transparency(c): |
| 1085 |
c.set_visual(c.get_screen().get_rgba_visual()) |
| 1086 |
c.override_background_color(gtk.StateFlags.ACTIVE, Gdk.RGBA(0, 0, 0, 0)) |
| 1087 |
c.override_background_color(gtk.StateFlags.BACKDROP, Gdk.RGBA(0, 0, 0, 0)) |
| 1088 |
c.override_background_color(gtk.StateFlags.DIR_LTR, Gdk.RGBA(0, 0, 0, 0)) |
| 1089 |
c.override_background_color(gtk.StateFlags.DIR_RTL, Gdk.RGBA(0, 0, 0, 0)) |
| 1090 |
c.override_background_color(gtk.StateFlags.FOCUSED, Gdk.RGBA(0, 0, 0, 0)) |
| 1091 |
c.override_background_color(gtk.StateFlags.INCONSISTENT, Gdk.RGBA(0, 0, 0, 0)) |
| 1092 |
c.override_background_color(gtk.StateFlags.INSENSITIVE, Gdk.RGBA(0, 0, 0, 0)) |
| 1093 |
c.override_background_color(gtk.StateFlags.NORMAL, Gdk.RGBA(0, 0, 0, 0)) |
| 1094 |
c.override_background_color(gtk.StateFlags.PRELIGHT, Gdk.RGBA(0, 0, 0, 0)) |
| 1095 |
c.override_background_color(gtk.StateFlags.SELECTED, Gdk.RGBA(0, 0, 0, 0)) |
| 1096 |
transparentWindowStyleProvider = gtk.CssProvider() |
| 1097 |
transparentWindowStyleProvider.load_from_data( |
| 1098 |
b""" |
| 1099 |
GtkWindow { |
| 1100 |
background-color:rgba(0,0,0,0); |
| 1101 |
background-image:none; |
| 1102 |
}""" |
| 1103 |
) |
| 1104 |
c.get_style_context().add_provider( |
| 1105 |
transparentWindowStyleProvider, gtk.STYLE_PROVIDER_PRIORITY_APPLICATION |
| 1106 |
) |