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)
예제 #2
0
def main():
    from misc.ui_generator import UiGenerator
    import example.constants as const
    ui_generator = UiGenerator(ui_dir=const.UI_FILE_DIR,
                               rc_dir=const.RC_FILE_DIR,
                               out_dir=const.GUI_COMPILE_OUTPUT)
    ui_generator.compile_all()

    import example.gui.rc_qml as rc_qml
    rc_qml.qInitResources()

    from misc.debug import qt_message_handler
    QtCore.qInstallMessageHandler(qt_message_handler)
    app = ExampleApp(sys.argv)

    engine = QQmlApplicationEngine()
    qmlRegisterType(QmlOpenGLWindowInteractor, "QmlVTK", 1, 0, "Interactor")

    context = engine.rootContext()
    main_window = MainWindow()
    engine.setContextForObject(main_window, context)
    context.setContextProperty("mainWindow", main_window)

    engine.load(QUrl.fromLocalFile(":/qml/app.qml"))

    if len(engine.rootObjects()) == 0:
        logging.error("No QML file is loaded. Application Exit!")
        return

    sys.exit(app.exec_())
예제 #3
0
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 appload():
    '''
    When using QmlApplicationEngine() to load qml-vtk window, in the unlikely event,
    you will encounter the following problems: the QML window is stuck.

    Please check if you: import pyside2, and use QmlApplicationEngine().load to load only one qml-vtk window
    (such as main.qml in here containing custom qmlRegisterType 【import QmlVTK 1.0】) .
    If you have to do this, plus self.createRenderer () to __ init__ function, fboitem class.
    Then it works but an error window, vtkoutputwindow, will be displayed.
    Then try to close the vtkoutputwindow (maybe call the Win32 API findwindow?)

    Recommended solution: import PyQt5 instead of pyside2;
    Or using QQuickView().setSource to load qml window;
    Or load another independent general qml window before load the qml-vtk window.
    '''
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    view_model = URControlViewModel()
    ur_singal = view_model.gui  # 这样在urgui里面定义的变量可以用self,否则只能定义全局变量
    engine.rootContext().setContextProperty("urSingal", ur_singal)
    qmlRegisterType(ur_visual.FboItem, "QmlVTK", 1, 0, "VtkFboItem")
    # qmlRegisterType(UIsignal, 'PySignal', 1, 0, 'PySignal') # implicit error when using slot and singal
    engine.load(os.path.join(os.path.dirname(__file__),
                             "qmlRobotGui\main.qml"))
    if not engine.rootObjects():
        sys.exit(-1)
    root_obj = engine.rootObjects()[0]
    view_model.init_connect(root_obj)
    #    print(type(root_obj))
    root_obj.destroyed.connect(view_model.disconnectRobot)
    sys.exit(app.exec_())
예제 #5
0
    def __init__(self, argv):
        self.plumbing_bridge = PlumbingBridge()
        self.procedures_bridge = ProceduresBridge(self.plumbing_bridge)
        self.daq_bridge = DAQBridge(self.plumbing_bridge)

        self.app = QApplication(argv)

        # ALL custom built QQuickItems have to be registered as QML objects in this way:
        qmlRegisterType(QMLVisualizationArea, 'VisualizationArea', 1, 0,
                        'VisualizationArea')

        self.app.setWindowIcon(QIcon(find_resource('icon.ico')))
        self.app.setOrganizationName('Waterloo Rocketry')
        self.app.setOrganizationDomain('waterloorocketry.com')
        self.app.setApplicationName('Topside')

        self.qml_engine = QQmlEngine()
        context = self.qml_engine.rootContext()
        context.setContextProperty('plumbingBridge', self.plumbing_bridge)
        context.setContextProperty('proceduresBridge', self.procedures_bridge)

        self.main_window = self._make_main_window()

        # TODO(jacob): Currently we load these example files at startup
        # to make testing turnaround a bit faster. Figure out how to
        # make the application remember the last file opened, and open
        # that instead.
        self.plumbing_bridge.load_from_files([find_resource('example.pdl')])
        self.procedures_bridge.load_from_file(find_resource('example.proc'))
예제 #6
0
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)
예제 #7
0
def athenumEngineStart():
    app = QGuiApplication(sys.argv)
    athenumInfo = AthenumInfo()

    if len(sys.argv) > 1:
        if sys.argv[1] == '-platform' and sys.argv[2].find('webgl') != -1:
            print("Starting WebGl mode")
            athenumInfo.setWebGL()
        if sys.argv[1] == '-c':
            print("Console mode activated")
            consoleMode(sys.argv)
            sys.exit(0)

    app.setApplicationName("Full reptend prime & cyclic prime numbers")
    engine = QQmlApplicationEngine()
    platformName = platform.system()
    print('Platform name is', platformName)
    from Rational import Rational
    qmlRegisterType(Rational, 'Athenum', 1, 0, 'Rational')
    athenumModuleImport("SumModels")
    athenumModuleImport("DigitalCircle")
    athenumModuleImport("PrimeScales")
    athenumModuleImport("IntervalScales")
    athenumModuleImport("CyclicPrimes")
    athenumModuleImport("Primes")
    athenumModuleImport("GeometricProgression")
    athenumModuleImport("NumericSystem")
    copyClipboard = CopyClipboard()
    engine.rootContext().setContextProperty("athenumInfo", athenumInfo)
    engine.rootContext().setContextProperty("copyClipboard", copyClipboard)
    engine.load('qml/athenum.qml')
    print("Starting viewer")
    res = app.exec_()
    del engine
    sys.exit(res)
예제 #8
0
    def testSignalEmission(self):
        qmlRegisterType(MyItem, "my.item", 1, 0, "MyItem")

        view = QQuickView()
        view.setSource(QUrl.fromLocalFile(adjust_filename('bug_951.qml', __file__)))

        self.app.exec_()
        self.assertTrue(MyItem.COMPONENT_COMPLETE_CALLED)
예제 #9
0
    def install(self):
        from PySide2.QtQml import qmlRegisterType
        import importlib

        pkg = importlib.import_module(self._path)
        for export in pkg.qmlexports:
            qmlRegisterType(export['class'], export['uri'], export['major'],
                            export['minor'], export['exportName'])
예제 #10
0
    def testSignalEmission(self):
        qmlRegisterType(MyItem, "my.item", 1, 0, "MyItem")

        view = QQuickView()
        view.setSource(QUrl.fromLocalFile(adjust_filename('bug_951.qml', __file__)))

        self.app.exec_()
        self.assertTrue(MyItem.COMPONENT_COMPLETE_CALLED)
예제 #11
0
def registerTypes():
    from PySide2.QtQml import qmlRegisterType
    from meshroom.ui.components.edge import EdgeMouseArea
    from meshroom.ui.components.filepath import FilepathHelper

    qmlRegisterType(EdgeMouseArea, "GraphEditor", 1, 0, "EdgeMouseArea")
    qmlRegisterType(FilepathHelper, "Meshroom.Helpers", 1, 0,
                    "FilepathHelper")  # TODO: uncreatable
예제 #12
0
    def __init__(self, sys_argv):
        super().__init__()
        self.__m_previousWorldX: float = 0.0
        self.__m_previousWorldY: float = 0.0
        self.__m_draggingMouse: bool = False
        self.__m_showFileDialog: bool = False
        self.__m_vtkFboItem = None
        #* Set style: https://stackoverflow.com/questions/43093797/PySide2-quickcontrols-material-style
        sys_argv += ['--style', 'material']  #! MUST HAVE
        app = QApplication(sys_argv)

        engine = QQmlApplicationEngine()
        # engine.setImportPathList(['C:\\Users\\tungdao\\.conda\\envs\\qtvtkpy\\Lib\\site-packages\\PySide2\\qml'])
        # print(engine.importPathList())
        app.setApplicationName('QtVTK-Py')

        #* Register QML Types
        qmlRegisterType(Squircle, 'QtVTK', 1, 0, 'VtkFboItem')

        # #* Create classes instances
        self.__m_processingEngine = ProcessingEngine()

        # #* Expose/Bind Python classes (QObject) to QML
        ctxt = engine.rootContext()  # returns QQmlContext
        ctxt.setContextProperty('canvasHandler', self)

        # #* Load main QML file
        engine.load(QUrl.fromLocalFile('resources\\main.qml'))

        # #* Get reference to the QVTKFramebufferObjectItem in QML
        rootObject = engine.rootObjects()[0]  # returns QObject
        self.__m_vtkFboItem = rootObject.findChild(Squircle, 'vtkFboItem')

        # # #* Give the vtkFboItem reference to the CanvasHandler
        if (self.__m_vtkFboItem):
            qDebug(
                'CanvasHandler::CanvasHandler: setting vtkFboItem to CanvasHandler'
            )
            self.__m_vtkFboItem.setProcessingEngine(self.__m_processingEngine)

            self.__m_vtkFboItem.rendererInitialized.connect(
                self.startApplication)
            self.__m_vtkFboItem.isModelSelectedChanged.connect(
                self.isModelSelectedChanged)
            self.__m_vtkFboItem.selectedModelPositionXChanged.connect(
                self.selectedModelPositionXChanged)
            self.__m_vtkFboItem.selectedModelPositionYChanged.connect(
                self.selectedModelPositionYChanged)
        else:
            qCritical(
                'CanvasHandler::CanvasHandler: Unable to get vtkFboItem instance'
            )
            return

        rc = app.exec_()
        qDebug(
            f'CanvasHandler::CanvasHandler: Execution finished with return code: {rc}'
        )
예제 #13
0
 def testIt(self):
     app = QGuiApplication([])
     qmlRegisterType(MyClass,'Example',1,0,'MyClass')
     view = QQuickView()
     view.setSource(QUrl.fromLocalFile(adjust_filename('bug_926.qml', __file__)))
     self.assertEqual(len(view.errors()), 0)
     view.show()
     QTimer.singleShot(0, app.quit)
     app.exec_()
예제 #14
0
    def test_qml_type(self):
        qmlRegisterType(TestClass, "JavaScriptExceptions", 1, 0, "JavaScriptExceptions")

        view = QQuickView()
        qml_url = QUrl.fromLocalFile(adjust_filename("javascript_exceptions.qml", __file__))

        view.setSource(qml_url)

        self.assertTrue(test_1)
        self.assertTrue(test_2)
예제 #15
0
 def testIt(self):
     app = QGuiApplication([])
     qmlRegisterType(MyClass, 'Example', 1, 0, 'MyClass')
     view = QQuickView()
     view.setSource(
         QUrl.fromLocalFile(adjust_filename('bug_926.qml', __file__)))
     self.assertEqual(len(view.errors()), 0)
     view.show()
     QTimer.singleShot(0, app.quit)
     app.exec_()
예제 #16
0
 def __init__(self, plugins=None, template_path=None):
     self.plugins = []
     for p in plugins:
         qmlRegisterType(
             p, 
             p.verbose_name, 
             p.version.major, 
             p.version.minor, 
             p.service_name
         )
         self.plugins.append(plugins)
예제 #17
0
    def test_qml_type(self):
        qmlRegisterType(TestClass, 'JavaScriptExceptions', 1, 0,
                        'JavaScriptExceptions')

        view = QQuickView()
        qml_url = QUrl.fromLocalFile(
            adjust_filename('javascript_exceptions.qml', __file__))

        view.setSource(qml_url)

        self.assertTrue(test_1)
        self.assertTrue(test_2)
예제 #18
0
파일: bug_825.py 프로젝트: zhoub/pyside2
    def testIt(self):
        global paintCalled
        app = QGuiApplication([])
        qmlRegisterType(Bug825, 'bugs', 1, 0, 'Bug825')
        self.assertRaises(TypeError, qmlRegisterType, A, 'bugs', 1, 0, 'A')

        view = QQuickView()
        view.setSource(QUrl.fromLocalFile(adjust_filename('bug_825.qml', __file__)))
        view.show()
        QTimer.singleShot(250, view.close)
        app.exec_()
        self.assertTrue(paintCalled)
예제 #19
0
    def testIt(self):
        app = QGuiApplication([])

        qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart');
        qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice");

        view = QQuickView()
        view.setSource(QUrl.fromLocalFile(helper.adjust_filename('registertype.qml', __file__)))
        view.show()
        QTimer.singleShot(250, view.close)
        app.exec_()
        self.assertTrue(appendCalled)
        self.assertTrue(paintCalled)
예제 #20
0
파일: main.py 프로젝트: SeanHsieh/SLAM_Qt
def main():
    sys.argv += ['--style', 'material']
    app = QApplication(sys.argv)

    QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
    QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

    qmlRegisterType(Map, 'Map', 1, 0, 'Map')
    qmlRegisterType(Bot, 'Bot', 1, 0, 'Bot')

    engine = QQmlApplicationEngine('main.qml')

    sys.exit(app.exec_())
예제 #21
0
파일: main.py 프로젝트: Ryuno-Ki/crimpy
    def __setup(self):
        self.__current_language = QLocale.system().name()
        self.__de_translator = QTranslator()

        self.translation_directory = os.path.abspath(
            os.path.join(os.path.dirname(__file__), "crimpy", "languages"))

        self.__engine = QQmlApplicationEngine()
        self.__root_context = RootContext()
        self.__engine.rootContext().setContextProperty("main",
                                                       self.__root_context)
        qmlRegisterType(TwitterConnector, 'Twitter', major, minor,
                        'TwitterModel')
        self.__engine.load(QUrl.fromLocalFile(qml_file))
예제 #22
0
    def testIt(self):
        app = QGuiApplication([])

        qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart')
        qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice")

        view = QQuickView()
        view.setSource(
            QUrl.fromLocalFile(adjust_filename('registertype.qml', __file__)))
        view.show()
        QTimer.singleShot(250, view.close)
        app.exec_()
        self.assertTrue(appendCalled)
        self.assertTrue(paintCalled)
def main():
    print('main()')

    qmlRegisterType(MatplotlibController, "Matplot", 1, 0, "Matplot")

    app = QApplication(sys.argv)
    engine = QQmlApplicationEngine()
    main_controller = MainController(app)
    context = engine.rootContext()
    context.setContextProperty("main", main_controller)
    script_directory = os.path.dirname(os.path.abspath(__file__))
    engine.load(os.path.join(script_directory, 'qml/main.qml'))

    main_controller.start()

    sys.exit(app.exec_())
예제 #24
0
def registerTypes():
    from PySide2.QtQml import qmlRegisterType
    from meshroom.ui.components.clipboard import ClipboardHelper
    from meshroom.ui.components.edge import EdgeMouseArea
    from meshroom.ui.components.filepath import FilepathHelper
    from meshroom.ui.components.scene3D import Scene3DHelper, TrackballController

    qmlRegisterType(EdgeMouseArea, "GraphEditor", 1, 0, "EdgeMouseArea")
    qmlRegisterType(ClipboardHelper, "Meshroom.Helpers", 1, 0,
                    "ClipboardHelper")  # TODO: uncreatable
    qmlRegisterType(FilepathHelper, "Meshroom.Helpers", 1, 0,
                    "FilepathHelper")  # TODO: uncreatable
    qmlRegisterType(Scene3DHelper, "Meshroom.Helpers", 1, 0,
                    "Scene3DHelper")  # TODO: uncreatable
    qmlRegisterType(TrackballController, "Meshroom.Helpers", 1, 0,
                    "TrackballController")
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 = QApplication(argv)

    qmlRegisterType(FigureCanvasQTAgg, "Backend", 1, 0, "FigureCanvasByPython")
    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()

    # !! You must specified the QApplication as parent of QQmlApplicationEngine
    # otherwise a segmentation fault is raised when exiting the app
    engine = QQmlApplicationEngine(parent=app)
    engine.addImageProvider("mplIcons", imgProvider)

    context = engine.rootContext()
    data_model = DataSeriesModel()
    context.setContextProperty("dataModel", data_model)
    mainApp = Form(data=data_model)
    context.setContextProperty("draw_mpl", mainApp)

    engine.load(
        QUrl(str(pathlib.Path(__file__).parent / 'main_mpl_qtquick_main.qml')))

    win = engine.rootObjects()[0]

    figure = win.findChild(QObject, "figure")
    mainApp.figure = figure.getFigure()

    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)
예제 #26
0
def main():
    app = QGuiApplication(sys.argv)
    qmlRegisterType(Backend, 'PythonBackendLibrary', 1, 0, 'PythonBackend')

    qml_file = 'main.qml'
    current_dir = os.path.dirname(os.path.realpath(__file__))
    filename = os.path.join(current_dir, qml_file)

    backend = Backend()
    engine = QQmlApplicationEngine()
    win = engine.rootContext()
    engine.load(QUrl.fromLocalFile(filename))

    rospy.init_node('rospy_qt_quick')

    if not engine.rootObjects():
        sys.exit(-1)
    sys.exit(app.exec_())
예제 #27
0
def main():
    app = QGuiApplication(sys.argv)

    # QtWebEngine.initialize()

    qmlRegisterType(BackEnd, 'io.qml.locals', 1, 0, 'BackEnd')

    engine = QQmlApplicationEngine()

    context = engine.rootContext()

    myVar = {"A": 18, "B": {"C": 74}}

    context.setContextProperty("myVar", myVar)

    qml_file = os.path.join(BASE_DIR, 'view.qml')
    engine.load(QUrl.fromLocalFile(qml_file))

    if not engine.rootObjects():
        sys.exit(-1)
    sys.exit(app.exec_())
예제 #28
0
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)
예제 #29
0
    def __init__(self, sys_argv):
        super().__init__()
        self.__m_vtkFboItem = None
        #* Set style: https://stackoverflow.com/questions/43093797/PySide2-quickcontrols-material-style
        sys_argv += ['--style', 'material'] #! MUST HAVE


        QApplication.setAttribute( Qt.AA_UseDesktopOpenGL )
        QtGui.QSurfaceFormat.setDefaultFormat(defaultFormat(False)) # from vtk 8.2.0
        app = QApplication(sys_argv)

        engine = QQmlApplicationEngine()
        app.setApplicationName('QtVTK-Py')

        # Register QML Types
        qmlRegisterType(FboItem, 'QtVTK', 1, 0, 'VtkFboItem')

        # Expose/Bind Python classes (QObject) to QML
        ctxt = engine.rootContext() # returns QQmlContext
        ctxt.setContextProperty('canvasHandler', self)
        self.dataProvider = ChartDataProvider()
        ctxt.setContextProperty('chartDataProvider', self.dataProvider)

        # Load main QML file
        engine.load(QUrl.fromLocalFile('resources/main.qml'))

        # Get reference to the QVTKFramebufferObjectItem in QML
        rootObject = engine.rootObjects()[0] # returns QObject
        self.__m_vtkFboItem = rootObject.findChild(FboItem, 'vtkFboItem')

        # Give the vtkFboItem reference to the CanvasHandler
        if (self.__m_vtkFboItem):
            qDebug('CanvasHandler::CanvasHandler: setting vtkFboItem to CanvasHandler')
            self.__m_vtkFboItem.rendererInitialized.connect(self.startApplication)
        else:
            qCritical('CanvasHandler::CanvasHandler: Unable to get vtkFboItem instance')
            return

        rc = app.exec_()
        qDebug(f'CanvasHandler::CanvasHandler: Execution finished with return code: {rc}')
예제 #30
0
def main(verbosity, log_to_file):

    # Configure the LogConfigurator and instantiate logger for this module
    logConfig = LogConfigurator(verbosity="DEBUG",
                                output_to_logfile=log_to_file)

    # Create the QML Application and Engine
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()

    # Instantiate custom python classes and add them to QML engine
    nav_buttons = NavigationButton()
    search_panels = SearchPanel()
    qmlRegisterType(NavigationButton, "NavigationButton", 1, 0,
                    "NavigationButton")
    qmlRegisterType(SearchPanel, "Search", 1, 0, "SearchPanel")
    qmlRegisterType(NodeManager, "Node", 1, 0, "NodeManager")

    # Load the main QML file
    engine.load(QUrl("learn_ml/ui/app.qml"))

    if not engine.rootObjects():
        sys.exit(-1)

    # Begin execution
    sys.exit(app.exec_())
예제 #31
0
def main():
    app = App(sys.argv)
    engine = QQmlApplicationEngine()

    app.setApplicationName('vtkMolecule_QML')

    qmlRegisterType(FboItem, 'QtVTK', 1, 0, 'VtkFboItem')

    handler = canvasHandler()

    # Expose/Bind Python classes (QObject) to QML
    ctxt = engine.rootContext()  # returns QQmlContext
    ctxt.setContextProperty('canvasHandler', handler)

    # Load main QML file
    engine.load(QUrl.fromLocalFile('Mixed/main.qml'))

    app.setup(engine)
    handler.fbo = app._m_vtkFboItem

    rc = app.exec_()
    qDebug(f'CanvasHandler: Execution finished with return code: {rc}')
def main():
    # QApplication.setAttribute( Qt.AA_UseDesktopOpenGL )
    # QSurfaceFormat.setDefaultFormat(utils.defaultFormat(False)) # from vtk 8.2.0
    app = QGuiApplication(sys.argv)
    app.setApplicationName('QtVTK-Py')
    # qmlRegisterType(FboItem, "QmlVTK", 1, 0, "Interactor")
    qmlRegisterType(FboItem, "QtVTK", 1, 0, "VtkFboItem")

    view = QQuickView()  # qml file must begin with Item, not ApplicationWindow
    view.setSource(QUrl.fromLocalFile(abs_path("main.qml")))
    # view.setTitle ("QQuickView Load")
    # view.setResizeMode(QQuickView.SizeRootObjectToView)
    #    view.setFlags(Qt.FramelessWindowHint)
    view.show()
    '''
    In the unlikely event, you will encounter the following problems: the QML window is stuck.

    Please check if you: import pyside2, and use QmlApplicationEngine().load to load only one qml-vtk window(containing qmlRegisterType class) .
    If you have to do this, plus self.createRenderer () to __ init__ function, fboitem class.
    Then it works but an error window, vtkoutputwindow, will be displayed.
    Then try to close the vtkoutputwindow (maybe call the Win32 API findwindow?)

    Recommended solution: import PyQt5 instead of pyside2;
    Or using QQuickView().setSource to load qml window;
    Or load another independent general qml window before load the qml-vtk window.

    '''
    #    engine1 = QQmlApplicationEngine()  # qml file must begin with ApplicationWindow, not Item
    #    engine1.load(os.path.join(os.path.dirname(__file__), "main.qml")) # another independent general qml window

    #    engine = QQmlApplicationEngine()
    #    engine.load(os.path.join(os.path.dirname(__file__), "app.qml"))  # the qml-vtk window
    #    if not engine.rootObjects():
    #        sys.exit(-1)

    sys.exit(app.exec_())
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
def main():
    argv = sys.argv

    # Trick to set the style / not found how to do it in pythonic way
    argv.extend(["-style", "universal"])
    app = QGuiApplication(argv)

    # why needed now?
    app.setOrganizationName("Some Company")
    app.setOrganizationDomain("somecompany.com")
    app.setApplicationName("Amazing Application")

    qmlRegisterType(FigureCanvasQTAggToolbar, "Backend", 1, 0, "FigureToolbar")
    imgProvider = MatplotlibIconProvider()

    # !! You must specified the QApplication as parent of QQmlApplicationEngine
    # otherwise a segmentation fault is raised when exiting the app
    engine = QQmlApplicationEngine(parent=app)
    engine.addImageProvider("mplIcons", imgProvider)

    context = engine.rootContext()
    data_model = DataSeriesModel()
    context.setContextProperty("dataModel", data_model)
    mainApp = Form(data=data_model)
    context.setContextProperty("draw_mpl", mainApp)

    engine.load(QUrl('main.qml'))

    win = engine.rootObjects()[0]
    mainApp.figure = win.findChild(QObject, "figure").getFigure()

    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)
예제 #35
0
    def setName(self, value):
        self._name = value

    name = Property(text_type, getName, setName)

    def appendSlice(self, _slice):
        _slice.setParentItem(self)
        self._slices.append(_slice)

    slices = ListProperty(PieSlice, appendSlice)

if __name__ == '__main__':
    app = QGuiApplication(sys.argv)

    qmlRegisterType(PieChart, 'Charts', 1, 0, 'PieChart')
    qmlRegisterType(PieSlice, "Charts", 1, 0, "PieSlice")

    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)
예제 #36
0
        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)
예제 #37
0
파일: model.py 프로젝트: e8johan/qmlbook
        psutil.cpu_percent(percpu=True)
            
    def __update(self):
        self.__cpu_load = psutil.cpu_percent(percpu=True)
        self.dataChanged.emit(self.index(0,0), self.index(self.__cpu_count-1, 0))
        
    def rowCount(self, parent):
        return self.__cpu_count
    
    def data(self, index, role):
        if (role == Qt.DisplayRole and
            index.row() >= 0 and
            index.row() < len(self.__cpu_load) and
            index.column() == 0):
            return self.__cpu_load[index.row()]
        else:
            return None

if __name__ == '__main__':
    app = QGuiApplication(sys.argv)
    engine = QQmlApplicationEngine()
    
    qmlRegisterType(CpuLoadModel, 'PsUtils', 1, 0, 'CpuLoadModel')
    
    engine.load(QUrl("main.qml"))
    
    if not engine.rootObjects():
        sys.exit(-1)    
    
    sys.exit(app.exec_())
예제 #38
0
def register_qml_types():
    class TestClass(QQuickItem):
        def __init__(self, parent = None):
            QQuickItem.__init__(self, parent)

    qmlRegisterType(TestClass, "UserTypes", 1, 0, "TestClass")