本文整理汇总了Python中PyQt5.QtQuick.QQuickView.rootObject方法的典型用法代码示例。如果您正苦于以下问题:Python QQuickView.rootObject方法的具体用法?Python QQuickView.rootObject怎么用?Python QQuickView.rootObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtQuick.QQuickView
的用法示例。
在下文中一共展示了QQuickView.rootObject方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: LoginWin
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
class LoginWin(QtCore.QObject):
def __init__(self, state, app):
QtCore.QObject.__init__(self)
self.state = state
self.app = app
# Create the QML user interface.
self.login_win = QQuickView()
self.login_win.setTitle(self.tr("Xiami Login"))
self.login_win.setSource(QUrl('login.qml'))
self.login_win.setResizeMode(QQuickView.SizeRootObjectToView)
self.login_win.show()
# Connect signals
self.root_obj = self.login_win.rootObject()
self.root_obj.loginClicked.connect(self.login_clicked)
self.root_obj.exitClicked.connect(self.exit_clicked)
def set_state(self, msg):
self.root_obj.setStatus(msg)
def exit_clicked(self):
sys.exit(0)
def login_clicked(self, username, password):
code = self.root_obj.getVerificationCode()
if code != "":
try:
login.login_with_code(self.state, self.key, code)
except Exception as e:
self.set_state(e.message)
self.root_obj.hideCode()
return
self.ok()
else:
try:
ret = login.login(self.state, username, password)
except Exception as e:
self.set_state(e.message)
return
if not ret[0]:
with open(login.img_path, 'wb') as imgf:
imgf.write(ret[2])
self.set_state(self.tr("Please enter verification code"))
self.root_obj.setVerificationImage("file://%s"
% login.img_path)
self.key = ret[1]
else:
self.ok()
def ok(self):
self.login_win.close()
self.app.auth_ok()
示例2: main
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
def main():
print("start")
app = QApplication(sys.argv)
qmlRegisterType(Person, 'People', 1, 0, 'Person')
v = QQuickView(QUrl("testFindChild.qml"))
qmlRoot = v.rootObject()
assert isinstance(qmlRoot, QQuickItem)
assert isinstance(qmlRoot, QObject)
dumpQMLComponents(qmlRoot)
result = qmlRoot.findChild(Person, "person")
assert result is not None
sys.exit(app.exec_())
示例3: __init__
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
def __init__(self):
super(QmlStartPage, self).__init__()
box = QVBoxLayout(self)
box.setContentsMargins(0, 0, 0, 0)
# View
view = QQuickView()
view.setSource(QUrl.fromLocalFile(PATH_QML))
view.setResizeMode(QQuickView.SizeRootObjectToView)
# Root object
self._root = view.rootObject()
widget_container = QWidget.createWindowContainer(view)
box.addWidget(widget_container)
self._root.animationFinished.connect(self._on_animation_finished)
示例4: TabletShortcuts
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
class TabletShortcuts(QGuiApplication):
def __init__(self, argv):
QGuiApplication.__init__(self, argv)
self.view = QQuickView()
self.bus = QDBusConnection.sessionBus()
self.server = MyDBUSServer(self)
self.bus.registerObject("/app", self.server)
self.bus.registerService("sevanteri.TabletShortcuts")
self.view.setTitle("TabletShortcuts")
self.view.setResizeMode(QQuickView.SizeRootObjectToView)
self.view.setSource(QUrl('main.qml'))
self.root = self.view.rootObject()
self.showView()
self.root.runCommand.connect(self.run)
self.root.hideView.connect(self.view.hide)
self.view.engine().quit.connect(self.quit)
def run(self, cmd):
return Popen(shlex.split(cmd))
def quit(self):
self.exit()
def showView(self):
if self.view.isVisible():
self.view.hide()
else:
# width, height = TabletShortcuts.getScreenGeometry()
# self.view.setGeometry(1, 1, width, height)
self.view.show()
def getScreenGeometry():
output = Popen("xrandr | grep 'current'", shell=True, stdout=PIPE)\
.communicate()[0].decode('UTF-8')
m = re.search('current.([0-9]+).x.([0-9]+)', output)
width = int(m.group(1))
height = int(m.group(2))
return (width, height)
示例5: __init__
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
def __init__(self):
super(StartPage, self).__init__()
vbox = QVBoxLayout(self)
vbox.setContentsMargins(0, 0, 0, 0)
view = QQuickView()
qml = os.path.join(settings.QML_PATH, "StartPage.qml")
view.setSource(QUrl.fromLocalFile(qml))
view.setResizeMode(QQuickView.SizeRootObjectToView)
widget = QWidget.createWindowContainer(view)
vbox.addWidget(widget)
self.__root = view.rootObject()
# Connections
self.__root.openDatabase.connect(self.__open_database)
self.__root.newDatabase.connect(self.__new_database)
self.__root.removeCurrent.connect(self.__remove_current)
示例6: __init__
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
def __init__(self, parent=None):
super(MessageError, self).__init__(parent,
Qt.Dialog | Qt.FramelessWindowHint)
self._parent = parent
self.setModal(True)
self.setFixedHeight(150)
self.setFixedWidth(350)
box = QVBoxLayout(self)
box.setContentsMargins(0, 0, 0, 0)
view = QQuickView()
qml = os.path.join(settings.QML_PATH, "MessageError.qml")
view.setSource(QUrl.fromLocalFile(qml))
view.setResizeMode(QQuickView.SizeRootObjectToView)
self.widget = QWidget.createWindowContainer(view)
box.addWidget(self.widget)
self._root = view.rootObject()
self._root.close.connect(self.close)
示例7: run_app
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
def run_app():
app = QGuiApplication(sys.argv)
app.setApplicationName("Worship Prototype")
view = QQuickView()
view.setResizeMode(QQuickView.SizeRootObjectToView)
view.setSource(QUrl.fromLocalFile(os.path.join(os.path.dirname(__file__), 'main.qml')))
view.show()
root = view.rootObject()
preview = DefaultScreen()
preview.wire_to_gui(root, 'previewScreen')
preview.show_background(VideoBackground(os.path.join(os.path.dirname(__file__), '../echo.mp4')))
# preview_live = DefaultScreen()
# live = DefaultScreen()
modules = [
LyricsModule(SongsList(), root, preview),
]
sys.exit(app.exec_())
示例8: QApplication
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
# Create main app
myApp = QApplication(sys.argv)
# Create a label and set its properties
appLabel = QQuickView()
appLabel.setSource(QUrl('main.qml'))
#appLabel.load(QUrl('main2.qml'))
# Show the Label
appLabel.show()
# Create a QML engine.
engine = QQmlEngine()
# Initialize PhotoBoothEngine.
pbengine = PhotoBoothEngine()
pbengine.on_status.connect(appLabel.rootObject().status)
pbengine.on_update_filter_preview.connect(appLabel.rootObject().updateImageFilterPreview)
appLabel.rootContext().setContextProperty('pbengine', pbengine)
# Create a component factory and load the QML script.
print("Hello")
component = QQmlComponent(appLabel.engine())
component.loadUrl(QUrl('TextStatusFly.qml'))
print("Hello2")
asdf = component.create(appLabel.rootContext())
print("Hello3")
asdf.setParentItem(appLabel.rootObject())
asdf.setParent(appLabel.rootObject())
示例9: on_quit
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
is_full_screen = False
# technique lifted from https://stackoverflow.com/questions/19131084/pyqt5-qml-signal-to-python-slot
# and augmented from https://stackoverflow.com/questions/30586983/how-to-close-pyqt5-program-from-qml
# could refine with https://stackoverflow.com/questions/24111717/how-to-bind-buttons-in-qt-quick-to-python-pyqt-5
# not 100% ideal, but adequate and interesting
def on_quit():
app.quit()
def on_toggle_fullscreen():
global is_full_screen
if is_full_screen:
view.show()
else:
view.showFullScreen()
is_full_screen = not is_full_screen
weather_dash = view.rootObject()
weather_dash.quit.connect(on_quit)
weather_dash.toggleFullScreen.connect(on_toggle_fullscreen)
# may want to do this slightly differently, though I prefer QML doing the heavy lifting
# http://doc.qt.io/qt-5/qqmlcomponent.html
#weather_chart = view.findChild(Loader, "WeatherChart")
# this does work
#view.showFullScreen()
app.exec_()
示例10: __init__
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
def __init__(self):
super(MyMain,self).__init__()
self.btsearch = Search()
@pyqtSlot(str,int,result = QVariant)
def add_items(self,parm,index):
bt_thread = Thread(target = self.thread_add_items,args = (parm,index,))
bt_thread.start()
@pyqtSlot(str,int,result = QVariant)
def thread_add_items(self,parm,index):
result = self.btsearch.search(parm)
self.signal_add_items.emit(QVariant(result),index)
if __name__ == '__main__':
path = 'main.qml'
app = QApplication([])
view = QQuickView()
con = MyMain()
context = view.rootContext()
context.setContextProperty("con",con)
view.engine().quit.connect(app.quit)
view.setSource(QUrl(path))
view.show()
root = view.rootObject()
con.signal_add_items.connect(root.slot_add_items)
app.exec()
示例11: QGuiApplication
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
#Sample Python File
from PyQt5.QtCore import QUrl
from PyQt5.QtGui import QGuiApplication
from PyQt5.QtQuick import QQuickView
if __name__ == '__main__':
import os
import sys
app = QGuiApplication(sys.argv)
view = QQuickView()
view.setWidth(500)
view.setHeight(500)
view.setTitle('Hello PyQt')
view.setResizeMode(QQuickView.SizeRootObjectToView)
view.setSource(QUrl.fromLocalFile(os.path.join(os.path.dirname(__file__),'main.qml')))
view.show()
qml_rectangle = view.rootObject()
sys.exit(app.exec_())
示例12: __init__
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
def __init__(self, parent=None):
super(Trace, self).__init__(parent)
self.freq = 1.0
def get_data(self):
max = 256
data = list(map(lambda x: int(127 + 127 * math.sin( 2.0 * math.pi * self.freq * x / max)), range(0,max)))
self.freq *= 1.01
self.new_data.emit(data)
# Create the application instance.
app = QApplication(sys.argv)
# Create the QML user interface.
view = QQuickView()
view.setSource(QUrl('test.qml'))
#view.setResizeMode(QDeclarativeView.SizeRootObjectToView)
view.showFullScreen()
scope = ScopeInterface()
scope.new_data.connect(view.rootObject().newData)
scope.initialize()
scope.capture()
sys.exit(app.exec_())
scope.stop()
示例13: P2CQMLApplication
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
class P2CQMLApplication(QGuiApplication):
def __init__(self, list_of_str):
super().__init__(list_of_str)
self._current_category = None
self._current_torrent = None
self._current_torrent_info = None
self._status_timer = QTimer(self)
self._movies_thread = None
self._search_thread = None
def run_view(self):
self._view = QQuickView()
self._view.engine().addImportPath("qml")
self._rctx = self._view.rootContext()
self._view.setResizeMode(QQuickView.SizeRootObjectToView)
# set context variables
self.categories = []
self._rctx.setContextProperty("categoriesModel", self.categories)
self.tiles = []
self.torrents = []
self._rctx.setContextProperty("moviesModel", self.tiles)
self._set_loading(False)
self._view.setSource(QUrl('qrc:/qml.qml'))
self._view.showFullScreen()
# self._view.show()
def connect_daemon(self, daemon: P2CDaemon):
self._daemon = daemon
self._set_categories()
self._connect_signals()
def play(self, movie: Movie):
self._set_movie_status("Ready to play!")
self._set_media(movie)
self._daemon.play(movie)
self._set_additional_media_info()
def buffer(self, movie: Movie):
seconds = self._current_torrent.get_seconds_to_buffer()
info = "just started"
if seconds:
if seconds < 15:
info = "just a moment"
else:
# rount to minutes
minutes = int(seconds / 60) + 1
if minutes == 1:
info = "1 minute"
else:
info = "{} minutes".format(minutes)
self._set_movie_status("Buffering... ({})".format(info))
self._daemon.buffer(movie)
self._set_additional_media_info()
def wait_for_metadata(self):
self._set_movie_status("Getting metadata...")
if self._current_torrent:
self._set_additional_media_info(self._current_torrent.name)
def select_movie(self, torrent: Torrent) -> Movie:
movies = torrent.get_movies()
if len(movies) == 0:
return
# TODO: show dialog with movie selecting instead of doing it automatically
return max(movies, key=lambda x: x.size)
def update_status(self):
torrent = self._current_torrent
if torrent:
if(torrent.has_torrent_info()):
movie = self.select_movie(torrent)
if not movie:
self._set_movie_status("No movie in this torrent. Please, select another.")
return
torrent.download_file(movie.path)
self._set_duration(movie)
if not self._daemon.is_playing(movie):
if(movie.can_play()):
# print(movie.get_subtitles())
self.play(movie)
else:
self.buffer(movie)
### DEBUG INFO
text = "s: %s, num p: %s, rate: %s kbs, p_rate: %s kbs" % (
torrent.get_status()['state'],
torrent.get_status()['num_peers'],
int(torrent.get_status()['download_rate'] / 1024),
int(torrent.get_status()['download_payload_rate'] / 1024),
)
self._view.rootObject().setProperty("debugText", text)
### END DEBUG INFO
else:
self.wait_for_metadata()
else:
self.wait_for_metadata()
#.........这里部分代码省略.........
示例14: View
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
class View(object):
shapes = ["rectangle", "ellipse", "image"]
edgetypes = ["line", "curve"]
def __init__(self):
self._controller = Controller(self)
self._gui = QGuiApplication(sys.argv)
self._qml_dir = os.path.dirname(os.path.realpath(__file__))
self._main = QQuickView()
self._main.setResizeMode(QQuickView.SizeRootObjectToView)
self._main.setSource(QUrl(self._qml_dir + '/main.qml'))
self._main.rootObject().create_node.connect(
self._controller.create_node)
self._main.rootObject().mouse_position.connect(
self._controller.mouse_position)
self._main.rootObject().save.connect(
self._controller.save)
self._main.rootObject().load.connect(
self._controller.load)
self._main.rootObject().lose_focus.connect(
self._controller.lose_focus)
self._main.rootObject().node_color_sel.connect(
self._controller.node_color_sel)
self._main.rootObject().edge_color_sel.connect(
self._controller.edge_color_sel)
self._main.rootObject().workspace_height_changed.connect(
self._controller.workspace_height_changed)
self._main.rootObject().workspace_width_changed.connect(
self._controller.workspace_width_changed)
self._main.rootObject().edge_type_sel.connect(
self._controller.edge_type_sel)
self._main.rootObject().node_shape_sel.connect(
self._controller.node_shape_sel)
self._main.rootObject().clear_workspace.connect(
self._controller.clear_workspace)
self._main.rootObject().node_width_changed.connect(
self._controller.node_width_changed)
self._main.rootObject().node_height_changed.connect(
self._controller.node_height_changed)
self._main.rootObject().node_text_color_sel.connect(
self._controller.node_text_color_sel)
self._main.rootObject().node_text_size_changed.connect(
self._controller.node_text_size_changed)
self._main.rootObject().edge_thickness_changed.connect(
self._controller.edge_thickness_changed)
self._main.rootObject().show_edge_controls.connect(
self._controller.show_edge_controls)
self._main.rootObject().hide_edge_controls.connect(
self._controller.hide_edge_controls)
self._main.rootObject().exporting.connect(
self._controller.exporting)
self._main.setProperty(
"width", self._controller.project.workspace_width)
self._main.setProperty(
"height", self._controller.project.workspace_height)
self._main.show()
def run(self):
return self._gui.exec_()
def create_node(self, node):
# Creates new node from source QML and puts it inside of main window
qml_node = QQuickView(QUrl(self._qml_dir + '/shapes/' +
self.shapes[node.shape] + '.qml'),
self._main)
workspace = self._main.rootObject().findChild(QQuickItem, "workspace")
# Sets all properties
qml_node.rootObject().setProperty("parent", workspace)
qml_node.rootObject().setProperty("objectId", str(node.id))
qml_node.rootObject().setProperty("background",
str(node.background))
qml_node.rootObject().setProperty("width", str(node.width))
qml_node.rootObject().setProperty("height", str(node.height))
qml_node.rootObject().setProperty("text", str(node.text.text))
qml_node.rootObject().setProperty("textFont", str(node.text.font))
qml_node.rootObject().setProperty("textSize", str(node.text.size))
qml_node.rootObject().setProperty("textColor", str(node.text.color))
# Sets drag boundaries
qml_node.rootObject().setProperty("workspaceWidth",
str(workspace.property("width")))
qml_node.rootObject().setProperty("workspaceHeight",
str(workspace.property("height")))
# Signal connection
qml_node.rootObject().node_delete.connect(
self._controller.node_delete)
qml_node.rootObject().node_text_changed.connect(
self._controller.node_text_changed)
qml_node.rootObject().node_position_changed.connect(
self._controller.node_position_changed)
qml_node.rootObject().node_connect.connect(
self._controller.node_connect)
qml_node.rootObject().node_focus.connect(
self._controller.node_focus)
#.........这里部分代码省略.........
示例15: create_node
# 需要导入模块: from PyQt5.QtQuick import QQuickView [as 别名]
# 或者: from PyQt5.QtQuick.QQuickView import rootObject [as 别名]
def create_node(self, node):
# Creates new node from source QML and puts it inside of main window
qml_node = QQuickView(QUrl(self._qml_dir + '/shapes/' +
self.shapes[node.shape] + '.qml'),
self._main)
workspace = self._main.rootObject().findChild(QQuickItem, "workspace")
# Sets all properties
qml_node.rootObject().setProperty("parent", workspace)
qml_node.rootObject().setProperty("objectId", str(node.id))
qml_node.rootObject().setProperty("background",
str(node.background))
qml_node.rootObject().setProperty("width", str(node.width))
qml_node.rootObject().setProperty("height", str(node.height))
qml_node.rootObject().setProperty("text", str(node.text.text))
qml_node.rootObject().setProperty("textFont", str(node.text.font))
qml_node.rootObject().setProperty("textSize", str(node.text.size))
qml_node.rootObject().setProperty("textColor", str(node.text.color))
# Sets drag boundaries
qml_node.rootObject().setProperty("workspaceWidth",
str(workspace.property("width")))
qml_node.rootObject().setProperty("workspaceHeight",
str(workspace.property("height")))
# Signal connection
qml_node.rootObject().node_delete.connect(
self._controller.node_delete)
qml_node.rootObject().node_text_changed.connect(
self._controller.node_text_changed)
qml_node.rootObject().node_position_changed.connect(
self._controller.node_position_changed)
qml_node.rootObject().node_connect.connect(
self._controller.node_connect)
qml_node.rootObject().node_focus.connect(
self._controller.node_focus)
if node.shape == 2:
qml_node.rootObject().node_image_loaded.connect(
self._controller.node_image_loaded)
# Position to mouse click
qml_node.rootObject().setX(node.x - node.width / 2)
qml_node.rootObject().setY(node.y - node.height / 2)
qml_node.rootObject().setZ(2)
return qml_node