Created
February 1, 2019 12:19
-
-
Save narodnik/9df8d6a4ff199cbe4ca938a8480728fa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide2.QtCore import QObject, Signal, Property, QUrl | |
from PySide2.QtQml import QQmlApplicationEngine | |
from PySide2.QtWebEngine import QtWebEngine | |
from PySide2.QtWidgets import QApplication | |
import sys | |
class SourceTextProperty(QObject): | |
def __init__(self, text): | |
QObject.__init__(self) | |
self._source_text = text | |
def _text(self): | |
return self._source_text | |
def _set_text(self, text): | |
self._source_text = text | |
@Signal | |
def text_changed(self): | |
print("text changed") | |
text = Property(str, _text, _set_text, notify=text_changed) | |
def main(): | |
app = QApplication([]) | |
QtWebEngine.initialize() | |
engine = QQmlApplicationEngine() | |
source_text_property = SourceTextProperty(open('sample.md').read()) | |
engine.rootContext().setContextProperty('source_text', source_text_property) | |
engine.load(QUrl.fromLocalFile('view.qml')) | |
if not engine.rootObjects(): | |
return -1 | |
source_text_property.text = 'hello' | |
return app.exec_() | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment