Well, no need to look up how to get the WebEngineView.  Here it is:

from leo.core.leoQt import has_WebEngineWidgets
if has_WebEngineWidgets:
    from leo.core.leoQt import QtWebEngineWidgets
    QWebEngineView = QtWebEngineWidgets.QWebEngineView
    # If you have existing code that uses QWebView:
    QWebView =  QWebEngineView

On Wednesday, February 16, 2022 at 9:38:13 AM UTC-5 tbp1...@gmail.com wrote:

> For those following this thread and who want to use the WebEngineView with 
> PyQt6, my suggestion above has now made its way into the devel branch. You 
> can look the the code for VR3 or Freewin (in LeoPyRef.leo) to see ways to 
> import and use it.
>
> Even though this lets you import the WebEngineView without needing to know 
> whether Leo is using PyQt5 or 6, there are still changes with PyQt6 that 
> could bite you, especially in the paths to some of the enums and 
> constants.  So you may still need to have some version-conditional code 
> paths to set them up.
>
> On Monday, February 14, 2022 at 12:05:47 PM UTC-5 tbp1...@gmail.com wrote:
>
>> As an alternative to the approach in my previous message,  Qt5 also has a 
>> QtWebEngineWidgets module.  It isn't used by current code because QWebView 
>> is actually a QWebEngineView under the covers.  But we could add importing  
>> QtWebEngineWidgets for Qt5 as well as Qt6. Then leo.core.leoQt could return 
>> either the Qt5 or Qt6 version of QWebEngineView, no version tests 
>> required.  QWebView could be aliased to this QWebEngineView for use by 
>> existing code.
>>
>> IMHO, this would be a better approach.  There will still be the problem 
>> that some of the Qt6 WebEngineView's enums have a different classpath, but 
>> we've dealt with that for other Qt classes already.
>>
>> At any rate, any one of these three approaches gets VR3 and Freewin 
>> working again.  Hurray!
>>
>> On Monday, February 14, 2022 at 11:55:42 AM UTC-5 tbp1...@gmail.com 
>> wrote:
>>
>>> I have succeeded with a slightly different approach:
>>>
>>> 1.  In LeoQt6.py:
>>>
>>> # Must import this before creating the GUI
>>> try:
>>>     from PyQt6 import QtWebEngineWidgets
>>> except ImportError:
>>>     print('No QtWebEngineWidgetsInstall with python3 -m pip install 
>>> --upgrade ')
>>>
>>> 2.  Add a new try: block to existing VR3 code:
>>>
>>> QWebView = None
>>> if isQt6:
>>>     try:
>>>         from leo.core.leoQt6 import QtWebEngineWidgets
>>>         QWebView = QtWebEngineWidgets.QWebEngineView
>>>     except ImportError:
>>>         if not g.unitTesting:
>>>             g.trace("Can't import Qt6 QtWebEngineWidgets")
>>>     except AttributeError:
>>>         if not g.unitTesting:
>>>             g.trace('No QWebView')
>>>     except Exception as e:
>>>         g.trace(e)
>>> else:
>>>     try:
>>>         from leo.core.leoQt import QtWebKitWidgets
>>>         QWebView = QtWebKitWidgets.QWebView
>>>     except ImportError:
>>>         if not g.unitTesting:
>>>             g.trace("Can't import QtWebKitWidgets")
>>>     except AttributeError:
>>>         if not g.unitTesting:
>>>             g.trace('No QWebView')
>>>     except Exception as e:
>>>         g.trace(e)
>>>
>>> This gets VR3 to render as intended.  However, I'd like to see something 
>>> in leoQt that makes it unnecessary to test for Qt6, but only for 
>>> QtWebEngineWidgets. See next message for more on this.
>>> On Monday, February 14, 2022 at 11:29:40 AM UTC-5 Edward K. Ream wrote:
>>>
>>>> On Monday, February 14, 2022 at 9:59:39 AM UTC-6 Edward K. Ream wrote:
>>>>
>>>> > I have just created #2415 
>>>> <https://github.com/leo-editor/leo-editor/issues/2415> for this. The 
>>>> mind boggles.
>>>>
>>>> PR #2416 <https://github.com/leo-editor/leo-editor/pull/2416> (the 
>>>> ekr-web-engine branch) suggests the way forward.  At startup, *for 
>>>> PyQt6 only*, LeoApp.createQtGui imports QtWebEngineWidgets as follows:
>>>>
>>>> from PyQt6 import QtWebEngineWidgets as qt6_QtWebEngineWidgets
>>>> self.qt6_QtWebEngineWidgets = qt6_QtWebEngineWidgets
>>>>
>>>>  So instead of trying to import QtWebEngineWidgets, VR3 could just test 
>>>> and use g.app.qt6_QtWebEngineWidgets.
>>>>
>>>> Does this work for you?
>>>>
>>>> Edward
>>>>
>>>

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to leo-editor+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/leo-editor/daad9e89-d02d-46ed-9d20-670b27624d8an%40googlegroups.com.

Reply via email to