本文整理汇总了Python中PyQt5.QtQml.QQmlComponent类的典型用法代码示例。如果您正苦于以下问题:Python QQmlComponent类的具体用法?Python QQmlComponent怎么用?Python QQmlComponent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QQmlComponent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: init_country_names_from_code
def init_country_names_from_code(locale):
'''Init the country description as found in GCompris geography/resource/board/board*.qml'''
'''in the global descriptions hash'''
po = None
try:
po = polib.pofile( gcompris_qt + '/po/gcompris_' + locale + '.po')
except:
print "**ERROR: Failed to load po file %s**" %(gcompris_qt + '/po/gcompris_' + locale + '.po')
print ''
app = QCoreApplication(sys.argv)
engine = QQmlEngine()
component = QQmlComponent(engine)
for qml in glob.glob(gcompris_qt + '/src/activities/geography/resource/board/*.qml'):
component.loadUrl(QUrl(qml))
board = component.create()
levels = board.property('levels')
for level in levels.toVariant():
if level.has_key('soundFile') and level.has_key('toolTipText'):
sound = level['soundFile'].split('/')[-1].replace('$CA', 'ogg')
tooltip = level['toolTipText']
if po:
tooltip = po.find(tooltip).msgstr if po.find(tooltip) else tooltip
descriptions[sound] = tooltip
示例2: createChangelogWindow
def createChangelogWindow(self):
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "ChangeLog.qml"))
component = QQmlComponent(Application.getInstance()._engine, path)
self._changelog_context = QQmlContext(Application.getInstance()._engine.rootContext())
self._changelog_context.setContextProperty("manager", self)
self._changelog_window = component.create(self._changelog_context)
示例3: spawnFirmwareInterface
def spawnFirmwareInterface(self, serial_port):
if self._firmware_view is None:
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("Doodle3D"), "SettingsWindow.qml"))
component = QQmlComponent(Application.getInstance()._engine, path)
self._firmware_context = QQmlContext(Application.getInstance()._engine.rootContext())
self._firmware_context.setContextProperty("manager", self)
self._firmware_view = component.create(self._firmware_context)
self._firmware_view.show()
示例4: createControlInterface
def createControlInterface(self):
if self._control_view is None:
Logger.log("d", "Creating control interface for printer connection")
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("USBPrinting"), "ControlWindow.qml"))
component = QQmlComponent(Application.getInstance()._engine, path)
self._control_context = QQmlContext(Application.getInstance()._engine.rootContext())
self._control_context.setContextProperty("manager", self)
self._control_view = component.create(self._control_context)
示例5: view
def view(self):
with self.__view_creation_lock:
if self._view is None:
component = QQmlComponent(self.dice.qml_engine, self.qml_file, self)
if component.status() == QQmlComponent.Error:
qDebug("errors loading component: "+str(component.errors()))
qDebug(self.qml_file)
for error in component.errors():
qDebug(error.description())
return QQuickItem(self)
# don't create the view immediately so the properties are available as soon as the view is created
view = component.beginCreate(self.dice.qml_context)
if view:
view.setParentItem(self.dice.main_window)
view.setProperty("appWindow", self.dice.app_window)
view.setProperty("app", self)
view.setProperty("mainWindow", self.dice.main_window)
self._view = view
component.completeCreate()
self.view_changed.emit()
else:
component.completeCreate()
qDebug("no view")
view = QQuickItem(self)
view.setParentItem(self.dice.main_window)
# TODO: send an alert
return view
return self._view
示例6: _createConfigUI
def _createConfigUI(self):
if self._ui_view is None:
Logger.log("d", "Creating ImageReader config UI")
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("ImageReader"), "ConfigUI.qml"))
component = QQmlComponent(Application.getInstance()._engine, path)
self._ui_context = QQmlContext(Application.getInstance()._engine.rootContext())
self._ui_context.setContextProperty("manager", self)
self._ui_view = component.create(self._ui_context)
self._ui_view.setFlags(self._ui_view.flags() & ~Qt.WindowCloseButtonHint & ~Qt.WindowMinimizeButtonHint & ~Qt.WindowMaximizeButtonHint);
self._disable_size_callbacks = False
示例7: _createViewFromQML
def _createViewFromQML(self):
path = QUrl.fromLocalFile(
os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), self._qml_url))
self._component = QQmlComponent(Application.getInstance()._engine, path)
self._context = QQmlContext(Application.getInstance()._engine.rootContext())
self._context.setContextProperty("manager", self)
self._view = self._component.create(self._context)
示例8: get_geography_on_letter_from_code
def get_geography_on_letter_from_code():
'''Return all the countries in geography/resource/board/board-x.json'''
words = set()
app = QCoreApplication(sys.argv)
engine = QQmlEngine()
component = QQmlComponent(engine)
for qml in glob.glob(gcompris_qt + '/src/activities/geography/resource/board/*.qml'):
component.loadUrl(QUrl(qml))
board = component.create()
levels = board.property('levels')
for level in levels.toVariant():
if level.has_key('soundFile') and (not level.has_key('type') or level['type'] != "SHAPE_BACKGROUND"):
sound = level['soundFile'].split('/')[-1].replace('$CA', 'ogg')
words.add(sound)
return words
示例9: _createViewFromQML
def _createViewFromQML(self):
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("3MFReader"), self._qml_url))
self._component = QQmlComponent(Application.getInstance()._engine, path)
self._context = QQmlContext(Application.getInstance()._engine.rootContext())
self._context.setContextProperty("manager", self)
self._view = self._component.create(self._context)
if self._view is None:
Logger.log("c", "QQmlComponent status %s", self._component.status())
Logger.log("c", "QQmlComponent error string %s", self._component.errorString())
示例10: createQmlComponent
def createQmlComponent(self, qml_file_path: str, context_properties: Dict[str, "QObject"] = None) -> Optional["QObject"]:
if self._qml_engine is None: # Protect in case the engine was not initialized yet
return None
path = QUrl.fromLocalFile(qml_file_path)
component = QQmlComponent(self._qml_engine, path)
result_context = QQmlContext(self._qml_engine.rootContext()) #type: ignore #MyPy doens't realise that self._qml_engine can't be None here.
if context_properties is not None:
for name, value in context_properties.items():
result_context.setContextProperty(name, value)
result = component.create(result_context)
for err in component.errors():
Logger.log("e", str(err.toString()))
if result is None:
return None
# We need to store the context with the qml object, else the context gets garbage collected and the qml objects
# no longer function correctly/application crashes.
result.attached_context = result_context
return result
示例11: _createView
def _createView(self):
## Load all scripts in the scripts folder
self.loadAllScripts(os.path.join(PluginRegistry.getInstance().getPluginPath("PostProcessingPlugin"), "scripts"))
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("PostProcessingPlugin"), "PostProcessingPlugin.qml"))
self._component = QQmlComponent(Application.getInstance()._engine, path)
self._context = QQmlContext(Application.getInstance()._engine.rootContext())
self._context.setContextProperty("manager", self)
self._view = self._component.create(self._context)
示例12: _createDialog
def _createDialog(self):
Logger.log("d", "PluginBrowser")
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath(self.getPluginId()), "PluginBrowser.qml"))
self._qml_component = QQmlComponent(Application.getInstance()._engine, path)
# We need access to engine (although technically we can't)
self._qml_context = QQmlContext(Application.getInstance()._engine.rootContext())
self._qml_context.setContextProperty("manager", self)
self._dialog = self._qml_component.create(self._qml_context)
if self._dialog is None:
Logger.log("e", "QQmlComponent status %s", self._qml_component.status())
Logger.log("e", "QQmlComponent errorString %s", self._qml_component.errorString())
示例13: _createMonitorViewFromQML
def _createMonitorViewFromQML(self):
path = QUrl.fromLocalFile(self._monitor_view_qml_path)
# Because of garbage collection we need to keep this referenced by python.
self._monitor_component = QQmlComponent(Application.getInstance()._engine, path)
# Check if the context was already requested before (Printer output device might have multiple items in the future)
if self._qml_context is None:
self._qml_context = QQmlContext(Application.getInstance()._engine.rootContext())
self._qml_context.setContextProperty("OutputDevice", self)
self._monitor_item = self._monitor_component.create(self._qml_context)
if self._monitor_item is None:
Logger.log("e", "QQmlComponent status %s", self._monitor_component.status())
Logger.log("e", "QQmlComponent error string %s", self._monitor_component.errorString())
示例14: _createAdditionalComponentsView
def _createAdditionalComponentsView(self):
Logger.log("d", "Creating additional ui components for Pause Backend plugin.")
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("PauseBackendPlugin"), "PauseBackend.qml"))
self._additional_component = QQmlComponent(Application.getInstance()._engine, path)
# We need access to engine (although technically we can't)
self._additional_components_context = QQmlContext(Application.getInstance()._engine.rootContext())
self._additional_components_context.setContextProperty("manager", self)
self._additional_components_view = self._additional_component.create(self._additional_components_context)
if not self._additional_components_view:
Logger.log("w", "Could not create additional components for Pause Backend plugin.")
return
Application.getInstance().addAdditionalComponent("saveButton", self._additional_components_view.findChild(QObject, "pauseResumeButton"))
示例15: _createView
def _createView(self):
Logger.log("d", "Creating post processing plugin view.")
## Load all scripts in the scripts folder
try:
self.loadAllScripts(os.path.join(PluginRegistry.getInstance().getPluginPath("PostProcessingPlugin"), "scripts"))
except Exception as e:
print("Exception occured", e) # TODO: Debug code (far to general catch. Remove this once done testing)
path = QUrl.fromLocalFile(os.path.join(PluginRegistry.getInstance().getPluginPath("PostProcessingPlugin"), "PostProcessingPlugin.qml"))
self._component = QQmlComponent(Application.getInstance()._engine, path)
# We need access to engine (although technically we can't)
self._context = QQmlContext(Application.getInstance()._engine.rootContext())
self._context.setContextProperty("manager", self)
self._view = self._component.create(self._context)
Logger.log("d", "Post processing view created.")