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

HtmlWindow.OnOpeningURL > REDIRECT #1068

Closed
RobinD42 opened this Issue Oct 31, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@RobinD42
Copy link
Member

RobinD42 commented Oct 31, 2018

Operating system: any
wxPython version & source: 4.0.3
Python version & source: any

Description of the problem:

See: https://groups.google.com/d/msg/wxpython-users/wS93sD14GzQ/HBjUR1OMCwAJ

Hello everyone,

in wxPython 3 we used the following code to redirect image links:

def OnOpeningURL(self, htmlUrlType, url):
    if (
        htmlUrlType == HTML_URL_IMAGE and
        (self.basePath is not None) and
        not url.startswith(self.basePath)
    ):
        return self.basePath + "/" + url
    else:
        return HTML_OPEN

wxPython 4 now raises

TypeError: invalid result from HtmlWindow.OnOpeningURL(), a member of enum 'HtmlOpeningStatus' is expected not 'unicode'

From reading the docs OnOpeningURL has a fourth parameter redirect which is a Pointer to String variable that must be filled with an URL. How do i use this? I tried

        redirect = self.basePath + "/" + url
        return HTML_REDIRECT
    else:
        return HTML_OPEN

but with no success.

How is the correct way of handling the redirect in wxPython 4?

--
TIA,
Torsten

@RobinD42

This comment has been minimized.

Copy link
Member

RobinD42 commented Nov 1, 2018

Fixed by #1069

@RobinD42 RobinD42 closed this Nov 1, 2018

@topic2k

This comment has been minimized.

Copy link
Contributor

topic2k commented Jan 19, 2019

I've tested again with 4.0.4, but still no success.

The migration guide for OnOpeningURL says

In Phoenix this has been changed to a simpler wrapper implementation which requires that both an enum value and a string be returned as a tuple

If i do that, it raises a TypeError
TypeError: invalid result from HtmlWindow.OnOpeningURL(), a member of enum 'HtmlOpeningStatus' is expected not 'tuple'

From the documentation for HtmlWindow.OnOpeningURL:

Return type:

wx.html.HtmlOpeningStatus

  • wx.html.HTML_OPEN: Open the URL.
  • wx.html.HTML_BLOCK: Deny access to the URL, wx.html.HtmlParser.OpenURL will return None.
  • wx.html.HTML_REDIRECT: Don’t open url, redirect to another URL. OnOpeningURL must fill redirect with the new URL. OnOpeningURL will be called again on returned URL.

Just returning HTML_REDIRECT will call OnOpeningURL again with an empty url.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment