本文整理汇总了Python中PyQt5.QtQml.QQmlComponent.errorString方法的典型用法代码示例。如果您正苦于以下问题:Python QQmlComponent.errorString方法的具体用法?Python QQmlComponent.errorString怎么用?Python QQmlComponent.errorString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtQml.QQmlComponent
的用法示例。
在下文中一共展示了QQmlComponent.errorString方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: PrinterOutputDevice
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import errorString [as 别名]
#.........这里部分代码省略.........
acceptsCommandsChanged = pyqtSignal()
printerStateChanged = pyqtSignal()
printerTypeChanged = pyqtSignal()
# Signal to be emitted when some drastic change occurs in the remaining time (not when the time just passes on normally).
preheatBedRemainingTimeChanged = pyqtSignal()
@pyqtProperty(QObject, constant=True)
def monitorItem(self):
# Note that we specifically only check if the monitor component is created.
# It could be that it failed to actually create the qml item! If we check if the item was created, it will try to
# create the item (and fail) every time.
if not self._monitor_component:
self._createMonitorViewFromQML()
return self._monitor_item
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())
@pyqtProperty(str, notify=printerTypeChanged)
def printerType(self):
return self._printer_type
@pyqtProperty(str, notify=printerStateChanged)
def printerState(self):
return self._printer_state
@pyqtProperty(str, notify = jobStateChanged)
def jobState(self):
return self._job_state
def _updatePrinterType(self, printer_type):
if self._printer_type != printer_type:
self._printer_type = printer_type
self.printerTypeChanged.emit()
def _updatePrinterState(self, printer_state):
if self._printer_state != printer_state:
self._printer_state = printer_state
self.printerStateChanged.emit()
def _updateJobState(self, job_state):
if self._job_state != job_state:
self._job_state = job_state
self.jobStateChanged.emit()
@pyqtSlot(str)
def setJobState(self, job_state):
self._setJobState(job_state)
示例2: WorkspaceDialog
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import errorString [as 别名]
#.........这里部分代码省略.........
self._result[key] = strategy
## Close the backend: otherwise one could end up with "Slicing..."
@pyqtSlot()
def closeBackend(self):
Application.getInstance().getBackend().close()
def setMaterialConflict(self, material_conflict):
if self._has_material_conflict != material_conflict:
self._has_material_conflict = material_conflict
self.materialConflictChanged.emit()
def setMachineConflict(self, machine_conflict):
if self._has_machine_conflict != machine_conflict:
self._has_machine_conflict = machine_conflict
self.machineConflictChanged.emit()
def setQualityChangesConflict(self, quality_changes_conflict):
if self._has_quality_changes_conflict != quality_changes_conflict:
self._has_quality_changes_conflict = quality_changes_conflict
self.qualityChangesConflictChanged.emit()
def setDefinitionChangesConflict(self, definition_changes_conflict):
if self._has_definition_changes_conflict != definition_changes_conflict:
self._has_definition_changes_conflict = definition_changes_conflict
self.definitionChangesConflictChanged.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 "definition_changes" in self._result and not self._has_definition_changes_conflict:
self._result["definition_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,
"definition_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):
self._result = {}
self._visible = False
self._lock.release()
def hide(self):
self._visible = False
self._lock.release()
self._view.hide()
@pyqtSlot()
def onOkButtonClicked(self):
self._view.hide()
self.hide()
@pyqtSlot()
def onCancelButtonClicked(self):
self._view.hide()
self.hide()
self._result = {}
## Block thread until the dialog is closed.
def waitForClose(self):
if self._visible:
if threading.current_thread() != threading.main_thread():
self._lock.acquire()
self._lock.release()
else:
# If this is not run from a separate thread, we need to ensure that the events are still processed.
while self._visible:
time.sleep(1 / 50)
QCoreApplication.processEvents() # Ensure that the GUI does not freeze.
def __show(self):
if self._view is None:
self._createViewFromQML()
if self._view:
self._view.show()
示例3: QApplication
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import errorString [as 别名]
from PyQt5.QtQml import QQmlComponent, QQmlApplicationEngine
from PyQt5.QtQuick import QQuickWindow
from view_model import ViewModel
if __name__ == '__main__':
myApp = QApplication(sys.argv)
engine = QQmlApplicationEngine()
context = engine.rootContext()
engine.addImportPath("/home/bob/Qt/5.11.2/Automotive/sources/qtapplicationmanager/dummyimports/")
# create a view model
view_model = ViewModel()
# bind the view model to the context
context.setContextProperty('view_model', view_model)
component = QQmlComponent(engine)
component.loadUrl(QUrl('mainwindow.qml'))
# some boilerplate to make sure the component is ready before showing
if component.status() != QQmlComponent.Ready:
if component.status() == QQmlComponent.Error:
sys.exit(component.errorString())
root_window: QQuickWindow = component.create()
myApp.exec_()
sys.exit()
示例4: MachineAction
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import errorString [as 别名]
class MachineAction(QObject, PluginObject):
## Create a new Machine action.
# \param key unique key of the machine action
# \param label Human readable label used to identify the machine action.
def __init__(self, key, label = ""):
super().__init__()
self._key = key
self._label = label
self._qml_url = ""
self._component = None
self._context = None
self._view = None
self._finished = False
labelChanged = pyqtSignal()
onFinished = pyqtSignal()
def getKey(self):
return self._key
@pyqtProperty(str, notify = labelChanged)
def label(self):
return self._label
def setLabel(self, label):
if self._label != label:
self._label = label
self.labelChanged.emit()
## Reset the action to it's default state.
# This should not be re-implemented by child classes, instead re-implement _reset.
# /sa _reset
@pyqtSlot()
def reset(self):
self._component = None
self._finished = False
self._reset()
## Protected implementation of reset.
# /sa reset()
def _reset(self):
pass
@pyqtSlot()
def setFinished(self):
self._finished = True
self._reset()
self.onFinished.emit()
@pyqtProperty(bool, notify = onFinished)
def finished(self):
return self._finished
## Protected helper to create a view object based on provided QML.
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)
if self._view is None:
Logger.log("c", "QQmlComponent status %s", self._component.status())
Logger.log("c", "QQmlComponent error string %s", self._component.errorString())
@pyqtProperty(QObject, constant = True)
def displayItem(self):
if not self._component:
self._createViewFromQML()
return self._view
示例5: WorkspaceDialog
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import errorString [as 别名]
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()
#.........这里部分代码省略.........
示例6: ros_qml_main
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import errorString [as 别名]
def ros_qml_main():
try:
rospy.init_node('ros_qml', sys.argv)
my_argv = rospy.myargv(sys.argv)
signal.signal(signal.SIGINT, sigint_handler)
app = QApplication(my_argv)
engine = QQmlEngine()
engine.quit.connect(app.quit)
plugins_dir = QLibraryInfo.location(QLibraryInfo.PluginsPath)
# ## Add QML extension modules and plugins to the path, including ourselves
plugins_paths = rospack.get_manifest(THIS_PACKAGE).get_export(THIS_PACKAGE, 'plugins')
for idx, p in enumerate(plugins_paths):
# If a relative path provided, treat it as relative to Qt plugins dir
if not os.path.isabs(p):
plugins_paths[idx] = plugins_dir + '/' + p
qml_paths = rospack.get_manifest(THIS_PACKAGE).get_export(THIS_PACKAGE, 'imports')
deps = rospack.get_depends_on(THIS_PACKAGE)
for d in deps:
pp = rospack.get_manifest(d).get_export(THIS_PACKAGE, 'plugins')
for idx, p in enumerate(pp):
# If a relative path provided, treat it as relative to Qt plugins dir
if not os.path.isabs(p):
pp[idx] = plugins_dir + '/' + p
plugins_paths += pp
qp = rospack.get_manifest(d).get_export(THIS_PACKAGE, 'imports')
qml_paths += qp
for p in plugins_paths:
engine.addPluginPath(p)
for p in qml_paths:
engine.addImportPath(p)
qml_sys_path = QLibraryInfo.location(QLibraryInfo.ImportsPath)
engine.addImportPath(qml_sys_path)
# Somehow we need to set the path both with QQmlEngine and with environment,
# commenting any of the two will lead to 'module not installed' error
os.environ['QML2_IMPORT_PATH'] = ':'.join(qml_paths) + ':' + qml_sys_path
comp = QQmlComponent(engine)
if len(my_argv) > 1 and my_argv[1]:
qml_url = my_argv[1]
comp.loadUrl(QUrl(qml_url))
elif rospy.has_param('qml_url'):
qml_url = rospy.get_param('qml_url')
comp.loadUrl(QUrl(qml_url))
elif rospy.has_param('qml_description'): # experimental
qml_description = rospy.get_param('qml_description')
# FIXME that hangs for unknown reason
comp.setData(QByteArray(qml_description), QUrl())
else:
rospy.logfatal('Neither /qml_url nor /qml_description (experimental) parameter is present')
sys.exit(1)
if not comp.isReady():
sys.stderr.write(comp.errorString())
sys.exit(1)
win = comp.create()
if not win:
rospy.logfatal('Your root item has to be a Window')
sys.exit(1)
engine.setIncubationController(win.incubationController())
if win:
win.show()
# Poll Python interpreter every 500ms
timer = QTimer()
timer.start(500)
timer.timeout.connect(lambda: None)
sys.exit(app.exec_())
except KeyboardInterrupt:
pass
except rospy.ROSInterruptException:
pass
示例7: PluginBrowser
# 需要导入模块: from PyQt5.QtQml import QQmlComponent [as 别名]
# 或者: from PyQt5.QtQml.QQmlComponent import errorString [as 别名]
class PluginBrowser(QObject, Extension):
def __init__(self, parent = None):
super().__init__(parent)
self.addMenuItem(i18n_catalog.i18n("Browse plugins"), self.browsePlugins)
self._api_version = 1
self._api_url = "http://software.ultimaker.com/cura/v%s/" % self._api_version
self._plugin_list_request = None
self._download_plugin_request = None
self._download_plugin_reply = None
self._network_manager = None
self._plugins_metadata = []
self._plugins_model = None
self._qml_component = None
self._qml_context = None
self._dialog = None
self._download_progress = 0
self._is_downloading = False
self._request_header = [b"User-Agent", str.encode("%s - %s" % (Application.getInstance().getApplicationName(), Application.getInstance().getVersion()))]
# Installed plugins are really installed after reboot. In order to prevent the user from downloading the
# same file over and over again, we keep track of the upgraded plugins.
self._newly_installed_plugin_ids = []
pluginsMetadataChanged = pyqtSignal()
onDownloadProgressChanged = pyqtSignal()
onIsDownloadingChanged = pyqtSignal()
@pyqtProperty(bool, notify = onIsDownloadingChanged)
def isDownloading(self):
return self._is_downloading
def browsePlugins(self):
self._createNetworkManager()
self.requestPluginList()
if not self._dialog:
self._createDialog()
self._dialog.show()
def requestPluginList(self):
url = QUrl(self._api_url + "plugins")
self._plugin_list_request = QNetworkRequest(url)
self._plugin_list_request.setRawHeader(*self._request_header)
self._network_manager.get(self._plugin_list_request)
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())
def setIsDownloading(self, is_downloading):
if self._is_downloading != is_downloading:
self._is_downloading = is_downloading
self.onIsDownloadingChanged.emit()
def _onDownloadPluginProgress(self, bytes_sent, bytes_total):
if bytes_total > 0:
new_progress = bytes_sent / bytes_total * 100
if new_progress > self._download_progress:
self._download_progress = new_progress
self.onDownloadProgressChanged.emit()
self._download_progress = new_progress
if new_progress == 100.0:
self.setIsDownloading(False)
self._download_plugin_reply.downloadProgress.disconnect(self._onDownloadPluginProgress)
self._temp_plugin_file = tempfile.NamedTemporaryFile(suffix = ".curaplugin")
self._temp_plugin_file.write(self._download_plugin_reply.readAll())
result = PluginRegistry.getInstance().installPlugin("file://" + self._temp_plugin_file.name)
self._newly_installed_plugin_ids.append(result["id"])
self.pluginsMetadataChanged.emit()
Application.getInstance().messageBox(i18n_catalog.i18nc("@window:title", "Plugin browser"), result["message"])
self._temp_plugin_file.close() # Plugin was installed, delete temp file
@pyqtProperty(int, notify = onDownloadProgressChanged)
def downloadProgress(self):
return self._download_progress
@pyqtSlot(str)
def downloadAndInstallPlugin(self, url):
#.........这里部分代码省略.........