wxWebView::LoadURL() in wxPHP

This forum can be used to talk about general design strategies, new ideas and questions in general related to wxWidgets. If you feel your questions doesn't fit anywhere, put it here.
Palloy
Earned a small fee
Earned a small fee
Posts: 10
Joined: Wed Oct 11, 2017 3:16 am

wxWebView::LoadURL() in wxPHP

Postby Palloy » Wed Oct 11, 2017 3:57 am

I am using wxPHP (wrappers built for PHP 5.6.39 and wxWidgets 3.0.0.2) on Ubuntu 16.04 (64).
I have been using it successfully for a couple of years now.
First time using wxWebView control though.
I am getting seg faults and this assert error with wxWebView::LoadURL()
Is this the correct way of doing it (procedural style)? - seems simple enough.

Code: Select all

<?php

$html_box = new wxWebView($frame, wxID_ANY, wxDefaultPosition, new wxSize(1024, 600));

print "entering LoadURL()\n";
$html_box->LoadURL($url_box->GetValue());
print "leaving LoadURL()\n";
while($html_box->IsBusy() === true)
    {   usleep(100000);   // wait for LoadURL() to finish
        print "Waiting\n";
    }
$frame->SetTitle($html_box->GetCurrentTitle());

?>



Produces this Terminal output:

Code: Select all

entering LoadURL()
../include/wx/event.h(1132): assert "m_event.m_propagationLevel > 0" failed in wxPropagateOnce(): shouldn't be used unless ShouldPropagate()!



wxPHP is badly in need of some support as JG is too busy these days and PHP 5 has gone end-of-life.

User avatar
doublemax
Moderator
Moderator
Posts: 11384
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWebView::LoadURL() in wxPHP

Postby doublemax » Wed Oct 11, 2017 5:26 am

I don't know wxPHP, but in C++ you need to use wxWebView::New() to create a new instance of wxWebView.

And so does this wxPHP sample:
https://github.com/wxphp/wxphp/blob/mas ... ebview.php
Use the source, Luke!

Palloy
Earned a small fee
Earned a small fee
Posts: 10
Joined: Wed Oct 11, 2017 3:16 am

Re: wxWebView::LoadURL() in wxPHP

Postby Palloy » Wed Oct 11, 2017 6:53 am

Doesn't

Code: Select all

$html_box = new wxWebView($frame, wxID_ANY, wxDefaultPosition, new wxSize(1024, 600));
do that?

User avatar
doublemax
Moderator
Moderator
Posts: 11384
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWebView::LoadURL() in wxPHP

Postby doublemax » Wed Oct 11, 2017 9:23 am

No. wxWebView is "special".

The sample uses

Code: Select all

$this->m_webView = wxWebView::NewMethod( $this, wxID_ANY, "http://wxphp.org/" );

So you should try this.
Use the source, Luke!

Palloy
Earned a small fee
Earned a small fee
Posts: 10
Joined: Wed Oct 11, 2017 3:16 am

Re: wxWebView::LoadURL() in wxPHP

Postby Palloy » Thu Oct 12, 2017 4:53 am

When I do:

Code: Select all

$htmlbox = new wxWebView::NewMethod($frame, wxID_ANY, "http://palloy.earth");

PHP gives a syntax error "unexpected 'NewMethod', expecting variable or $"
Changing it to "New", PHP editor highlights it as it does "new", so is not recognising it as a Method, then it errors as before
I have never come across a Method called New before.

From http://docs.wxwidgets.org/trunk/classwx_web_view.html I am assuming this would work:

Code: Select all

$html_box = new wxWebView::New(wxWEBVIEW_BACKEND_WEBKIT);
$html_box->Create($frame, wxID_ANY, "http://palloy.earth", wxDefaultPosition, $html_box_size);

but it doesn't - it gives the same error as above.

I am completely baffled.
Whatever the correct word for "new" is in PHP, it is taking "New" as being one of those, instead of a method.

Palloy
Earned a small fee
Earned a small fee
Posts: 10
Joined: Wed Oct 11, 2017 3:16 am

Re: wxWebView::LoadURL() in wxPHP

Postby Palloy » Thu Oct 12, 2017 5:24 am

(A bit like the thousand monkeys typing the works of Shakespeare.)

Code: Select all

$html_box = wxWebView::NewMethod(wxWEBVIEW_BACKEND_WEBKIT);
$html_box->Create($frame, wxID_ANY, "http://palloy.earth", wxDefaultPosition, $html_box_size);


produces in Terminal:

Code: Select all

Fatal error: Call to a member function Create() on null in /home/.../test.wxphp on line 37
./bin//wxphp: line 8: 31678 Segmentation fault      (core dumped) LD_LIBRARY_PATH=./lib ./bin/php -d extension=wxwidgets.so "$@"

so we seem to have got past the first part of construction of a WebView control even if it only constructed a null. :?

Palloy
Earned a small fee
Earned a small fee
Posts: 10
Joined: Wed Oct 11, 2017 3:16 am

Re: wxWebView::LoadURL() in wxPHP

Postby Palloy » Thu Oct 12, 2017 5:50 am

null seems to be returned if the backend is not available.
So maybe it is not in the build I have?
That will put an end to the project.

User avatar
doublemax
Moderator
Moderator
Posts: 11384
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWebView::LoadURL() in wxPHP

Postby doublemax » Thu Oct 12, 2017 8:58 am

Code: Select all

$htmlbox = new wxWebView::NewMethod($frame, wxID_ANY, "http://palloy.earth");
There should be no "new" in this line. Just:

Code: Select all

$htmlbox = wxWebView::NewMethod($frame, wxID_ANY, "http://palloy.earth");


In the other version, try without the backend parameter.

Code: Select all

$html_box = wxWebView::New();


Also: Try building the "webview" C++ sample of the wxWidgets version you compiled wxPHP against to check if webview is enabled and working there.
Use the source, Luke!

Palloy
Earned a small fee
Earned a small fee
Posts: 10
Joined: Wed Oct 11, 2017 3:16 am

Re: wxWebView::LoadURL() in wxPHP

Postby Palloy » Fri Oct 13, 2017 2:16 pm

Finally , this works:

Code: Select all

$html_box = wxWebView::NewMethod();
$html_box->Create($frame, wxID_ANY) ;


The frame gets drawn correctly.
Then I type my URL into $url_box and press ENTER, which triggers the event wxEVT_TEXT_ENTER, which leads to the LoadURL().

I wasn't happy with this as a solution:

Code: Select all

while($html_box->IsBusy() === true)
{   usleep(100000);   //wait 0.1 sec
        print "Waiting\n";
}

But the documentation says to cater for the event wxEVT_WEBVIEW_LOADED, but that doesn't trigger until AFTER you want to do something (wait).
In any case, it goes into a permanent loop.

User avatar
doublemax
Moderator
Moderator
Posts: 11384
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wxWebView::LoadURL() in wxPHP

Postby doublemax » Fri Oct 13, 2017 2:24 pm

Code: Select all

while($html_box->IsBusy() === true)
{   usleep(100000);   //wait 0.1 sec
        print "Waiting\n";
}

In any case, it goes into a permanent loop.
The wxWidgets event system is single threaded. And while the code is sleeping, nothing else is happening because the event loop is never active.

Remove this code completely. If there is anything you need to do *after* the page is fully loaded, do it in the event handler for wxEVT_WEBVIEW_LOADED.
Use the source, Luke!

Palloy
Earned a small fee
Earned a small fee
Posts: 10
Joined: Wed Oct 11, 2017 3:16 am

Re: wxWebView::LoadURL() in wxPHP [SOLVED]

Postby Palloy » Sat Oct 14, 2017 1:33 am

OK, finally wrestled the thing into submission. =D>
For the record:

Code: Select all

$html_box = wxWebView::NewMethod();
$html_box->Create($frame, wxID_ANY, "http://palloy.earth", wxDefaultPosition, new wxSize(1024, 600));
$html_box->Connect(wxEVT_WEBVIEW_LOADED, array(wxID_TOP, webpage_loaded));

// ==================================================
function url_entered ()
{   global $html_box, $url_box ;
    $html_box->LoadURL($url_box->GetValue());
}
// ==================================================
function webpage_loaded ()
{   global $frame, $html_box, $text_box ;
    $text_box->SetValue($html_box->GetPageSource());
    $frame->SetTitle($html_box->GetCurrentTitle());
}


Thanks for your patience with me, Doublemax.


Return to “General Development”

Who is online

Users browsing this forum: Google [Bot] and 3 guests