Need help, or want to share a macro? Post here!
k0nichiWa
Posts: 10 Joined: Fri May 01, 2020 5:48 pm
Post
by k0nichiWa » Wed Jun 03, 2020 10:10 pm
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
Post
by TheMarkster » Sat Jun 06, 2020 12:29 am
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
Post
by mario52 » Mon Jun 08, 2020 2:19 pm
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
k0nichiWa
Posts: 10 Joined: Fri May 01, 2020 5:48 pm
Post
by k0nichiWa » Mon Jun 08, 2020 2:44 pm
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 ... ")
bernd
Veteran
Posts: 12851 Joined: Sun Sep 08, 2013 8:07 pm
Location: Zürich, Switzerland
Contact:
Post
by bernd » Fri Aug 07, 2020 7:18 am
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
Post
by mario52 » Sat Aug 08, 2020 8:58 am
hi
thanks
mario