当前位置: 首页>>代码示例>>Python>>正文


Python QQmlApplicationEngine.addImportPath方法代码示例

本文整理汇总了Python中PyQt5.QtQml.QQmlApplicationEngine.addImportPath方法的典型用法代码示例。如果您正苦于以下问题:Python QQmlApplicationEngine.addImportPath方法的具体用法?Python QQmlApplicationEngine.addImportPath怎么用?Python QQmlApplicationEngine.addImportPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.QtQml.QQmlApplicationEngine的用法示例。


在下文中一共展示了QQmlApplicationEngine.addImportPath方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SmartControlApplication

# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import addImportPath [as 别名]
class SmartControlApplication(QGuiApplication):
    _instance = None

    WINDOW_ICON = "smart-control.png"
    DEFAULT_THEME = "default"
    MAIN_QML = "main.qml"

    def __init__(self, **kwargs):
        if sys.platform == "win32":
            if hasattr(sys, "frozen"):
                QCoreApplication.addLibraryPath(os.path.join(os.path.abspath(os.path.dirname(sys.executable)), "PyQt5", "plugins"))
            else:
                import site
                for dir in site.getsitepackages():
                    QCoreApplication.addLibraryPath(os.path.join(dir, "PyQt5", "plugins"))
        super().__init__(sys.argv, **kwargs)
        self.setApplicationVersion(version)
        self._engine = QQmlApplicationEngine()
        self._internationalization = Internationalization()
        self._theme = Theme()
        self._printerConnectionManager = PrinterConnectionManager()

    @classmethod
    def instance(cls):
        if SmartControlApplication._instance is None:
            SmartControlApplication._instance = cls()
        return SmartControlApplication._instance

    def run(self):
        self._internationalization.load(locale.getdefaultlocale()[0])
        self._theme.load(SmartControlApplication.DEFAULT_THEME)
        self._printerConnectionManager.start()

        self.aboutToQuit.connect(self._onClose)
        self.setWindowIcon(QIcon(Resources.icon(SmartControlApplication.WINDOW_ICON)))
        Binder(self._internationalization, self._theme, self._printerConnectionManager).register()

        self._engine = QQmlApplicationEngine()
        if sys.platform == "win32":
            self._engine.addImportPath(os.path.join(os.path.abspath(os.path.dirname(sys.executable)), "qml"))
        self._engine.load(Resources.qml(SmartControlApplication.MAIN_QML))

        sys.exit(self.exec_())

    def _onClose(self):
        self._printerConnectionManager.stop()
开发者ID:Kiddo3D,项目名称:SmartControl,代码行数:48,代码来源:SmartControlApplication.py

示例2: QtApplication

# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import addImportPath [as 别名]

#.........这里部分代码省略.........
        self.showSplashMessage(i18n_catalog.i18nc("@info:progress", "Loading preferences..."))
        try:
            file = Resources.getPath(Resources.Preferences, self.getApplicationName() + ".cfg")
            Preferences.getInstance().readFromFile(file)
        except FileNotFoundError:
            pass

    def run(self):
        pass

    def hideMessage(self, message):
        with self._message_lock:
            if message in self._visible_messages:
                self._visible_messages.remove(message)
                self.visibleMessageRemoved.emit(message)

    def showMessage(self, message):
        with self._message_lock:
            if message not in self._visible_messages:
                self._visible_messages.append(message)
                message.setTimer(QTimer())
                self.visibleMessageAdded.emit(message)

    def setMainQml(self, path):
        self._main_qml = path

    def initializeEngine(self):
        # TODO: Document native/qml import trickery
        Bindings.register()

        self._engine = QQmlApplicationEngine()

        for path in self._qml_import_paths:
            self._engine.addImportPath(path)

        if not hasattr(sys, "frozen"):
            self._engine.addImportPath(os.path.join(os.path.dirname(__file__), "qml"))

        self._engine.rootContext().setContextProperty("QT_VERSION_STR", QT_VERSION_STR)

        self.registerObjects(self._engine)

        self._engine.load(self._main_qml)
        self.engineCreatedSignal.emit()

    engineCreatedSignal = Signal()

    def isShuttingDown(self):
        return self._shutting_down

    def registerObjects(self, engine):
        pass

    def getRenderer(self):
        if not self._renderer:
            self._renderer = QtRenderer()

        return self._renderer

    def addCommandLineOptions(self, parser):
        parser.add_argument("--disable-textures",
                            dest="disable-textures",
                            action="store_true", default=False,
                            help="Disable Qt texture loading as a workaround for certain crashes.")

    #   Overridden from QApplication::setApplicationName to call our internal setApplicationName
开发者ID:fujitsai,项目名称:Uranium,代码行数:70,代码来源:QtApplication.py

示例3: QtApplication

# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import addImportPath [as 别名]
class QtApplication(QApplication, Application, SignalEmitter):
    def __init__(self, **kwargs):
        plugin_path = ""
        if sys.platform == "win32":
            plugin_path = os.path.join(os.path.dirname(os.path.abspath(sys.executable)), "PyQt5", "plugins")
            Logger.log("i", "Adding QT5 plugin path: %s" % (plugin_path))
            QCoreApplication.addLibraryPath(plugin_path)    
        elif sys.platform == "darwin":
            plugin_path = os.path.join(Application.getInstallPrefix(), "Resources", "plugins")

        if plugin_path:
            Logger.log("i", "Adding QT5 plugin path: %s" % (plugin_path))
            QCoreApplication.addLibraryPath(plugin_path)

        os.environ["QSG_RENDER_LOOP"] = "basic"
        super().__init__(sys.argv, **kwargs)

        self._main_qml = "main.qml"
        self._engine = None
        self._renderer = None

        try:
            self._splash = QSplashScreen(QPixmap(Resources.getPath(Resources.ImagesLocation, self.getApplicationName() + ".png")))
        except FileNotFoundError:
            self._splash = None
        else:
            self._splash.show()
            self.processEvents()

        signal.signal(signal.SIGINT, signal.SIG_DFL)
        # This is done here as a lot of plugins require a correct gl context. If you want to change the framework,
        # these checks need to be done in your <framework>Application.py class __init__().

        i18n_catalog = i18nCatalog("uranium")

        self.showSplashMessage(i18n_catalog.i18nc("Splash screen message", "Loading plugins..."))
        self._loadPlugins()
        self._plugin_registry.checkRequiredPlugins(self.getRequiredPlugins())

        self.showSplashMessage(i18n_catalog.i18nc("Splash screen message", "Loading machines..."))
        self.loadMachines()

        self.showSplashMessage(i18n_catalog.i18nc("Splash screen message", "Loading preferences..."))
        try:
            file = Resources.getPath(Resources.PreferencesLocation, self.getApplicationName() + ".cfg")
            Preferences.getInstance().readFromFile(file)
        except FileNotFoundError:
            pass

        self._translators = {}

        self.showSplashMessage(i18n_catalog.i18nc("Splash screen message", "Loading translations..."))

        self.loadQtTranslation("uranium_qt")
        self.loadQtTranslation(self.getApplicationName() + "_qt")

    def run(self):
        pass
    
    def hideMessage(self, message):
        with self._message_lock:
            if message in self._visible_messages:
                self._visible_messages.remove(message)
                self.visibleMessageRemoved.emit(message)
    
    def showMessage(self, message):
        with self._message_lock:
            if message not in self._visible_messages:
                self._visible_messages.append(message)
                message.setTimer(QTimer())
                self.visibleMessageAdded.emit(message)
    
        pass

    def setMainQml(self, path):
        self._main_qml = path

    def initializeEngine(self):
        # TODO: Document native/qml import trickery
        Bindings.register()

        self._engine = QQmlApplicationEngine()
        self.engineCreatedSignal.emit()
        
        self._engine.addImportPath(os.path.join(os.path.dirname(sys.executable), "qml"))
        self._engine.addImportPath(os.path.join(Application.getInstallPrefix(), "Resources", "qml"))
        if not hasattr(sys, "frozen"):
            self._engine.addImportPath(os.path.join(os.path.dirname(__file__), "qml"))

        self.registerObjects(self._engine)
        
        self._engine.load(self._main_qml)
    
    engineCreatedSignal = Signal()
    
    def registerObjects(self, engine):
        pass

    def getRenderer(self):
        if not self._renderer:
#.........这里部分代码省略.........
开发者ID:derekhe,项目名称:Uranium,代码行数:103,代码来源:QtApplication.py

示例4: QtApplication

# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import addImportPath [as 别名]

#.........这里部分代码省略.........
        last_run_version_str = self._preferences.getValue("general/last_run_version")
        if not last_run_version_str:
            last_run_version_str = self._version
        last_run_version = Version(last_run_version_str)
        current_version = Version(self._version)
        if last_run_version < current_version:
            self._just_updated_from_old_version = True
        self._preferences.setValue("general/last_run_version", str(current_version))
        self._preferences.writeToFile(self._preferences_filename)

        # Preferences: recent files
        self._preferences.addPreference("%s/recent_files" % self._app_name, "")
        file_names = self._preferences.getValue("%s/recent_files" % self._app_name).split(";")
        for file_name in file_names:
            if not os.path.isfile(file_name):
                continue
            self._recent_files.append(QUrl.fromLocalFile(file_name))

        if not self.getIsHeadLess():
            # Initialize System tray icon and make it invisible because it is used only to show pop up messages
            self._tray_icon = None
            if self._tray_icon_name:
                self._tray_icon = QIcon(Resources.getPath(Resources.Images, self._tray_icon_name))
                self._tray_icon_widget = QSystemTrayIcon(self._tray_icon)
                self._tray_icon_widget.setVisible(False)

    def initializeEngine(self) -> None:
        # TODO: Document native/qml import trickery
        self._qml_engine = QQmlApplicationEngine(self)
        self._qml_engine.setOutputWarningsToStandardError(False)
        self._qml_engine.warnings.connect(self.__onQmlWarning)

        for path in self._qml_import_paths:
            self._qml_engine.addImportPath(path)

        if not hasattr(sys, "frozen"):
            self._qml_engine.addImportPath(os.path.join(os.path.dirname(__file__), "qml"))

        self._qml_engine.rootContext().setContextProperty("QT_VERSION_STR", QT_VERSION_STR)
        self._qml_engine.rootContext().setContextProperty("screenScaleFactor", self._screenScaleFactor())

        self.registerObjects(self._qml_engine)

        Bindings.register()
        self._qml_engine.load(self._main_qml)
        self.engineCreatedSignal.emit()

    recentFilesChanged = pyqtSignal()

    @pyqtProperty("QVariantList", notify=recentFilesChanged)
    def recentFiles(self) -> List[QUrl]:
        return self._recent_files

    def _onJobFinished(self, job: Job) -> None:
        if isinstance(job, WriteFileJob):
            if not job.getResult() or not job.getAddToRecentFiles():
                # For a write file job, if it failed or it doesn't need to be added to the recent files list, we do not
                # add it.
                return
        elif (not isinstance(job, ReadMeshJob) and not isinstance(job, ReadFileJob)) or not job.getResult():
            return

        if isinstance(job, (ReadMeshJob, ReadFileJob, WriteFileJob)):
            self.addFileToRecentFiles(job.getFileName())

    def addFileToRecentFiles(self, file_name: str) -> None:
开发者ID:Ultimaker,项目名称:Uranium,代码行数:70,代码来源:QtApplication.py

示例5: QApplication

# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import addImportPath [as 别名]
import sys
import os

from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QUrl
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())
开发者ID:bobzurad,项目名称:zsandbox.azurewebsites.net,代码行数:32,代码来源:app.py

示例6: QtApplication

# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import addImportPath [as 别名]

#.........这里部分代码省略.........
        pref = ""
        for path in self._recent_files:
            pref += path.toLocalFile() + ";"

        Preferences.getInstance().setValue("%s/recent_files" % self.getApplicationName(), pref)
        self.recentFilesChanged.emit()

    def run(self):
        pass

    def hideMessage(self, message):
        with self._message_lock:
            if message in self._visible_messages:
                self._visible_messages.remove(message)
                self.visibleMessageRemoved.emit(message)

    def showMessage(self, message):
        with self._message_lock:
            if message not in self._visible_messages:
                self._visible_messages.append(message)
                message.setTimer(QTimer())
                self.visibleMessageAdded.emit(message)

    def setMainQml(self, path):
        self._main_qml = path

    def initializeEngine(self):
        # TODO: Document native/qml import trickery
        Bindings.register()

        self._engine = QQmlApplicationEngine()

        for path in self._qml_import_paths:
            self._engine.addImportPath(path)

        if not hasattr(sys, "frozen"):
            self._engine.addImportPath(os.path.join(os.path.dirname(__file__), "qml"))

        self._engine.rootContext().setContextProperty("QT_VERSION_STR", QT_VERSION_STR)
        self._engine.rootContext().setContextProperty("screenScaleFactor", self._screenScaleFactor())

        self.registerObjects(self._engine)

        self._engine.load(self._main_qml)
        self.engineCreatedSignal.emit()

    engineCreatedSignal = Signal()

    def isShuttingDown(self):
        return self._shutting_down

    def registerObjects(self, engine):
        engine.rootContext().setContextProperty("PluginRegistry", PluginRegistry.getInstance())

    def getRenderer(self):
        if not self._renderer:
            self._renderer = QtRenderer()

        return self._renderer

    @classmethod
    def addCommandLineOptions(self, parser):
        super().addCommandLineOptions(parser)
        parser.add_argument("--disable-textures",
                            dest="disable-textures",
                            action="store_true", default=False,
开发者ID:senttech,项目名称:Uranium,代码行数:70,代码来源:QtApplication.py

示例7: UiState

# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import addImportPath [as 别名]
class UiState(QObject):
    sigComPortOpened = pyqtSignal()
    sigComPortClosed = pyqtSignal()
    sigPowerOn = pyqtSignal()
    sigPowerOff = pyqtSignal()

    def __init__(self):
        super().__init__()
        self.fsm = QStateMachine()
        self.qmlEngine = QQmlApplicationEngine()
        self.qmlEngine.addImportPath("qml")
        self.qmlEngine.addImportPath("lib")
        self.qmlEngine.load(QUrl('qrc:/qml/main.qml'))        
        self.rootObject = self.qmlEngine.rootObjects()[0]

        self.rootObject.comPortOpened.connect(self.sigComPortOpened)
        self.rootObject.comPortClosed.connect(self.sigComPortClosed)
        self.rootObject.powerOn.connect(self.sigPowerOn)
        self.rootObject.powerOff.connect(self.sigPowerOff)
        self.createState()
        pass

    def createState(self):
        # state defintion
        mainState = QState(self.fsm)
        finalState = QFinalState(self.fsm)
        self.fsm.setInitialState(mainState)
        
        initState = QState(mainState)
        openState = QState(mainState)
        mainState.setInitialState(initState)

        standbyState = QState(openState)
        processingState = QState(openState)
        openState.setInitialState(standbyState)

        # transition defition
        initState.addTransition(self.sigComPortOpened, openState) 
        openState.addTransition(self.sigComPortClosed, initState)

        standbyState.addTransition(self.sigPowerOn, processingState)
        processingState.addTransition(self.sigPowerOff, standbyState)

        initState.entered.connect(self.initStateEntered)
        openState.entered.connect(self.openStateEntered)
        standbyState.entered.connect(self.standbyStateEntered)
        processingState.entered.connect(self.processingStateEntered)

        # fsm start
        self.fsm.start()
        pass

    @pyqtSlot()
    def initStateEntered(self):
        print("init")
        QMetaObject.invokeMethod(self.rootObject, "setPathViewIndex", QtCore.Q_ARG("QVariant", 0))
        pass

    @pyqtSlot()   
    def openStateEntered(self):
        print("open")
        pass

    @pyqtSlot()
    def standbyStateEntered(self):
        print("standby")
        QMetaObject.invokeMethod(self.rootObject, "setPathViewIndex", QtCore.Q_ARG("QVariant", 1))
        pass

    @pyqtSlot()
    def processingStateEntered(self):
        print("processing")
        QMetaObject.invokeMethod(self.rootObject, "setPathViewIndex",QtCore.Q_ARG("QVariant", 2))
        pass 
开发者ID:coreanq,项目名称:ultra_sonic,代码行数:76,代码来源:main.py


注:本文中的PyQt5.QtQml.QQmlApplicationEngine.addImportPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。