本文整理汇总了Python中PyQt5.QtQml.QQmlApplicationEngine.load方法的典型用法代码示例。如果您正苦于以下问题:Python QQmlApplicationEngine.load方法的具体用法?Python QQmlApplicationEngine.load怎么用?Python QQmlApplicationEngine.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtQml.QQmlApplicationEngine
的用法示例。
在下文中一共展示了QQmlApplicationEngine.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
def __init__(self, qml):
app = QGuiApplication(sys.argv)
model = QmlModel()
model.register()
qmlUrl = QUrl(qml)
assert qmlUrl.isValid()
print(qmlUrl.path())
# assert qmlUrl.isLocalFile()
"""
Create an engine a reference to the window?
window = QuickWindowFactory().create(qmlUrl=qmlUrl)
window.show() # visible
"""
engine = QQmlApplicationEngine()
"""
Need this if no stdio, i.e. Android, OSX, iOS.
OW, qWarnings to stdio.
engine.warnings.connect(self.errors)
"""
engine.load(qmlUrl)
engine.quit.connect(app.quit)
app.exec_() # !!! C exec => Python exec_
print("Application returned")
示例2: MainWindow
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
class MainWindow(QObject):
def __init__(self, parent=None):
super().__init__(parent)
self.log = logging.getLogger(__name__)
self._read_settings()
self.client = Client(self)
if self.remember:
self._autologin()
self.model = MainWindowViewModel(self)
self.loginModel = LoginViewModel(self.client, self.user, self.password, self.remember, self)
self.loginModel.panel_visible = not self.remember
self.gamesModel = GamesViewModel(self)
self.engine = QQmlApplicationEngine(self)
self.engine.rootContext().setContextProperty('windowModel', self.model)
self.engine.rootContext().setContextProperty('loginModel', self.loginModel)
self.engine.rootContext().setContextProperty('contentModel', self.gamesModel)
self.engine.quit.connect(parent.quit)
self.engine.load(QUrl.fromLocalFile('ui/Chrome.qml'))
self.window = self.engine.rootObjects()[0]
# wire up logging console
self.console = self.window.findChild(QQuickItem, 'console')
parent.log_changed.connect(self._log)
def show(self):
self.window.show()
def _read_settings(self):
stored = settings.get()
stored.beginGroup('login')
self.user = stored.value('user')
self.password = stored.value('password')
self.remember = stored.value('remember') == 'true'
stored.endGroup()
@async_slot
def _autologin(self):
try:
self.log.info('logging in (auto)...')
self.loginModel.logged_in = yield from self.client.login(self.user, self.password)
self.log.debug('autologin result: {}'.format(self.loginModel.logged_in))
except Exception as e:
self.log.error('autologin failed. {}'.format(e))
@pyqtSlot(str)
def _log(self, msg):
# replace with collections.deque binding(ish)?
if self.console.property('lineCount') == LOG_BUFFER_SIZE:
line_end = self.console.property('text').find('\n') + 1
self.console.remove(0, line_end)
self.console.append(msg)
示例3: MainWindow
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
class MainWindow(QObject):
def __init__(self, parent=None):
super().__init__(parent)
self.model = MainWindowViewModel(self)
self.loginModel = LoginViewModel(self)
self.engine = QQmlApplicationEngine(self)
self.engine.rootContext().setContextProperty('model', self.model)
self.engine.rootContext().setContextProperty('loginModel', self.loginModel)
self.engine.quit.connect(parent.quit)
self.engine.load(QUrl.fromLocalFile('ui/Chrome.qml'))
self.window = self.engine.rootObjects()[0]
# wire up logging console
self.log = self.window.findChild(QQuickItem, 'log')
parent.log_changed.connect(self._log)
def show(self):
self.window.show()
def _log(self, msg):
# replace with collections.deque binding(ish)?
if self.log.property('lineCount') == LOG_BUFFER_SIZE:
line_end = self.log.property('text').find('\n') + 1
self.log.remove(0, line_end)
self.log.append(msg)
示例4: __init__
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
class SnowflakeUI:
def __init__(self, qmlfile, gamesdb):
self.engine = QQmlApplicationEngine()
self.games_db = gamesdb
self.root_qml = qmlfile
self.platformsListModel = self._load_platforms()
self.gamesListModel = self._load_games()
def init_ui(self):
self.engine.load(QUrl(self.root_qml))
def show(self):
raise NotImplementedError
def get_root(self):
raise NotImplementedError
def _load_games(self):
gameslist = {}
keys = Loadables.Instance().platforms.keys()
for platform in keys:
games = self.games_db.get_games_for_platform(platform)
gameslist[platform] = qml_games.RunnableGamesListModel(sorted((qml_games.RunnableGameWrapper(game) for game in games),
key=lambda game: game.game.gameinfo.title))
return gameslist
def _load_platforms(self):
return qml_platforms.PlatformsListModel(sorted((qml_platforms.PlatformsWrapper(platform_info)
for platform_info in iter(Loadables.Instance().platforms.values())),
key = lambda platform: platform.platform_id))
示例5: __init__
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
class AboutWindow:
QML_FILE = "qml/AboutWindow.qml"
def __init__(self):
# Create window from QML via QQmlApplicationEngine
self.engine = QQmlApplicationEngine()
self.engine.load(self.QML_FILE)
self.window = self.engine.rootObjects()[0]
示例6: main
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
def main():
print("start")
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(QUrl("main.qml"))
engine.rootObjects()[0].show()
sys.exit(app.exec_())
示例7: startgui
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
def startgui():
app = QApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(QUrl("qrc:/asserts/gui.qml"))
classifier = Classifier(engine, SRCFaceClassifier(DALMSolver()))
classifier.run()
return app.exec_()
示例8: main
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
def main():
app = QGuiApplication(sys.argv)
qmlRegisterType(MainController, 'MainController', 1, 0, 'MainController')
qmlRegisterType(ProfileViewModel, 'ProfileViewModel', 1, 0, 'ProfileViewModel')
engine = QQmlApplicationEngine()
main_controller = MainController()
main_controller.profile_selection_changed(0)
engine.rootContext().setContextProperty('mainController', main_controller)
engine.load(QUrl.fromLocalFile(pkg_resources.resource_filename('yarg.resource', 'main.qml')))
sys.exit(app.exec_())
示例9: Application
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
class Application(QApplication):
def __init__(self, argv):
super(Application, self).__init__(argv)
stderrHandler = logging.StreamHandler(stream=sys.stderr)
stderrHandler.setLevel(logging.WARN)
stdoutHandler = logging.StreamHandler(stream=sys.stdout)
stdoutHandler.setLevel(logging.INFO)
stdoutHandler.filter = lambda rec: rec.levelno <= stdoutHandler.level
logging.basicConfig(
format='%(name)-15s %(message)s',
level=logging.INFO,
handlers=[stderrHandler, stdoutHandler]
)
logger.info("__init__")
self._qml_engine = QQmlApplicationEngine()
self._root_context = self._qml_engine.rootContext()
self.char = Character(self)
def setContext(self, name, value):
self._root_context.setContextProperty(name, value)
def start(self):
logger.info("start")
self.setContext('character', self.char)
self.readModels()
self._qml_engine.load(QUrl("qrc:/ui/main.qml"))
def readModels(self):
logger.info("readModels")
modelTypes = [
MODEL.Perk,
MODEL.Quirk,
MODEL.Species
]
allDelayedInits = {}
for modelType in modelTypes:
delayedInits = []
logger.info("parsing model %s", modelType.__name__)
g = modelParsers.parse(modelType, delayedInits=delayedInits)
allDelayedInits[modelType] = delayedInits
model = list(g)
# TODO
name = "%sModel" % modelType.__name__
assert model is not None, "failed to parse {0}".format(modelType.__name__)
self.setContext(name, model)
for modelType, delayedInits in allDelayedInits.items():
logger.info("delayed init model %s (%s)", modelType.__name__, len(delayedInits))
for delayedInit in delayedInits:
delayedInit()
def exec(self):
logger.info("exec")
super().exec()
示例10: main
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
def main(argv=None):
if not argv:
argv = sys.argv
app = QApplication(argv)
# register own type
qmlRegisterType(QmlController, 'QmlController', 1, 0, 'QmlController')
engine = QQmlApplicationEngine(app)
engine.load(QUrl('main.qml'))
return app.exec_()
示例11: PixelWall
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
class PixelWall(QApplication):
def __init__(self, *args, **kwargs):
super(PixelWall, self).__init__(*args, **kwargs)
self.engine = QQmlApplicationEngine(self)
self.servers = ServerModel(self.engine)
self.settings = QSettings('OpenServices', 'PixelWall')
url = self.settings.value('server/url')
self.engine.setNetworkAccessManagerFactory(NetworkAccessManagerFactory('hetzner.fladi.at', 3128))
ctxt = self.engine.rootContext()
ctxt.setContextProperty('app', self)
ctxt.setContextProperty('url', 'about:blank')
self.engine.load(QUrl('states.qml'))
discoverer = Avahi(self.engine, '_pixelwall._tcp')
discoverer.initialized.connect(self.serverState)
discoverer.added.connect(self.servers.addService)
ctxt.setContextProperty('serverModel', self.servers)
discoverer.run()
if url:
self.setUrl(url)
self.setState('Web')
def setState(self, state):
for root in self.engine.rootObjects():
node = root.findChild(QObject, 'main')
if node:
logger.info('Setting state: {}'.format(state))
node.setProperty('state', state)
def setUrl(self, url):
logger.info('Connecting WebView to {}'.format(url))
ctxt = self.engine.rootContext()
ctxt.setContextProperty('url', 'https://www.heise.de/')
@pyqtSlot()
def reset(self):
self.settings.remove('server/url')
self.setState('Servers')
@pyqtSlot(int)
def serverSelected(self, index):
server = self.servers.getIndex(index)
logger.info('Server selected {}'.format(server))
url = 'https://{server.host}:{server.port}/'.format(server=server)
self.settings.setValue('server/url', url)
self.setUrl(url)
self.setState('Web')
@pyqtSlot()
def serverState(self):
self.setState('Servers')
示例12: SmartControlApplication
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [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()
示例13: MyApp
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
class MyApp(QObject):
def __init__(self, qml, set_context=None):
super().__init__()
self.app = QApplication(sys.argv)
self.engine = QQmlApplicationEngine(self)
self.root_context = self.engine.rootContext()
if set_context:
set_context(self.root_context)
self.engine.load(QUrl(qml))
self.root_view = self.engine.rootObjects()[0]
@staticmethod
def run(my_app):
my_app.root_view.show()
return my_app.app.exec_()
示例14: __init__
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
class Application:
organization = 'pisak'
name = 'pisak'
def __init__(self, gui):
self._app = QApplication(sys.argv)
self._app.setOrganizationName(self.organization)
self._app.setApplicationName(self.name)
self._context = _ApplicationContext()
self._engine = QQmlApplicationEngine()
self._engine.rootContext().setContextProperty('pisak', self._context)
self._engine.load(gui)
def run(self):
sys.exit(self._app.exec_())
示例15: main
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import load [as 别名]
def main(argv):
signal.signal(signal.SIGINT, signal.SIG_DFL)
qapp = QGuiApplication([])
engine = QQmlApplicationEngine()
data_list = []
for entry in os.scandir(argv[1]):
url = "file://" + urllib.parse.quote(os.path.abspath(entry.path))
digest = hashlib.md5(os.fsencode(url)).hexdigest()
result = os.path.join(xdg.BaseDirectory.xdg_cache_home, "thumbnails", "normal", digest + ".png")
data_list.append(Foo(entry.name, result, "2018-01-11T19:20"))
engine.load(QUrl('main.qml'))
ctxt = engine.rootContext()
ctxt.setContextProperty("menu2", QVariant(data_list))
win = engine.rootObjects()[0]
win.show()
sys.exit(qapp.exec())