Действительно ли возможно представить веб-контент по ясному фону с помощью WebKit?

См. Код ниже. Вам нужно будет отфильтровать теги HTML из текста Div (работает для Bokeh v1.0.4).

from bokeh.io import show
from bokeh.plotting import figure
from bokeh import events
from bokeh.models import CustomJS, Div, Button, RadioButtonGroup
from bokeh.layouts import column, row

def display_event(div, attributes = [], style = 'float:left;clear:left;font_size=10pt'):
    "Build a suitable CustomJS to display the current event in the div model."
    return CustomJS(args = dict(div = div, radio_button = radioButton), code = """
        var attrs = %s; var args = [];
        for (var i = 0; i<attrs.length; i++) {
            args.push(attrs[i] + '=' + Number(cb_obj[attrs[i]]).toFixed(2));
        }
        var line = "<span style=%r><b>" + radio_button.labels[radio_button.active] + "</b>: (" + args.join(", ") + ")</span>\\n";
        var text = div.text.concat(line);
        var lines = text.split("\\n")
        if (lines.length > 35)
            lines.shift();
        div.text = lines.join("\\n");
    """ % (attributes, style))

p = figure()
p.circle(x = [1, 2, 3, 4, 5], y = [5, 4, 3, 2, 1])
div = Div(width = 1000)
radioButton = RadioButtonGroup(labels = ["Elevator", "LOP", "Waiting point"], active = 0)
button = Button(label = "Download JSON", button_type = "success")
layout = column(button, radioButton, row(p, div))

js_download = """
var filetext = div.text;
var lines = filetext.split("\\n")
var lines_json = {}
for (i = 0; i < lines.length; i++)
    if (lines[i].trim())
        lines_json[String(i)] = lines[i];

var filename = 'results.json';
var blob = new Blob([JSON.stringify(lines_json)], { type: 'text/json;charset=utf-8;' });
div.text = '';
if (navigator.msSaveBlob) { // IE 10+
navigator.msSaveBlob(blob, filename);
} else {
var link = document.createElement("a");
if (link.download !== undefined) { // feature detection
    // Browsers that support HTML5 download attribute
    var url = URL.createObjectURL(blob);
    link.setAttribute("href", url);
    link.setAttribute("download", filename);
    link.style.visibility = 'hidden';
    document.body.appendChild(link);
    link.click();
    document.body.removeChild(link);
}
}"""

button.callback = CustomJS(args = dict(div = div), code = js_download)
# button.js_on_event(events.ButtonClick, display_event(div))  # Button click$

point_attributes = ['x', 'y', 'sx', 'sy']  # Point events
point_events = [events.Tap, events.DoubleTap]

for event in point_events:
    p.js_on_event(event, display_event(div, attributes = point_attributes))

show(layout)
33
задан Paul D. Waite 2 November 2010 в 09:11
поделиться

3 ответа

Solved!

Through ongoing research, scouring forums and source code repositories, I peiced together the necessary steps to accomplish this using only libwebkit and a standard compiz desktop (any Xorg desktop with compositing should do).

For a current libwebkit (1.1.10-SVN), there is an Ubuntu PPA:

deb http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main
deb-src http://ppa.launchpad.net/webkit-team/ppa/ubuntu jaunty main

As far as the code goes, the key is calling webkit_web_view_set_transparent.

And of course the system you're running it on should have a capable graphics card (intel, radeon, or nvidia) and be running a compositing window manager (like Compiz).

And finally, to actually see transparency, the content you're viewing must set a transparent background using CSS3, otherwise it's still completely opaque.

It's as simple as:

BODY { background-color: rgba(0,0,0,0); }

Here' is the full sample for the simplest possible webkit browser app, with transparency support:

#include <gtk/gtk.h>
#include <webkit/webkit.h>

static void destroy_cb(GtkWidget* widget, gpointer data) {
  gtk_main_quit();
}

int main(int argc, char* argv[]) {
  gtk_init(&argc, &argv);

  if(!g_thread_supported())
    g_thread_init(NULL);

  // Create a Window, set colormap to RGBA
  GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  GdkScreen *screen = gtk_widget_get_screen(window);
  GdkColormap *rgba = gdk_screen_get_rgba_colormap (screen);

  if (rgba && gdk_screen_is_composited (screen)) {
    gtk_widget_set_default_colormap(rgba);
    gtk_widget_set_colormap(GTK_WIDGET(window), rgba);
  }

  gtk_window_set_default_size(GTK_WINDOW(window), 800, 800);
  g_signal_connect(window, "destroy", G_CALLBACK(destroy_cb), NULL);

  // Optional: for dashboard style borderless windows
  gtk_window_set_decorated(GTK_WINDOW(window), FALSE);


  // Create a WebView, set it transparent, add it to the window
  WebKitWebView* web_view = web_view = WEBKIT_WEB_VIEW(webkit_web_view_new());
  webkit_web_view_set_transparent(web_view, TRUE);
  gtk_container_add (GTK_CONTAINER(window), GTK_WIDGET(web_view));

  // Load a default page
  webkit_web_view_load_uri(web_view, "http://stackoverflow.com/");

  // Show it and continue running until the window closes
  gtk_widget_grab_focus(GTK_WIDGET(web_view));
  gtk_widget_show_all(window);
  gtk_main();
  return 0;
}

Screenshot!

27
ответ дан 27 November 2019 в 19:28
поделиться

Обычно вы хотите настроить цветовое пространство ARGB для отправки в диспетчер окон. Очевидно, что только оконные менеджеры, которые поддерживают композитинг, смогут воспользоваться этим.

Возможно, вы захотите поговорить с разработчиками скриншотов и compiz, они должны быть в состоянии помочь больше.

1
ответ дан 27 November 2019 в 19:28
поделиться

Еще в Safari 1.3 и 2 было скрытое меню отладки (вызываемое через Терминал: по умолчанию записывают com.apple.Safari IncludeDebugMenu 1 ), в котором есть Прозрачное окно ».

Не уверен, было ли это в WebKit или в Safari.

(В Safari 3 меню отладки, похоже, было заменено меню «Разработка» (включить в настройках> Дополнительно), которое не есть опция прозрачного окна.)

2
ответ дан 27 November 2019 в 19:28
поделиться
Другие вопросы по тегам:

Похожие вопросы: