-
Notifications
You must be signed in to change notification settings - Fork 0
Tut1 Example3
Sung-June, Lim edited this page Oct 12, 2016
·
19 revisions
_tutorials
_tutorial1
...
example3apps
HelloCyhub.py
blocks
MainWindow.py
Cone.py
cyapp.py
cyapp_cfg.py
cymgr.py
cymgr_cfg.py
cycoord.py
cycoord_cfg.py
-
S(Slot) : 'main'의
btn_change_color_random버튼에서clickedsignal과 'cone_view'의on_change_color_randomSlot을 연결
def app_spec():
t = 'Hello Cyhub'
B = [('main', 'MainWindow', [], {}),
('cone_view', 'Cone', [], {})
]
C = []
D = dict()
R = [
('main', 'view', 'cone_view')
]
S = [
('main', 'btn_change_color_random.clicked', 'cone_view', 'on_change_color_random')
]
return t, B, C, D, R, S- 버튼과 연결할
on_change_color_random()Slot 생성 - cyhub에서 Slot 생성은
@cyhub_slot()decorator를 사용
- Cone 색상을 변경 할
btn_change_color_random버튼 생성 - Slot에서 발생하는 Log Message를 출력 할 TextEdit 생성
from PyQt5 import QtWidgets
from cyhub.block import Block_meta, cyhub_slot
class MainWindow(QtWidgets.QMainWindow, metaclass=Block_meta):
def __init__(self, *args, **kwds):
super().__init__(*args, **kwds)
self.log = QtWidgets.QTextEdit()
self.btn_change_color_random = QtWidgets.QPushButton('Change Color (Random)', clicked=self.on_change_color_random)
def initialize(self):
"""
this method is called at end of 'compose_app'
thus, R(reference) like 'self.cone' are available from now (not available in '__init__(..)')
"""
# Organize layout.
cw = QtWidgets.QWidget()
self.setCentralWidget(cw)
cw.setLayout(QtWidgets.QHBoxLayout())
cw.layout().addWidget(self.view.as_widget())
widget_sig_slot = QtWidgets.QWidget()
cw.layout().addWidget(widget_sig_slot)
widget_sig_slot.setLayout(QtWidgets.QVBoxLayout())
widget_sig_slot.layout().addWidget(self.log)
widget_sig_slot.layout().addWidget(self.btn_change_color_random)
# Show.
self.show()
@cyhub_slot()
def on_change_color_random(self):
s = self.log.toPlainText() + 'Color is Changed\n'
self.log.setText(s)-
change_color(r,g,b)method 생성 : 색상을 입력받아 Cone 색상을 변경 -
on_change_color_random()Slot 생성 : random으로 색상 생성하여change_color(r,g,b)호출 - cyhub에서 Slot 생성은
@cyhub_slot()decorator를 사용
from cyhub import cy_vtk
from cyhub.block import Block_meta, cyhub_slot
from random import random
class Cone(cy_vtk.Vtk_image_holder, metaclass=Block_meta):
def __init__(self, *args, **kwds):
super().__init__(*args, **kwds)
self.cone = cy_vtk.actor_cone()
self.ren.AddActor(self.cone)
def change_color(self, r, g, b):
self.cone.GetProperty().SetColor(r, g, b)
# update render
self.view._RenderWindow.Render()
@cyhub_slot()
def on_change_color_random(self):
rgb = [random() for _ in range(3)]
self.change_color(*rgb)이전의 Example과 마찬가지로 Cloud 기반의 Application을 구성하기 위하여 2대의 Machine 환경이 필요합니다. 하나의 Machine에서는 Coordinator를 실행할 것이며, 다른 하나의 Machine에서는 Application을 실행 할 것입니다. 따라서, 2대의 Machine 환경에서 실행 가능하도록 환경이 구축되어 있어야 합니다. (하지만, 편의상 Tutorial 시연을 위해 하나의 Machine에서 Coordinator와 Application 모두 실행 가능)
이전 Example에서 작성한 cycoord_cfg.py, cyapp_cfg.py 파일에서 cycode_prefix의 값을 example3의 위치로 변경하면 됩니다.
cycode_prefix = '_tutorials._tutorial1.example3'- coordinator가 위치한 machine에서 cycoord.py 파일을 실행 합니다.
- application이 위치한 machine에서 cyapp.py 파일을 실행 합니다.
- Remote Rendering이 되고 있는 Block은 좌측 상단에 'R'이 표시 됩니다.


