def testIncubateWhileCall(self): app = QGuiApplication(sys.argv) view = QQuickView() controller = CustomIncubationController(self) view.engine().setIncubationController(controller) view.setResizeMode(QQuickView.SizeRootObjectToView) view.setSource( QUrl.fromLocalFile( adjust_filename('qqmlincubator_incubateWhile.qml', __file__))) view.show() root = view.rootObject() # The QML code will issue an interrupt signal after half of its items are loaded. root.shouldInterrupt.connect(controller.interrupter) res = app.exec_() itemsToCreate = root.property("itemsToCreate") loadedItems = root.property("loadedItems") self.assertEqual(loadedItems, itemsToCreate / 2) # Finish incubating the remaining items. controller.incubateFor(1000) loadedItems = root.property("loadedItems") self.assertEqual(loadedItems, itemsToCreate) # Deleting the view before it goes out of scope is required to make sure all child QML # instances are destroyed in the correct order. del view del app
def main(): app = QApplication([]) view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) # QML経由でアクセスするPythonTextクラスのインスタンスを生成する python_text = PythonText() # QMLのrootアイテムのコンテキストを取得する context = view.rootContext() """ QMLの rootアイテムにQML側からアクセスするPythonのクラスを登録する PySide2.QtQml.QQmlContext.setContextProperty(arg__1, arg__2) arg__1 – QML側からアクセスするためのQMLオブジェクト名 arg__2 - QML側からアクセスさせるPythonクラス """ context.setContextProperty("pythonText", python_text) url = QUrl("HelloWorld.qml") view.setSource(url) if view.status() == QQuickView.Error: sys.exit(-1) view.show() ret = app.exec_() del view sys.exit(ret)
def main(): qInstallMessageHandler(lambda x, y, msg: print(msg)) argv = sys.argv # Trick to set the style / not found how to do it in pythonic way #argv.extend(["-style", "universal"]) app = QGuiApplication(argv) qmlRegisterType(FigureCanvasQTAgg, "Backend", 1, 0, "FigureCanvasByPython") view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) view.setSource(QUrl(str(pathlib.Path(__file__).parent / 'Figure.qml'))) view.show() win = view.rootObject() qml_figure_canvas = win.findChild(QObject, "figure") fig = qml_figure_canvas.getFigure() print(fig) ax = fig.add_subplot(111) x = np.linspace(-5, 5) ax.plot(x, np.sin(x)) rc = app.exec_() # There is some trouble arising when deleting all the objects here # but I have not figure out how to solve the error message. # It looks like 'app' is destroyed before some QObject sys.exit(rc)
def main(argv): data = [ [4, 9, 2], [1, 0, 0], [3, 5, 0], [3, 3, 2], [7, 8, 9], ] myModel = BasicModel(data) app = QtWidgets.QApplication(argv) view = QQuickView() view.rootContext().setContextProperty("myModel", myModel) view.setResizeMode(QQuickView.SizeRootObjectToView) view.resize(640, 480) url = QtCore.QUrl("table.qml") result = view.setSource(url) # TODO somehow connect myModel python to QML Table view. view.show() sys.exit(app.exec_())
def main(): app = QApplication([]) """ 指定したクラスを、QMLモジュールのQMLタイプとしてバインディングする qmlRegisterType(class, uri, versionMajor, versionMinor, qmlName) class - QML側でQML Type定義するPythonクラス uri - 定義するQMLモジュール名 versionMajor - QMLモジュールのメジャーバージョン versionMinor - QMLモジュールのマイナーバージョン qmlName - 定義するQMLタイプ名 """ qmlRegisterType(PythonText, "FromPythonTextLibrary", 1, 0, "FromPythonText") view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) url = QUrl("HelloWorld.qml") view.setSource(url) if view.status() == QQuickView.Error: sys.exit(-1) view.show() ret = app.exec_() del view sys.exit(ret)
def main(): argv = sys.argv app = QGuiApplication(argv) qmlRegisterType(FigureCanvasQTAggToolbar, "Backend", 1, 0, "FigureToolbarByPython") # this should work in the future # qmlRegisterType( # QUrl.fromLocalFile( str(pathlib.Path(backend_qquick5agg.__file__)/'SubplotTool.qml')), # "Backend", 1, 0, "SubplotTool") imgProvider = MatplotlibIconProvider() view = QQuickView() view.engine().addImageProvider("mplIcons", imgProvider) view.setResizeMode(QQuickView.SizeRootObjectToView) view.setSource( QUrl(str(pathlib.Path(__file__).parent / 'FigureToolbar.qml'))) win = view.rootObject() fig = win.findChild(QObject, "figure").getFigure() ax = fig.add_subplot(111) x = np.linspace(-5, 5) ax.plot(x, np.sin(x)) view.show() rc = app.exec_() # There is some trouble arising when deleting all the objects here # but I have not figure out how to solve the error message. # It looks like 'app' is destroyed before some QObject sys.exit(rc)
def run(): app = QApplication(sys.argv) view = QQuickView() url = QUrl(os.path.join(os.path.dirname(__file__), 'view.qml')) view.setSource(url) view.setResizeMode(QQuickView.SizeRootObjectToView) view.show() app.exec_()
def main(): app = QApplication([]) view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) url = QUrl("HelloWorld.qml") view.setSource(url) if view.status() == QQuickView.Error: sys.exit(-1) view.show() ret = app.exec_() del view sys.exit(ret)
def main(): """ Entry point into program """ app = QGuiApplication(sys.argv) # Register the Backend which can be used in the qml view qmlRegisterType(Backend, 'Interface', 1, 0, 'Backend') # Create a quickview widget and load the view view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) view.setSource(QUrl.fromLocalFile('view.qml')) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make # sure all child QML instances are destroyed in the correct order. # Sept 2019 * Not sure if we still need to do this * del view sys.exit(res)
def main(): """ .qml ファイルのロードする準備 QGuiApplication と QQuickView のインスタンスを生成する """ app = QApplication([]) view = QQuickView() """ Qt Quickの表示方法の設定 PySide2.QtQuick.QQuickView.ResizeMode の enum 定義 表示サイズはQMLのrootのQML rootアイテム(topの QMLオブジェクト)で サイズ変更されます。 QQuickView.SizeViewToRootObject : 表示はQMLの rootアイテム (topのQMLオブジェクト)でサイズ変更する QQuickView.SizeRootObjectToView : 表示は、rootアイテムサイズに QMLのオブジェクトが自動的に調整する """ view.setResizeMode(QQuickView.SizeRootObjectToView) """ 画面表示するQMLコンポーネントの読み出し URL形式で画面表示するQMLファイルを設定する。 """ url = QUrl("HelloWorld.qml") view.setSource(url) if view.status() == QQuickView.Error: sys.exit(-1) # QMLコンポーネントの表示 view.show() # QApplicationのイベントループ ret = app.exec_() """ アプリケーションの終了処理 注意: アプリケーション終了前にQQuickViewのオブジェクトを delしてから終了させる。 """ del view sys.exit(ret)
def viewload(): app = QGuiApplication(sys.argv) view = QQuickView() view_model = URControlViewModel() ur_singal = view_model.gui view.rootContext().setContextProperty("urSingal", ur_singal) # qmlRegisterType(UIsignal, 'PySignal', 1, 0, 'PySignal') # implicit error when using slot and singal qmlRegisterType(ur_visual.FboItem, "QmlVTK", 1, 0, "VtkFboItem") view.setSource(QUrl.fromLocalFile(abs_path("qmlRobotGui\main.qml"))) view.setResizeMode(QQuickView.SizeRootObjectToView) view.setTitle("UR Controller") if view.status() == QQuickView.Error: sys.exit(-1) view.show() root_obj = view.rootObject() view_model.init_connect(root_obj) root_obj.destroyed.connect(view_model.disconnectRobot) app.exec_() # Deleting the view before it goes out of scope is required to make # sure all child QML instances are destroyed in the correct order. del view
self._name = value colorChanged = Signal() color = Property(QColor, getColor, setColor, notify=colorChanged) name = Property(text_type, getName, setName) chartCleared = Signal() @Slot() # This should be something like @Invokable def clearChart(self): self.setColor(Qt.transparent) self.update() self.chartCleared.emit() if __name__ == '__main__': app = QGuiApplication(sys.argv) qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart'); view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) if view.status() == QQuickView.Error: sys.exit(-1) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make sure all child QML instances # are destroyed in the correct order. del view sys.exit(res)
import sys from PySide2.QtWidgets import QApplication from PySide2.QtQuick import QQuickView from PySide2.QtCore import QUrl if __name__ == '__main__': app = QApplication( []) # can use sys.argv in place of [] for command line arguments view = QQuickView() url = QUrl('basic_qml.qml') view.setSource(url) view.setResizeMode( QQuickView.SizeRootObjectToView) # makes the view scale w/ the window view.show() sys.exit(app.exec_()) # run the app until closed
from PySide2.QtWidgets import QApplication from PySide2.QtQuick import QQuickView from PySide2.QtCore import QUrl import sys import os app = QApplication([]) view = QQuickView() current_path = os.path.abspath(os.path.dirname(__file__)) qml_file = os.path.join(current_path, 'view.qml') url = QUrl(qml_file) view.setSource(url) #view.setSource(QUrl.fromLocalFile(qml_file)) if view.status() == QQuickView.Error: sys.exit(-1) # When programming for Desktop: view.setResizeMode( QQuickView.SizeRootObjectToView ) # force the outer QML rectangle to resize along with the outer window view.show() res = app.exec_() # To ensure the correct destruction order, del must be invoked on the view object # before quitting the application. del view sys.exit(res)
# This Python file uses the following encoding: utf-8 import sys from PySide2.QtWidgets import QApplication from PySide2.QtQuick import QQuickView from PySide2.QtCore import QUrl ''' class CupPong(QMainWindow): def __init__(self): QMainWindow.__init__(self) self.setSource(QUrl('qrc:///main.qml')) def init_ui(self): self.resize(480, 320) ''' if __name__ == "__main__": app = QApplication([]) #window = CupPong() #window.show() view = QQuickView() view.setSource(QUrl('main.qml')) view.setResizeMode(QQuickView.SizeViewToRootObject) view.show() sys.exit(app.exec_())
def setName(self, value): self._name = value color = Property(QColor, getColor, setColor) name = Property(text_type, getName, setName) chartCleared = Signal() @Slot() # This should be something like @Invokable def clearChart(self): self.setColor(Qt.transparent) self.update() self.chartCleared.emit() if __name__ == '__main__': app = QGuiApplication(sys.argv) qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart'); view = QQuickView() view.setResizeMode(QQuickView.SizeRootObjectToView) qmlFile = os.path.join(os.path.dirname(__file__), 'app.qml') view.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile))) if view.status() == QQuickView.Error: sys.exit(-1) view.show() res = app.exec_() # Deleting the view before it goes out of scope is required to make sure all child QML instances # are destroyed in the correct order. del view sys.exit(res)
class QTUI(UIBase): def xyToIndex(self, x, y): return y * 8 + x def indexToXY(self, index): return (index % 8, index // 8) def ioThread(self, inputQueue, emitter): while True: io = inputQueue.get() if (io["type"] == UIMessageType.SETUP): player = io["data"]["player_name"] emitter.sendName(player[WHITE], player[BLACK]) elif (io["type"] == UIMessageType.BOARD): for index in range(0, 64): col, row = self.indexToXY(index) item = io["data"][row][col] if (item == BLACK): emitter.send(index, True) elif (item == WHITE): emitter.send(index, False) time.sleep(0.2) elif (io["type"] == UIMessageType.SCORE): emitter.sendScore(io["data"]["o"], io["data"]["x"]) elif (io["type"] == UIMessageType.TURN): turn = io["data"] if turn == "x": emitter.sendMark(True) else: emitter.sendMark(False) elif (io["type"] == UIMessageType.FORFEIT): print("Tidak ada langkah mungkin, skip") elif (io["type"] == UIMessageType.DOTURN): pass elif (io["type"] == UIMessageType.QUIT): break self.inputQueue.task_done() def threadWorker(self): self.app = QGuiApplication() self.view = QQuickView() self.view.setResizeMode(QQuickView.SizeRootObjectToView) #Load the QML file qml_file = os.path.join(os.path.dirname(__file__), "view.qml") self.view.setSource(QUrl.fromLocalFile(os.path.abspath(qml_file))) root = self.view.rootObject() ioHandler = Handler(self.moveQueue) context = self.view.rootContext() context.setContextProperty("handler", ioHandler) #Show the window if self.view.status() == QQuickView.Error: sys.exit(-1) ioSignaler = ioObject(root) input_thread = threading.Thread(target=self.ioThread, args=(self.inputQueue, ioSignaler)) input_thread.start() self.view.show() self.app.exec_() self.inputQueue.put({"type": UIMessageType.QUIT}) input_thread.join() self.outputQueue.put({"type": UICommandType.QUIT}) self.moveQueue.put({"x": -1, "y": -1})