how to use Web Kit widgets ?

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
k0nichiWa
Posts: 10
Joined: Fri May 01, 2020 5:48 pm

how to use Web Kit widgets ?

Post by k0nichiWa »

I haven't worked with QtWebKit, I guess in PySide2 its QWebEngine or something like that

I found some information but it appears to be outdated
https://wiki.freecadweb.org/Code_snippe ... om_webpage

Code: Select all

>>> from PySide import QtGui,QtWebKit
Traceback (most recent call last):
  File "<input>", line 1, in <module>
ImportError: cannot import name 'QtWebKit'
Is there some import I can use to pop-up a QDialog and display some HTML ? Thought this would be an easy way to provide a "Help" button for a Task Panel macro I'm working on

*******

OS: macOS 10.13
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.18.16146 (Git)
Build type: Release
Branch: (HEAD detached at 0.18.4)
Hash: 980bf9060e28555fecd9e3462f68ca74007b70f8
Python version: 3.6.7
Qt version: 5.6.2
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: English/UnitedStates (en_US)
TheMarkster
Veteran
Posts: 5513
Joined: Thu Apr 05, 2018 1:53 am

Re: how to use Web Kit widgets ?

Post by TheMarkster »

This seems to work, but there might be a different preferred way.

Code: Select all

from PySide2.QtWebEngineWidgets import QWebEngineView
mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: how to use Web Kit widgets ?

Post by mario52 »

hi

this run (convert to PySide2)

merci bernd Browser inside task panel

Code: Select all

##https://forum.freecadweb.org/viewtopic.php?f=22&t=47224&sid=0a58cca8ad2a3b2aeff6c1aedd889517
##https://forum.freecadweb.org/viewtopic.php?f=10&t=25189
##08/06/2020
import FreeCAD
import FreeCADGui
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtWebEngineWidgets import QWebEngineView
from PySide2 import QtWebEngine
from PySide2.QtWidgets import *
from PySide2.QtCore import *
from PySide2.QtGui import *

class TransWindow(QtWidgets.QDialog):
    HOME = "https://wiki.freecadweb.org/Macro_Compound_Plus"
    def __init__(self):
        super(TransWindow, self).__init__()
        self.webView = QWebEngineView()
        self.webView.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.addLayout(QtWidgets.QHBoxLayout())
        self.layout.addWidget(self.webView)

    def showEvent(self, event):
        super(TransWindow, self).showEvent(event)
        self.webView.load(QtCore.QUrl(self.HOME))

mw = FreeCADGui.getMainWindow()
d = QtWidgets.QDockWidget()
d.setWidget(TransWindow())
#mw.addDockWidget(QtCore.Qt.LeftDockWidgetArea, d)
mw.addDockWidget(QtCore.Qt.RightDockWidgetArea, d)

#### other copy content web page ######
###https://forum.freecadweb.org/viewtopic.php?f=22&t=47224&sid=0a58cca8ad2a3b2aeff6c1aedd889517
#import PySide2
#from PySide2 import (QtWidgets, QtCore, QtGui)
#import requests
#
##contentPage = requests.get("https://wiki.freecadweb.org/Macro_Compound_Plus").text
##memo        = PySide2.QtGui.QClipboard()    # Clipboard
##memo.setText(contentPage)                   # copy contentPage on Clipboard
#
##for i in content.split("\n"):               # list page to line
##    print(i)
#
####################################

#### other ##########################
#
#
#import WebGui
#WebGui.openBrowser("https://wiki.freecadweb.org/Macro_Compound_Plus#Choice")
#
####################################
mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
k0nichiWa
Posts: 10
Joined: Fri May 01, 2020 5:48 pm

Re: how to use Web Kit widgets ?

Post by k0nichiWa »

QTextBrowser turns out was good enough for me ... it can display most HTML tags, not complicated CSS

it think it was PySide.QtGui.QTextBrowser

called setHtml(" ... html string ... ")
User avatar
bernd
Veteran
Posts: 12851
Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:

Re: how to use Web Kit widgets ?

Post by bernd »

code without comments and not needed imports less new lines:

Code: Select all

import FreeCADGui
from PySide2 import QtCore
from PySide2 import QtGui
from PySide2 import QtWidgets
from PySide2.QtWebEngineWidgets import QWebEngineView

class TransWindow(QtWidgets.QDialog):
    HOME = "https://wiki.freecadweb.org/Macro_Compound_Plus"
    def __init__(self):
        super(TransWindow, self).__init__()
        self.webView = QWebEngineView()
        self.webView.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)
        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.addLayout(QtWidgets.QHBoxLayout())
        self.layout.addWidget(self.webView)
    def showEvent(self, event):
        super(TransWindow, self).showEvent(event)
        self.webView.load(QtCore.QUrl(self.HOME))

mw = FreeCADGui.getMainWindow()
d = QtWidgets.QDockWidget()
d.setWidget(TransWindow())
mw.addDockWidget(QtCore.Qt.RightDockWidgetArea, d)

runs on :

Code: Select all

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.22130 (Git)
Build type: Release
Branch: master
Hash: dc65b055e5143a7d7349520da466d4d722df57e8
Python version: 3.6.8
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0
Locale: German/Switzerland (de_CH)

mario52
Veteran
Posts: 4692
Joined: Wed May 16, 2012 2:13 pm

Re: how to use Web Kit widgets ?

Post by mario52 »

hi

thanks

mario
Maybe you need a special feature, go into Macros_recipes and Code_snippets, Topological_data_scripting.
My macros on Gist.github here complete macros Wiki and forum.
Post Reply