Beispiel #1
0
def test_run_3():
    with qt_multiprocessing.AppEventLoop() as loop:
        app = QtWidgets.QApplication([])

        QtManager.register('Label', QtWidgets.QLabel)
        mngr = QtManager()
        mngr.start()

        # Create the proxy label
        lbl = mngr.Label("Hello")
        lbl.show()

        widg = QtWidgets.QDialog()
        lay = QtWidgets.QFormLayout()
        widg.setLayout(lay)

        # Form
        inp = QtWidgets.QLineEdit()
        btn = QtWidgets.QPushButton('Set Text')
        lay.addRow(inp, btn)

        def set_text():
            value = inp.text()
            lbl.setText(value)
            # loop.add_var_event('label', 'setText', value)

        btn.clicked.connect(set_text)

        widg.show()

        app.exec_()
Beispiel #2
0
def run_manual():
    app = QtWidgets.QApplication([])
    mp_loop = qt_multiprocessing.AppEventLoop(initialize_process=create_process_widgets)
    print("Main PID:", os.getpid())

    widg = QtWidgets.QDialog()
    lay = QtWidgets.QFormLayout()
    widg.setLayout(lay)

    # Form
    inp = QtWidgets.QLineEdit()
    btn = QtWidgets.QPushButton('Set Text')
    lay.addRow(inp, btn)

    def set_text():
        text = inp.text()
        mp_loop.add_var_event('label', 'setText', text)

        # The label does not exist in this process at all. Can only access by string names
        print('Set Label text', text + '.')

        # `print_pid` will run in a separate process and print the pid.
        mp_loop.add_var_event('label', 'print_pid')

    btn.clicked.connect(set_text)

    widg.show()

    # Run the multiprocessing event loop
    mp_loop.start()

    # Run the application event loop
    app.exec_()

    # Quit the multiprocessing event loop when the app closes
    mp_loop.close()
Beispiel #3
0
import time

import qt_multiprocessing
from qtpy import QtWidgets


def make_widgets():
    label = QtWidgets.QLabel("hello")
    label.show()
    return {'label': label}


if __name__ == '__main__':
    with qt_multiprocessing.AppEventLoop(
            initialize_process=make_widgets) as loop:
        app = QtWidgets.QApplication([])

        widg = QtWidgets.QDialog()
        lay = QtWidgets.QFormLayout()
        widg.setLayout(lay)

        # Form
        inp = QtWidgets.QLineEdit()
        btn = QtWidgets.QPushButton('Set Text')
        lay.addRow(inp, btn)

        def set_text():
            loop.add_var_event('label', 'setText', inp.text())

        btn.clicked.connect(set_text)
Beispiel #4
0
import mp_event_loop
import qt_multiprocessing
from qtpy import QtWidgets


class LabelProxy(qt_multiprocessing.WidgetProxy):
    PROXY_CLASS = QtWidgets.QLabel
    GETTERS = ['text']


if __name__ == '__main__':
    with qt_multiprocessing.AppEventLoop() as loop:
        mp_event_loop.Proxy.__loop__ = loop

        app = QtWidgets.QApplication([])

        lbl = LabelProxy("Hello")

        widg = QtWidgets.QDialog()
        lay = QtWidgets.QFormLayout()
        widg.setLayout(lay)

        # Form
        inp = QtWidgets.QLineEdit()
        btn = QtWidgets.QPushButton('Set Text')
        lay.addRow(inp, btn)

        def set_text():
            lbl.setText(inp.text())

        btn.clicked.connect(set_text)
"""
Test to make sure the multiprocessing event loop closes automatically.
"""
import mp_event_loop
import qt_multiprocessing
from qtpy import QtWidgets


class LabelProxy(qt_multiprocessing.WidgetProxy):
    PROXY_CLASS = QtWidgets.QLabel
    GETTERS = ['text']


if __name__ == '__main__':
    loop = qt_multiprocessing.AppEventLoop()
    qt_multiprocessing.WidgetProxy.__loop__ = loop
    loop.start()

    app = QtWidgets.QApplication([])

    lbl = LabelProxy("Hello")

    widg = QtWidgets.QDialog()
    lay = QtWidgets.QFormLayout()
    widg.setLayout(lay)

    # Form
    inp = QtWidgets.QLineEdit()
    btn = QtWidgets.QPushButton('Set Text')
    lay.addRow(inp, btn)