Skip to content

Tut2 Example1

Sung-June, Lim edited this page Oct 4, 2016 · 2 revisions

File Composition for Tutorial1

_tutorials

_tutorial2

example1

apps

Advanced_SignalSlot.py

blocks

MainWindow.py
Mars.py
Venus.py
Earth.py

cyapp.py
cyapp_cfg.py
cymgr.py
cymgr_cfg.py
cycoord.py
cycoord_cfg.py

Introduction

Application Specification

Advanced_SignalSlot.py

  • t(title) : Application Title은 'Advanced Signal/Slot : Trip around distributed modules'으로 사용
  • B(Block) : 'MainWindow'의 별칭을 'main'으로, 'Mars', 'Venus', 'Earth'의 별칭을 각각 'mars', 'venus, 'earth'으로 사용
  • C(Connectivity) : -
  • D(Data) : -
  • R(Reference) :
    'main'에서 'mars'를 reference로 사용
    'mars'에서 'venus'와 'earth'를 reference로 사용
  • S(Slot) :
    main의 sig_of_main 시그널과 venus의 on_sig_of_main 슬롯 연결
    main의 sig_of_main 시그널과 earth의 on_sig_of_main 슬롯 연결
    earth의 sig_of_earth 시그널과 main의 on_sig_of_earth 슬롯 연결
    earth의 sig_of_earth 시그널과 mars의 on_sig_of_earth 슬롯 연결
def app_spec():
    t = 'Advanced Signal/Slot : Trip around distributed modules'
    B = [('main', 'MainWindow', [], {}),
         ('mars', 'Mars', [], {}),
         ('venus', 'Venus', [], {}),
         ('earth', 'Earth', [], {}),
    ]

    C = []

    D = dict(
        note=dict()
    )

    R = [
        ('main', 'mars', 'mars'),
        ('mars', 'venus', 'venus'),
        ('mars', 'earth', 'earth'),
    ]
    S = [
        ('main', 'sig_of_main', 'venus', 'on_sig_of_main'),
        ('main', 'sig_of_main', 'earth', 'on_sig_of_main'),
        ('earth', 'sig_of_earth', 'main', 'on_sig_of_earth'),
        ('earth', 'sig_of_earth', 'mars', 'on_sig_of_earth'),
    ]
    return t, B, C, D, R, S

Block Implementation

MainWindow.py (Main Block)

  • 모든 Block Class는 metaclass로 Block_meta를 사용
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QPushButton

from cyhub.block import Block_meta, cyhub_slot


class MainWindow(QtWidgets.QWidget, metaclass=Block_meta):

    sig_of_main = QtCore.pyqtSignal('PyQt_PyObject')

    def __init__(self):
        super().__init__()
        layout = QtWidgets.QVBoxLayout()
        self.setLayout(layout)
        layout.addWidget(QPushButton('Trip around planets via Signal/Slot', clicked=self.on_trip))

    def initialize(self):
        self.show()

    @QtCore.pyqtSlot()
    def on_trip(self):
        self.sig_of_main.emit('Hi there... From main')

    @cyhub_slot('PyQt_PyObject')
    def on_sig_of_earth(self, x):
        print('This is main via on_sig_of_earth : ', x)

Mars.py (Block)

  • 모든 Block Class는 metaclass로 Block_meta를 사용
from PyQt5 import QtCore

from cyhub.block import Block_meta, cyhub_slot


class P1(QtCore.QObject, metaclass=Block_meta):
    
    @cyhub_slot('PyQt_PyObject')
    def on_sig_of_earth(self, x):
        print('This is mars via on_sig_of_earth : ', x)

Venus.py (Block)

  • 모든 Block Class는 metaclass로 Block_meta를 사용
from PyQt5 import QtCore

from cyhub.block import Block_meta, cyhub_slot


class P2(QtCore.QObject, metaclass=Block_meta):

    @cyhub_slot('PyQt_PyObject')
    def on_sig_of_main(self, i):
        print('This is venus via sig_of_main : ', i)

Earth.py (Block)

  • 모든 Block Class는 metaclass로 Block_meta를 사용
from PyQt5 import QtCore

from cyhub.block import Block_meta, cyhub_slot


class P3(QtCore.QObject, metaclass=Block_meta):
    
    sig_of_earth = QtCore.pyqtSignal('PyQt_PyObject')
    
    @cyhub_slot('PyQt_PyObject')
    def on_sig_of_main(self, i):
        print('This is earth via sig_of_main : ', i)
        self.sig_of_earth.emit('Hello there... From earth')

How to run a Cloud-App

본 예제를 가장 잘 이해 하기 위해서는 4대의 Machine 환경이 필요합니다. 각각의 Machine에서 Coordinator, Manager1, Manager2, Application을 실행 할 것입니다. 따라서, 4대의 Machine 환경에서 실행 가능하도록 환경이 구축되어 있어야 합니다. (하지만, 편의상 Tutorial 시연을 위해 하나의 Machine에서 Coordinator, Manager1, Manager2, Application 모두 실행 가능)

이전 Example에서 작성한 cycoord_cfg.py, cymgr_cfg.py, cyapp_cfg.py 파일에서 cycode_prefix의 값을 example1의 위치로 변경하면 됩니다.

cycoord_cfg.py / cymgr_cfg.py / cyapp_cfg.py
cycode_prefix = '_tutorials._tutorial2.example1'

App 실행

  • Coordinator가 위치한 machine에서 cycoord.py 파일을 실행 합니다.
  • Manager1이 위치한 machine에서 cymgr.py 파일을 실행합니다.
  • Manager2이 위치한 machine에서 cymgr.py 파일을 실행합니다.
  • Application이 위치한 machine에서 cyapp.py 파일을 실행 합니다.
[Application]

[Application Console]

[Coordinator]

[Manager1]

[Manager2]

Clone this wiki locally