本文整理汇总了Python中PyQt5.QtQml.QQmlContext类的典型用法代码示例。如果您正苦于以下问题:Python QQmlContext类的具体用法?Python QQmlContext怎么用?Python QQmlContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QQmlContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _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)
示例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: _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())
示例6: 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
示例7: _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)
示例8: _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
示例9: PauseBackend
class PauseBackend(QObject, Extension):
def __init__(self, parent = None):
super().__init__(parent = parent)
self._additional_component = None
self._additional_components_view = None
Application.getInstance().engineCreatedSignal.connect(self._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"))
@pyqtSlot()
def pauseBackend(self):
backend = Application.getInstance().getBackend()
backend._change_timer.timeout.disconnect(backend.slice)
backend._terminate()
backend.backendStateChange.emit(BackendState.Error)
@pyqtSlot()
def resumeBackend(self):
backend = Application.getInstance().getBackend()
backend._change_timer.timeout.connect(backend.slice)
backend.forceSlice()
示例10: _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())
示例11: _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())
示例12: _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"))
示例13: _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.")
示例14: _createAdditionalComponentsView
def _createAdditionalComponentsView(self):
Logger.log("d", "Creating additional ui components for UM3.")
path = QUrl.fromLocalFile(
os.path.join(PluginRegistry.getInstance().getPluginPath("UM3NetworkPrinting"), "UM3InfoComponents.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 ui components for UM3.")
return
Application.getInstance().addAdditionalComponent(
"monitorButtons", self.__additional_components_view.findChild(QObject, "networkPrinterConnectButton")
)
Application.getInstance().addAdditionalComponent(
"machinesDetailPane", self.__additional_components_view.findChild(QObject, "networkPrinterConnectionInfo")
)
示例15: WorkspaceDialog
class WorkspaceDialog(QObject):
showDialogSignal = pyqtSignal()
def __init__(self, parent = None):
super().__init__(parent)
self._component = None
self._context = None
self._view = None
self._qml_url = "WorkspaceDialog.qml"
self._lock = threading.Lock()
self._default_strategy = "override"
self._result = {"machine": self._default_strategy,
"quality_changes": self._default_strategy,
"material": self._default_strategy}
self._visible = False
self.showDialogSignal.connect(self.__show)
self._has_quality_changes_conflict = False
self._has_machine_conflict = False
self._has_material_conflict = False
machineConflictChanged = pyqtSignal()
qualityChangesConflictChanged = pyqtSignal()
materialConflictChanged = pyqtSignal()
@pyqtProperty(bool, notify = machineConflictChanged)
def machineConflict(self):
return self._has_machine_conflict
@pyqtProperty(bool, notify=qualityChangesConflictChanged)
def qualityChangesConflict(self):
return self._has_quality_changes_conflict
@pyqtProperty(bool, notify=materialConflictChanged)
def materialConflict(self):
return self._has_material_conflict
@pyqtSlot(str, str)
def setResolveStrategy(self, key, strategy):
if key in self._result:
self._result[key] = strategy
def setMaterialConflict(self, material_conflict):
self._has_material_conflict = material_conflict
self.materialConflictChanged.emit()
def setMachineConflict(self, machine_conflict):
self._has_machine_conflict = machine_conflict
self.machineConflictChanged.emit()
def setQualityChangesConflict(self, quality_changes_conflict):
self._has_quality_changes_conflict = quality_changes_conflict
self.qualityChangesConflictChanged.emit()
def getResult(self):
if "machine" in self._result and not self._has_machine_conflict:
self._result["machine"] = None
if "quality_changes" in self._result and not self._has_quality_changes_conflict:
self._result["quality_changes"] = None
if "material" in self._result and not self._has_material_conflict:
self._result["material"] = None
return self._result
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())
def show(self):
# Emit signal so the right thread actually shows the view.
if threading.current_thread() != threading.main_thread():
self._lock.acquire()
# Reset the result
self._result = {"machine": self._default_strategy,
"quality_changes": self._default_strategy,
"material": self._default_strategy}
self._visible = True
self.showDialogSignal.emit()
@pyqtSlot()
## Used to notify the dialog so the lock can be released.
def notifyClosed(self):
if self._result is None:
self._result = {}
self._lock.release()
def hide(self):
self._visible = False
self._lock.release()
self._view.hide()
@pyqtSlot()
def onOkButtonClicked(self):
self._view.hide()
self.hide()
#.........这里部分代码省略.........