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
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def testQQuickNetworkFactory(self):
        view = QQuickView()
        self.factory = CustomFactory()
        view.engine().setNetworkAccessManagerFactory(self.factory)

        url = QUrl.fromLocalFile(adjust_filename('hw.qml', __file__))

        view.setSource(url)
        view.show()

        self.assertEqual(view.status(), QQuickView.Ready)

        self.app.exec_()
Exemplo n.º 4
0
class QuickWindow(MayaQWidgetBaseMixin, QMainWindow):
    """A window that can be used to display a QML UI in Maya."""
    def __init__(self, url=None, *args, **kwargs):
        super(QuickWindow, self).__init__(*args, **kwargs)
        self.view = QQuickView()
        self.view.statusChanged.connect(self.onStatusChanged)
        self.widget = None
        if url:
            self.setSource(url)
        self.setFocusPolicy(Qt.NoFocus)

    def setContextProperty(self, name, value):
        """Set a context property on the window.

        Context properties are used to handle the interop between QML and Python

        :param name: Name of the property
        :param value: Instance of the property object
        """
        self.view.engine().rootContext().setContextProperty(name, value)

    def addImportPath(self, path):
        """Add a new module import path to the window engine."""
        self.view.engine().addImportPath(path)

    def setSource(self, url):
        if isinstance(url, string_types):
            url = QUrl.fromLocalFile(os.path.abspath(url))
        self.view.setSource(url)
        size = self.view.size()
        self.widget = QWidget.createWindowContainer(self.view, self)
        self.setCentralWidget(self.widget)
        self.setFocusProxy(self.widget)
        self.resize(size)

    def onStatusChanged(self, status):
        if status == QQuickView.Error:
            errors = self.view.errors()
            for error in errors:
                logging.critical(error)
Exemplo n.º 5
0
        if self.data(self.index(i, 0), self.OPENEDFLAG):
            return
        m = ""
        currentmark = self.data(self.index(i, 0), self.MARK)
        if currentmark == "":
            m = "*"
            self.markedCount += 1
        elif currentmark == "*":
            m = "?"
            self.markedCount -= 1
        elif currentmark == "?":
            m = ""
        self.setData(self.index(i, 0), m, self.MARK)


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

    view = QQuickView()

    minesModel = MinesModel()

    ctx = view.rootContext()
    ctx.setContextProperty("minesModel", minesModel)

    view.engine().quit.connect(app.quit)
    view.setSource(QUrl("view.qml"))
    view.show()

    sys.exit(app.exec_())
Exemplo n.º 6
0
## DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
## THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
## (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
## OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
##
## $QT_END_LICENSE$
##
#############################################################################
"""PySide2 port of the QML Polar Chart Example from Qt v5.x"""

import sys
import os
from PySide2.QtQuick import QQuickView
from PySide2.QtCore import Qt, QUrl
from PySide2.QtWidgets import QApplication, QMainWindow

if __name__ == '__main__':
    app = QApplication(sys.argv)
    viewer = QQuickView()

    viewer.engine().addImportPath(os.path.dirname(__file__))
    viewer.engine().quit.connect(viewer.close)

    viewer.setTitle = "QML Polar Chart"
    qmlFile = os.path.join(os.path.dirname(__file__), 'main.qml')
    viewer.setSource(QUrl.fromLocalFile(os.path.abspath(qmlFile)))
    viewer.setResizeMode(QQuickView.SizeRootObjectToView)
    viewer.show()

    sys.exit(app.exec_())
Exemplo n.º 7
0
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.

from PySide2.QtCore import SIGNAL, SLOT, QObject
from PySide2.QtGui import QGuiApplication
from PySide2.QtQuick import QQuickView
from PySide2.QtQml import QQmlEngine
from PySide2.QtCore import QUrl

url = QUrl("generate_raster_assets.qml")
app = QGuiApplication([])
view = QQuickView()
engine = view.engine()

QObject.connect(engine, SIGNAL("quit()"), app, SLOT("quit()"))

view.setSource(url)
view.show()
app.exec_()
Exemplo n.º 8
0
if getattr(sys, 'frozen', False):
    current_dir = sys._MEIPASS
else:
    current_dir = os.path.dirname(os.path.abspath(__file__))

os.environ["QT_QUICK_CONTROLS_CONF"] = os.path.join(current_dir, "view",
                                                    "qtquickcontrols2.conf")
os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"

app = QGuiApplication(sys.argv)
view = QQuickView()
view.setResizeMode(QQuickView.SizeRootObjectToView)

import_path = os.path.join(current_dir, "view", "imports")
view.engine().addImportPath(import_path)

controller = CalculatorController()

view.rootContext().setContextProperty("controller", controller)

filename = os.path.join(current_dir, "view", "Main.qml")
url = QUrl.fromLocalFile(filename)
view.setSource(url)

if view.status() == QQuickView.Error:
    sys.exit(-1)
view.show()
res = app.exec_()

del view
Exemplo n.º 9
0
from PySide2.QtWidgets import QApplication
from PySide2.QtCore import QObject
from PySide2.QtQuick import QQuickView
from PySide2.QtQml import QQmlApplicationEngine
from PySide2.QtCore import QUrl

app = QApplication([])
view = QQuickView()
view.engine().addImportPath("./Modules")
url = QUrl("demo/view.qml")

view.setSource(url)
view.show()
app.exec_()