本文整理汇总了Python中PyQt5.QtQuick.QQuickView.rootContext方法的典型用法代码示例。如果您正苦于以下问题:Python QQuickView.rootContext方法的具体用法?Python QQuickView.rootContext怎么用?Python QQuickView.rootContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtQuick.QQuickView
的用法示例。
在下文中一共展示了QQuickView.rootContext方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootContext [as 别名]
def run():
signal.signal(signal.SIGINT, signal.SIG_DFL)
app = QGuiApplication(sys.argv)
view = QQuickView()
view.setTitle('Hot reloading demo')
qml_engine = view.rootContext().engine()
qml_engine.addImportPath(lib_dir_path)
notifier = HotReloadNotifier(demo_dir_path, qml_engine, parent=app)
view.rootContext().setContextProperty('hotReloadNotifier', notifier)
qml_url = QUrl.fromLocalFile(os.path.join(demo_dir_path, 'Demo.qml'))
view.setSource(qml_url)
view.show()
exit_code = app.exec_()
# notifier.stop() # seems like this is not needed
sys.exit(exit_code)
示例2: MainWindow
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootContext [as 别名]
class MainWindow(QtCore.QObject):
def __init__(self):
QtCore.QObject.__init__(self)
self._controller = Controller()
self.view = QQuickView()
full_path = os.path.realpath(__file__)
folder = os.path.dirname(full_path)
qml_file = os.path.join(folder, 'qml', 'App.qml')
qml_qurl = QtCore.QUrl.fromLocalFile(qml_file)
self.view.setSource(qml_qurl)
# Add context properties to use this objects from qml
rc = self.view.rootContext()
rc.setContextProperty('controller', self._controller)
def show(self):
self.view.show()
示例3: main
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootContext [as 别名]
def main():
app = QGuiApplication(sys.argv)
app.setApplicationName('InfiniteCopy')
openDataBase()
view = QQuickView()
clipboardItemModel = ClipboardItemModel()
clipboardItemModel.create()
filterProxyModel = QSortFilterProxyModel()
filterProxyModel.setSourceModel(clipboardItemModel)
clipboard = Clipboard()
clipboard.setFormats([
mimeText,
mimeHtml,
mimePng,
mimeSvg
])
clipboard.changed.connect(clipboardItemModel.addItem)
engine = view.engine()
imageProvider = ClipboardItemModelImageProvider(clipboardItemModel)
engine.addImageProvider("items", imageProvider)
context = view.rootContext()
context.setContextProperty('clipboardItemModel', clipboardItemModel)
context.setContextProperty('clipboardItemModelFilterProxy', filterProxyModel)
context.setContextProperty('clipboard', clipboard)
view.setSource(QUrl.fromLocalFile('qml/MainWindow.qml'))
view.setGeometry(100, 100, 400, 240)
view.show()
engine.quit.connect(QGuiApplication.quit)
return app.exec_()
示例4: QVariant
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootContext [as 别名]
return animal.type()
if role == self.SizeRole:
return animal.size()
return QVariant()
def roleNames(self):
return self._roles
if __name__ == '__main__':
import sys
app = QGuiApplication(sys.argv)
model = AnimalModel()
model.addAnimal(Animal("Wolf", "Medium"))
model.addAnimal(Animal("Polar bear", "Large"))
model.addAnimal(Animal("Quoll", "Small"))
view = QQuickView()
view.setResizeMode(QQuickView.SizeRootObjectToView)
ctxt = view.rootContext()
ctxt.setContextProperty('myModel', model)
view.setSource(QUrl('qrc:view.qml'))
view.show()
sys.exit(app.exec_())
示例5: QQuickView
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootContext [as 别名]
appLabel = QQuickView()
appLabel.setSource(QUrl('main.qml'))
#appLabel.load(QUrl('main2.qml'))
# Show the Label
appLabel.show()
# Create a QML engine.
engine = QQmlEngine()
# Initialize PhotoBoothEngine.
pbengine = PhotoBoothEngine()
pbengine.on_status.connect(appLabel.rootObject().status)
pbengine.on_update_filter_preview.connect(appLabel.rootObject().updateImageFilterPreview)
appLabel.rootContext().setContextProperty('pbengine', pbengine)
# Create a component factory and load the QML script.
print("Hello")
component = QQmlComponent(appLabel.engine())
component.loadUrl(QUrl('TextStatusFly.qml'))
print("Hello2")
asdf = component.create(appLabel.rootContext())
print("Hello3")
asdf.setParentItem(appLabel.rootObject())
asdf.setParent(appLabel.rootObject())
print("Hello4")
#asdf.setProperty("targetX", 100)
示例6: qmlRegisterType
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootContext [as 别名]
qmlRegisterType(DataBlock, 'WeatherCategory', 1, 0, 'DataBlock')
qmlRegisterType(Geocoder, 'WeatherCategory', 1, 0, 'Geocoder')
component = QQmlComponent(engine)
component.loadUrl(QUrl('WeatherDash.qml'))
# Create the QML user interface. Auto creates its own engine
view = QQuickView()
engine2 = view.engine
# Does not run
#engine2.quit.connect(app.quit)
#view.setSource(QUrl('PyTest.qml'))
# To Satisfy cool-retro-term needs
view.rootContext().setContextProperty('devicePixelRatio', app.devicePixelRatio())
view.setSource(QUrl('WeatherDash.qml'))
#view.setResizeMode(QDeclarativeView.SizeRootObjectToView)
view.setGeometry(100, 100, 750, 480)
# ala https://pythonspot.com/pyqt5-colors/
view.setColor(QColor(0, 30, 0))
view.show()
is_full_screen = False
# technique lifted from https://stackoverflow.com/questions/19131084/pyqt5-qml-signal-to-python-slot
# and augmented from https://stackoverflow.com/questions/30586983/how-to-close-pyqt5-program-from-qml
# could refine with https://stackoverflow.com/questions/24111717/how-to-bind-buttons-in-qt-quick-to-python-pyqt-5
# not 100% ideal, but adequate and interesting
示例7: P2CQMLApplication
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootContext [as 别名]
class P2CQMLApplication(QGuiApplication):
def __init__(self, list_of_str):
super().__init__(list_of_str)
self._current_category = None
self._current_torrent = None
self._current_torrent_info = None
self._status_timer = QTimer(self)
self._movies_thread = None
self._search_thread = None
def run_view(self):
self._view = QQuickView()
self._view.engine().addImportPath("qml")
self._rctx = self._view.rootContext()
self._view.setResizeMode(QQuickView.SizeRootObjectToView)
# set context variables
self.categories = []
self._rctx.setContextProperty("categoriesModel", self.categories)
self.tiles = []
self.torrents = []
self._rctx.setContextProperty("moviesModel", self.tiles)
self._set_loading(False)
self._view.setSource(QUrl('qrc:/qml.qml'))
self._view.showFullScreen()
# self._view.show()
def connect_daemon(self, daemon: P2CDaemon):
self._daemon = daemon
self._set_categories()
self._connect_signals()
def play(self, movie: Movie):
self._set_movie_status("Ready to play!")
self._set_media(movie)
self._daemon.play(movie)
self._set_additional_media_info()
def buffer(self, movie: Movie):
seconds = self._current_torrent.get_seconds_to_buffer()
info = "just started"
if seconds:
if seconds < 15:
info = "just a moment"
else:
# rount to minutes
minutes = int(seconds / 60) + 1
if minutes == 1:
info = "1 minute"
else:
info = "{} minutes".format(minutes)
self._set_movie_status("Buffering... ({})".format(info))
self._daemon.buffer(movie)
self._set_additional_media_info()
def wait_for_metadata(self):
self._set_movie_status("Getting metadata...")
if self._current_torrent:
self._set_additional_media_info(self._current_torrent.name)
def select_movie(self, torrent: Torrent) -> Movie:
movies = torrent.get_movies()
if len(movies) == 0:
return
# TODO: show dialog with movie selecting instead of doing it automatically
return max(movies, key=lambda x: x.size)
def update_status(self):
torrent = self._current_torrent
if torrent:
if(torrent.has_torrent_info()):
movie = self.select_movie(torrent)
if not movie:
self._set_movie_status("No movie in this torrent. Please, select another.")
return
torrent.download_file(movie.path)
self._set_duration(movie)
if not self._daemon.is_playing(movie):
if(movie.can_play()):
# print(movie.get_subtitles())
self.play(movie)
else:
self.buffer(movie)
### DEBUG INFO
text = "s: %s, num p: %s, rate: %s kbs, p_rate: %s kbs" % (
torrent.get_status()['state'],
torrent.get_status()['num_peers'],
int(torrent.get_status()['download_rate'] / 1024),
int(torrent.get_status()['download_payload_rate'] / 1024),
)
self._view.rootObject().setProperty("debugText", text)
### END DEBUG INFO
else:
self.wait_for_metadata()
else:
self.wait_for_metadata()
#.........这里部分代码省略.........
示例8: Application
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootContext [as 别名]
#.........这里部分代码省略.........
qml_dir = Options.res_dir.parent / "PyQt5" / "Qt" / "qml"
log.debug(f"Setting QML import path for {view} to {qml_dir!r}")
view.engine().addImportPath(str(qml_dir))
def init_gui(self) -> None:
self.api = QMLDriveApi(self)
self.conflicts_model = FileModel()
self.errors_model = FileModel()
self.engine_model = EngineModel(self)
self.action_model = ActionModel()
self.file_model = FileModel()
self.ignoreds_model = FileModel()
self.language_model = LanguageModel()
self.add_engines(list(self.manager._engines.values()))
self.engine_model.statusChanged.connect(self.update_status)
self.language_model.addLanguages(Translator.languages())
flags = Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint
if WINDOWS:
self.conflicts_window = QQuickView()
self.add_qml_import_path(self.conflicts_window)
self.conflicts_window.setMinimumWidth(550)
self.conflicts_window.setMinimumHeight(600)
self.settings_window = QQuickView()
self.add_qml_import_path(self.settings_window)
self.settings_window.setMinimumWidth(640)
self.settings_window.setMinimumHeight(520)
self.systray_window = SystrayWindow()
self.add_qml_import_path(self.systray_window)
self._fill_qml_context(self.conflicts_window.rootContext())
self._fill_qml_context(self.settings_window.rootContext())
self._fill_qml_context(self.systray_window.rootContext())
self.systray_window.rootContext().setContextProperty(
"systrayWindow", self.systray_window
)
self.conflicts_window.setSource(
QUrl.fromLocalFile(str(find_resource("qml", "Conflicts.qml")))
)
self.settings_window.setSource(
QUrl.fromLocalFile(str(find_resource("qml", "Settings.qml")))
)
self.systray_window.setSource(
QUrl.fromLocalFile(str(find_resource("qml", "Systray.qml")))
)
flags |= Qt.Popup
else:
self.app_engine = QQmlApplicationEngine()
self._fill_qml_context(self.app_engine.rootContext())
self.app_engine.load(
QUrl.fromLocalFile(str(find_resource("qml", "Main.qml")))
)
root = self.app_engine.rootObjects()[0]
self.conflicts_window = root.findChild(QQuickWindow, "conflictsWindow")
self.settings_window = root.findChild(QQuickWindow, "settingsWindow")
self.systray_window = root.findChild(SystrayWindow, "systrayWindow")
if LINUX:
flags |= Qt.Drawer
self.systray_window.setFlags(flags)
self.manager.newEngine.connect(self.add_engines)