Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use webkit2gtk with glade? #65

Open
idlesong opened this issue Mar 27, 2020 · 2 comments
Open

How to use webkit2gtk with glade? #65

idlesong opened this issue Mar 27, 2020 · 2 comments

Comments

@idlesong
Copy link

In glade, I added a WebKitWebView, then I want to get this object in my code:

        let builder = gtk::Builder::new_from_resource("/im/idlesong/handybox/window.ui");
        let widget: gtk::ApplicationWindow = builder.get_object("window").expect("Failed to find the window object");
        let webview: WebView = builder.get_object("webview").expect("Failed to find label");

It builded success, but when run:

failed to add UI: .:136:1 Invalid object type 'WebKitWebView'

I searched the web, it seems there are only two related answers,
https://stackoverflow.com/questions/51010820/glade-invalid-object-type-webkitwebview-when-loading-from-file-works-on-gla

https://prognotes.net/2019/12/make-a-gtk-web-browser-with-glade/

But one is C, one is Vala. It's too hard to convert to rust for me. Is there any samples or documents about it? Thanks.

@antoyo
Copy link
Contributor

antoyo commented Mar 27, 2020

Not sure.
Try to call get_type() before you use it.

@ghost
Copy link

ghost commented Jul 18, 2021

Heyo! I'm using Glade on my GTK-rs web browser, and I've got this working.
Firstly, the get_object() function gets an object by its ID/unique instance name. Have you given your WebView widget a name in Glade?
Additionally, if that doesn't work for whatever reason (though, it should), you can create your own WebView instance in Rust, like this:

let web_view_builder = webkit2gtk::WebViewBuilder::new()
        .is_ephemeral(false)
        .automation_presentation_type(webkit2gtk::AutomationBrowsingContextPresentation::Tab);
let web_view = web_view_builder.build();

The webkit2gtk-rs and gtk3-rs documentation books are really useful, so take a look at those on the regular.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants