pyside2_vue_template

Install

    pip3 install pyside2
    cd frontend
    yarn (npm -i)
    # Need to install vue and its dependencies, qwebchannel

Debug

    cd frontend
    yarn serve (npm run serve)
    cd ..
    python3 mainwindow.py

Usage

The Comm class is used to keep communication between JavaScript and Python. You can add some signals and slots just like that how PySide2 is used.

In the template, A slot which name is log is added to show how to use this in Python.

At the front end, an webchannel is generated by the qwebchannl library. You can use the channel module to get the communication object. The channel module export a Promise, it'll resolve an object which contains some functions. The name of these functions are same as the name of the slots defined in the Comm class. So just call it, then the Python side will call the corresponded slot.

You can also define some signals on the Python side, then emit them. At the front end, the object which the channel module exported will contains the signals object in it. The signal object contains a function named connect, and the argument of the function is an other function. The other function is like the slot in PySide2. When the correspond signal is emitted, the function (slot) is called. The work pattern is similar to the work pattern in PySide2.

Notice

  • Test in windows system. If run this in the terminal of the Qt IDE, the print function may echo nothing at the slots until the program stop. So you may need to use flush=True in the **kwargs of function print.