本文整理汇总了Python中PyQt5.QtQml.QQmlApplicationEngine.rootObjects方法的典型用法代码示例。如果您正苦于以下问题:Python QQmlApplicationEngine.rootObjects方法的具体用法?Python QQmlApplicationEngine.rootObjects怎么用?Python QQmlApplicationEngine.rootObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtQml.QQmlApplicationEngine
的用法示例。
在下文中一共展示了QQmlApplicationEngine.rootObjects方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [as 别名]
def main():
print("start")
app = QGuiApplication(sys.argv)
engine = QQmlApplicationEngine()
engine.load(QUrl("main.qml"))
engine.rootObjects()[0].show()
sys.exit(app.exec_())
示例2: MainWindow
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [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 rootObjects [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 rootObjects [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]
示例5: main
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [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('yarg/resource/main.qml'))
window = engine.rootObjects()[0]
sys.exit(app.exec_())
示例6: PixelWall
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [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')
示例7: create
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [as 别名]
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)
'''
示例8: MyApp
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [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_()
示例9: main
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [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())
示例10: Application
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [as 别名]
#.........这里部分代码省略.........
self.add_qml_import_path(self.conflicts_window)
self.conflicts_window.setMinimumWidth(550)
self.conflicts_window.setMinimumHeight(600)
self.settings_window = QQuickView()
self.add_qml_import_path(self.settings_window)
self.settings_window.setMinimumWidth(640)
self.settings_window.setMinimumHeight(520)
self.systray_window = SystrayWindow()
self.add_qml_import_path(self.systray_window)
self._fill_qml_context(self.conflicts_window.rootContext())
self._fill_qml_context(self.settings_window.rootContext())
self._fill_qml_context(self.systray_window.rootContext())
self.systray_window.rootContext().setContextProperty(
"systrayWindow", self.systray_window
)
self.conflicts_window.setSource(
QUrl.fromLocalFile(str(find_resource("qml", "Conflicts.qml")))
)
self.settings_window.setSource(
QUrl.fromLocalFile(str(find_resource("qml", "Settings.qml")))
)
self.systray_window.setSource(
QUrl.fromLocalFile(str(find_resource("qml", "Systray.qml")))
)
flags |= Qt.Popup
else:
self.app_engine = QQmlApplicationEngine()
self._fill_qml_context(self.app_engine.rootContext())
self.app_engine.load(
QUrl.fromLocalFile(str(find_resource("qml", "Main.qml")))
)
root = self.app_engine.rootObjects()[0]
self.conflicts_window = root.findChild(QQuickWindow, "conflictsWindow")
self.settings_window = root.findChild(QQuickWindow, "settingsWindow")
self.systray_window = root.findChild(SystrayWindow, "systrayWindow")
if LINUX:
flags |= Qt.Drawer
self.systray_window.setFlags(flags)
self.manager.newEngine.connect(self.add_engines)
self.manager.initEngine.connect(self.add_engines)
self.manager.dropEngine.connect(self.remove_engine)
self._window_root(self.conflicts_window).changed.connect(self.refresh_conflicts)
self._window_root(self.systray_window).appUpdate.connect(self.api.app_update)
self._window_root(self.systray_window).getLastFiles.connect(self.get_last_files)
self.api.setMessage.connect(self._window_root(self.settings_window).setMessage)
if self.manager.get_engines():
current_uid = self.engine_model.engines_uid[0]
self.get_last_files(current_uid)
self.update_status(self.manager._engines[current_uid])
self.manager.updater.updateAvailable.connect(
self._window_root(self.systray_window).updateAvailable
)
self.manager.updater.updateProgress.connect(
self._window_root(self.systray_window).updateProgress
)
@pyqtSlot(Action)
def action_started(self, action: Action) -> None:
self.refresh_actions()
示例11: Test
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [as 别名]
window = engine.rootObjects()[0]
myObject = window.findChild(QObject, "myObject")
#loop.call_soon(myObject.funcRetClicked())
#myObject.funcRetClicked()
loop.run_in_executor(exec, myObject.funcRetClicked)
'''
with loop:
try:
test = Test()
service = Service(loop)
#loop.run_forever()
print('1')
# rootObjects 실행전 context를 선언/추가해줍니다.
ctx = engine.rootContext()
ctx.setContextProperty('Service', service)
#engine.load("main.qml")
engine.load("qml/tytrader.qml")
window = engine.rootObjects()[0]
#window.setContextProperty('Service', service)
loop.run_until_complete(test.printInterval())
loop.run_forever()
except:
pass
示例12: Progressor
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [as 别名]
sleeptime = 1000000 - datetime.datetime.now().microsecond
yield from asyncio.sleep(round(sleeptime * 0.000001, 2))
with loop:
ctx = engine.rootContext()
engine.load("progressor.qml")
#engine.load("progressor_multiple.qml")
#window = engine.rootObjects()[0]
#window = engine.rootObjects()[0].findChild("wnd1")
#root = engine.rootObjects()[0].findChild(QObject, "rootObj")
#root = engine.rootObjects()[0]
#window = engine.rootObjects()[0].findChild(QObject, "wnd")
window = engine.rootObjects()[0].findChild(QObject, "wnd_dummy")
window1 = engine.rootObjects()[0].findChild(QObject, "wnd1")
window2 = engine.rootObjects()[0].findChild(QObject, "wnd2")
window.show()
window1.show()
window2.show()
obj = window.findChild(QObject, "main")
obj1 = window1.findChild(QObject, "main1")
obj2 = window2.findChild(QObject, "main2")
prog = Progressor(obj)
prog1 = Progressor(obj1)
prog2 = Progressor(obj2)
示例13: order_by
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [as 别名]
Card.type == CardType.MINION.value)))
cards = cards.order_by(Card.cost).order_by(Card.type.asc()). \
order_by(Card.name.asc()).limit(8).all()
model.reset()
model.add_cards(cards)
if __name__ == "__main__":
import pdb
app = QApplication(sys.argv)
# Register the Python type. Its URI is 'People', it's v1.0 and the type
# will be called 'Person' in QML.
qmlRegisterType(TrackedCard, 'TrackedCards', 1, 0, 'TrackedCard')
engine = QQmlApplicationEngine()
ctxt = engine.rootContext()
# Initialize the data base
sqlengine = create_engine('sqlite:///stats.db', echo=False)
Session = sessionmaker()
Session.configure(bind=sqlengine)
session = Session()
ctxt.setContextProperty('pythonList', model)
engine.load(QUrl('vt.qml'))
engine.quit.connect(app.quit)
autoComplete = engine.rootObjects()[0].findChild(QObject, 'autoComplete')
autoComplete.textModified.connect(onTextChanged)
# data = engine.rootObjects()[0].findChild(QObject, 'myList')
# QMetaObject.invokeMethod(data, "append",
# Q_ARG('QVariant', {'name':'Josh', 'number': 90}))
sys.exit(app.exec_())
示例14: QQmlApplicationEngine
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [as 别名]
appEngine = QQmlApplicationEngine()
context = appEngine.rootContext()
appEngine.addImageProvider('viewerprovider', CvImageProvider()) # Hack to make qml believe provider is valid before its creation
appEngine.addImageProvider('trackerprovider', CvImageProvider()) # Hack to make qml believe provider is valid before its creation
appEngine.addImageProvider('recorderprovider', CvImageProvider()) # Hack to make qml believe provider is valid before its creation
appEngine.addImageProvider('calibrationprovider', CvImageProvider()) # Hack to make qml believe provider is valid before its creation
analysisImageProvider = PyplotImageProvider(fig=None)
appEngine.addImageProvider("analysisprovider", analysisImageProvider)
analysisImageProvider2 = PyplotImageProvider(fig=None)
appEngine.addImageProvider("analysisprovider2", analysisImageProvider2)
appEngine.load(QUrl('./qml/MouseTracker.qml'))
win = appEngine.rootObjects()[0]
if not DEBUG:
logger = Logger(context, win, "log")
sys.stdout = logger
# REGISTER PYTHON CLASSES WITH QML
params = ParamsIface(app, context, win)
viewer = ViewerIface(app, context, win, params, "preview", "viewerprovider")
tracker = TrackerIface(app, context, win, params, "trackerDisplay", "trackerprovider", analysisImageProvider, analysisImageProvider2)
recorder = RecorderIface(app, context, win, params, "recording", "recorderprovider", analysisImageProvider, analysisImageProvider2)
calibrater = CalibrationIface(app, context, win, params, "calibrationDisplay", "calibrationprovider")
context.setContextProperty('py_iface', params)
context.setContextProperty('py_viewer', viewer)
context.setContextProperty('py_tracker', tracker)
示例15: QApplication
# 需要导入模块: from PyQt5.QtQml import QQmlApplicationEngine [as 别名]
# 或者: from PyQt5.QtQml.QQmlApplicationEngine import rootObjects [as 别名]
from PyQt5.QtQml import QQmlApplicationEngine
from PyQt5.QtCore import QUrl
from PyQt5.QtQml import qmlRegisterType
from PyQt5.QtWidgets import QApplication
from mvc_control.controller import Controller
import sys, signal
from mvc_view.FFDScene import FFDScene
from util.util import filter_for_speed
__author__ = 'ac'
# logging.basicConfig(level=logging.DEBUG)
app = QApplication(sys.argv)
signal.signal(signal.SIGINT, signal.SIG_DFL)
qmlRegisterType(FFDScene, 'FFD', 1, 0, "FFDScene")
# controller = Controller()
engine = QQmlApplicationEngine()
engine.load(QUrl(filter_for_speed(file_name='res/ui/main.qml')))
scene = engine.rootObjects()[0].findChild(FFDScene, 'scene')
controller = scene.controller # type: Controller
engine.rootContext().setContextProperty('controller', controller)
# print('main thread:', threading.current_thread().ident)
# app.exec()
sys.exit(app.exec())