PySide2.QtWebEngineWidgets

Post here for help on using FreeCAD's graphical user interface (GUI).
Forum rules
and Helpful information
IMPORTANT: Please click here and read this first, before asking for help

Also, be nice to others! Read the FreeCAD code of conduct!
Post Reply
smsyu
Posts: 2
Joined: Fri Oct 25, 2019 2:14 am

PySide2.QtWebEngineWidgets

Post by smsyu »

Hello, when I was doing FreeCAD development, I found that PySide was repackaged and used PySide2, but PySide2 did not have PySide2.QtWebEngineWidgets, such a module. Because I need to use these modules when doing development, but only three modules QtGui, QtCore, QtWidgets. In addition, I re-installed PySide2 in FreeCAD (pip install PySide2 == 5.12) and can not be introduced in FreeCAD. Environment: windows10, FreeCAD version: 0.18.
Question 1: Who can give a detailed introduction to why PySide has fewer modules in FreeCAD.
Question 2: Under the premise of not using the web workbench, I want to open the webpage window in FreeCAD.
mario52
Veteran
Posts: 4696
Joined: Wed May 16, 2012 2:13 pm

Re: PySide2.QtWebEngineWidgets

Post by mario52 »

hi

maybe

Code: Select all

pip install PyQtWebEngine
https://stackoverflow.com/questions/511 ... inewidgets
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.
mario52
Veteran
Posts: 4696
Joined: Wed May 16, 2012 2:13 pm

Re: PySide2.QtWebEngineWidgets

Post by mario52 »

hi

try this "upgrade of my old macro" and work with:

from PySide2.QtWebEngineWidgets import QWebEngineView


the page displayed is the original first post

Code: Select all

# -*- coding: utf-8 -*-
from __future__ import unicode_literals
#
"""
***************************************************************************
*   Copyright (c) 2019 <mario52>                                          *
*                                                                         *
*   This file is a supplement to the FreeCAD CAx development system.      *
*                                                                         *
*   This program is free software; you can redistribute it and/or modify  *
*   it under the terms of the GNU Lesser General Public License (LGPL)    *
*   as published by the Free Software Foundation; either version 2 of     *
*   the License, or (at your option) any later version.                   *
*   for detail see the LICENCE text file.                                 *
*                                                                         *
*   This software is distributed in the hope that it will be useful,      *
*   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
*   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
*   GNU Library General Public License for more details.                  *
*                                                                         *
*   You should have received a copy of the GNU Library General Public     *
*   License along with this macro; if not, write to the Free Software     *
*   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
*   USA                                                                   *
***************************************************************************
*           WARNING! All changes in this file will be lost and            *  
*                  may cause malfunction of the program                   *
***************************************************************************
"""
#
#OS: Windows 10 (10.0)
#Word size of OS: 64-bit
#Word size of FreeCAD: 64-bit
#Version: 0.19.18615 (Git)
#Build type: Release
#Branch: master
#Hash: a801ff5a236d9275c2dc184db5a457589b3eabc4
#Python version: 3.6.7
#Qt version: 5.12.1
#Coin version: 4.0.0a
#OCC version: 7.3.0
#

__title__="Titre"
__author__ = "Mario52"
__url__     = "http://www.freecadweb.org/index-fr.html"
__version__ = "00.02"
__date__    = "25/10/2019"

import PySide2
from PySide2 import QtCore, QtGui, QtWidgets

####import for WebPage
from PySide2.QtWebEngineWidgets import QWebEngineView
from PySide2 import  QtUiTools, QtNetwork
from PySide2.QtCore import QUrl
####

import Draft, Part, FreeCAD, math, PartGui, FreeCADGui, FreeCAD, os
from math import sqrt, pi, sin, cos, asin
from FreeCAD import Base

try:
    _fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
    def _fromUtf8(s):
        return s

try:
    _encoding = QtGui.QApplication.UnicodeUTF8
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
    def _translate(context, text, disambig):
        return QtGui.QApplication.translate(context, text, disambig)
       
class Ui_MainWindow(object):

    def __init__(self):
        #self.path      = FreeCAD.ConfigGet("AppHomePath")
        self.path       = FreeCAD.ConfigGet("UserAppData")

    def setupUi(self, MainWindow):
        self.window = MainWindow
#______________________________________________________________________________________
# mettre le code ici dessous #_________________________________________________________
#______________________________________________________________________________________
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(800, 600)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))

        self.webView = QWebEngineView(self.centralwidget)
        self.webView.setGeometry(QtCore.QRect(90, 40, 551, 411))

        font = QtGui.QFont()
        font.setFamily(_fromUtf8("MS Shell Dlg 2"))

        self.webView.setFont(font)
        self.webView.setUrl(QtCore.QUrl(_fromUtf8("http://forum.freecadweb.org/viewtopic.php?f=22&t=15881"))) # url your question
        self.webView.setObjectName(_fromUtf8("webView"))



        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        MainWindow.setWindowFlags(PySide2.QtCore.Qt.WindowStaysOnTopHint)        # PySide cette fonction met la fenetre en avant


    print( "wait little")
#______________________________________________________________________________________
# mettre le code ici dessus  #_________________________________________________________
#______________________________________________________________________________________

MainWindow = QtWidgets.QWidget()    #PySide2
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()

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.
smsyu
Posts: 2
Joined: Fri Oct 25, 2019 2:14 am

Re: PySide2.QtWebEngineWidgets

Post by smsyu »

Thank you very much for your reply, but still have not solved my problem.
I have installed QtWebEngineWidgets and QtWebEngine (only I am from China, China's network can not directly pip install QtWebEngine. I can only download the complete PySide2 through the image) And there are modules in my FreeCAD 0.18\bin\Lib\site-packages\PySide2 path, but it still reports an error: ModuleNotFoundError: No module named 'PySide2.QtWebEngineWidgets'.
mario52
Veteran
Posts: 4696
Joined: Wed May 16, 2012 2:13 pm

Re: PySide2.QtWebEngineWidgets

Post by mario52 »

hi

the macro run in

OS: Windows 10 (10.0)
Word size of OS: 64-bit
Word size of FreeCAD: 64-bit
Version: 0.19.18615 (Git)
Build type: Release
Branch: master
Hash: a801ff5a236d9275c2dc184db5a457589b3eabc4
Python version: 3.6.7
Qt version: 5.12.1
Coin version: 4.0.0a
OCC version: 7.3.0

without installation supplementary Python or Qt or other ... just the FreeCAD basic (uncompressed and used)
try https://github.com/FreeCAD/FreeCAD/rele ... g/0.19_pre

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