本文整理汇总了Python中PyQt5.QtQml.QQmlApplicationEngine类的典型用法代码示例。如果您正苦于以下问题:Python QQmlApplicationEngine类的具体用法?Python QQmlApplicationEngine怎么用?Python QQmlApplicationEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QQmlApplicationEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
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))
示例2: __init__
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")
示例3: __init__
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]
示例4: main
def main():
print("start")
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(QUrl("main.qml"))
engine.rootObjects()[0].show()
sys.exit(app.exec_())
示例5: main
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_())
示例6: startgui
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_()
示例7: MainWindow
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)
示例8: Application
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()
示例9: main
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_()
示例10: create
def create(self, qmlUrl):
# assert isinstance(qmlUrl, QUrl)
engine = QQmlApplicationEngine(qmlUrl)
try:
qmlRoot = engine.rootObjects()[0]
except:
qWarning("Failed to read or parse qml.")
raise
print(qmlRoot)
#assert isinstance(qmlRoot, QQuickWindow)
return qmlRoot
#super().__init__(qmlRoot)
'''
示例11: __init__
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)
示例12: SmartControlApplication
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: MainWindow
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)
示例14: MyApp
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_()
示例15: __init__
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)