JS에서 Python 호출하기
PylonAPI 소개
PyloidAPI
클래스는 JavaScript와 Python 간의 상호 작용을 가능하게 하는 핵심 구성 요소입니다.
PyloidAPI 속성
PyloidAPI 클래스는 다음과 같은 중요한 속성들을 가지고 있습니다:
window
: BrowserWindow 인스턴스를 참조합니다.app
: Pyloid 애플리케이션 인스턴스를 참조합니다.window_id
: 브라우저 창의 고유 식별자입니다.
Bridge 데코레이터 사용하기
PyloidAPI
클래스는 Bridge
데코레이터와 함께 사용되어 Python 메서드를 JavaScript에서 호출할 수 있게 합니다.
Bridge 데코레이터 매개변수
Bridge
데코레이터는 다음 매개변수를 사용할 수 있습니다:
result
: 반환 타입을 지정합니다.args
: 인수 타입을 지정합니다.
Python에서 JavaScript API 설정하기
from pyloid import Pyloid, PyloidAPI, Bridge
app = Pyloid("Pyloid-App")
class CustomAPI(PyloidAPI):
@Bridge(str, result=str)
def echo(self, message):
return f"Python에서 받은 메시지: {message}"
# 메인 윈도우 생성
window = app.create_window(
title="Pyloid 브라우저",
js_apis=[CustomAPI()],
)
window.load_file("index.html")
window.show()
window.focus()
app.run()
Last updated