Ejemplo n.º 1
0
    colorChanged = Signal()
    color = Property(QColor, getColor, setColor, notify=colorChanged)
    name = Property(str, 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)
Ejemplo n.º 2
0
            self.load_from_json(filename)

    def load_from_json(self,filename):
        """Load list of cities from given file"""
        with open(filename,encoding="utf-8") as f:
            self.city_list = json.load(f)

    def rowCount(self, parent:QtCore.QModelIndex=...) -> int:
        """ Return number of cities in the list"""
        return len(self.city_list)

    def data(self, index:QtCore.QModelIndex, role:int=...) -> typing.Any:
        """ For given index and DisplayRole return name of the selected city"""
        # Return None if the index is not valid
        if not index.isValid():
            return None
        # If the role is the DisplayRole, return name of the city
        if role == QtCore.Qt.DisplayRole:
            return self.city_list[index.row()]["muniLabel"]


app = QGuiApplication(sys.argv)
view = QQuickView()
url = QUrl(VIEW_URL)
citylist_model = CityListModel(CITY_LIST_FILE)
ctxt = view.rootContext()
ctxt.setContextProperty('cityListModel',citylist_model)
view.setSource(url)
view.show()
app.exec_()
Ejemplo n.º 3
0
    url = "http://country.io/names.json"
    response = urllib.request.urlopen(url)
    data = json.loads(response.read().decode('utf-8'))
    # print("data",data)
    # Format and sort the data
    data_list = list(data.values())
    # print("data_list", data_list)
    data_list.sort()

    # Set up the application window
    app = QGuiApplication(sys.argv)
    view = QQuickView()
    view.setResizeMode(QQuickView.SizeRootObjectToView)

    # Expose the list to the Qml code
    my_model = QStringListModel()
    my_model.setStringList(data_list)
    view.rootContext().setContextProperty("myModel", my_model)

    # Load the QML file
    qml_file = Path(__file__).parent / "main_view.qml"
    view.setSource(QUrl.fromLocalFile(os.fspath(qml_file.resolve())))

    # Show the window
    if view.status() == QQuickView.Error:
        sys.exit(-1)
    view.show()
    # execute and cleanup
    app.exec()
    del view
Ejemplo n.º 4
0
    @Slot(str)
    def outputStr(self, s):
        print(s)

    @Slot('double')
    def outputFloat(self, x):
        print(x)


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

    # Instantiate the Python object.
    con = Console()

    # Expose the object to QML.
    context = view.rootContext()
    context.setContextProperty("con", con)

    #qml_file = os.fspath(Path(__file__).resolve().parent / 'qml_test2.qml')
    view.setSource(QUrl("Source/away_from_keyboard/qml_test2.qml"))
    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)
Ejemplo n.º 5
0
        painter.drawRoundedRect(0, 0, itemSize.width(), itemSize.height() - 10, 10, 10)

        if self.rightAligned:
            points = [
                QPointF(itemSize.width() - 10.0, itemSize.height() - 10.0),
                QPointF(itemSize.width() - 20.0, itemSize.height()),
                QPointF(itemSize.width() - 30.0, itemSize.height() - 10.0),
            ]
        else:
            points = [
                QPointF(10.0, itemSize.height() - 10.0),
                QPointF(20.0, itemSize.height()),
                QPointF(30.0, itemSize.height() - 10.0),
            ]
        painter.drawConvexPolygon(points)


if __name__ == "__main__":

    app = QApplication(sys.argv)
    view = QQuickView()
    view.setResizeMode(QQuickView.SizeRootObjectToView)
    qmlRegisterType(TextBalloon, "TextBalloonPlugin", 1, 0, "TextBalloon")
    view.setSource(QUrl.fromLocalFile("main.qml"))

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

    sys.exit(app.exec_())
Ejemplo n.º 6
0
from PySide6.QtCore import QUrl
from PySide6.QtGui import QGuiApplication
from PySide6.QtQuick import QQuickView
import sys

VIEW_PATH = "view.qml"

# Create the application object and pass command line arguments to it
app = QGuiApplication(sys.argv)

# Create the view object
view = QQuickView()
# Set the QML file to view
view.setSource(QUrl(VIEW_PATH))
# Resize the view with the window
view.setResizeMode(QQuickView.ResizeMode.SizeRootObjectToView)
# Show the view (open the window)
view.show()

# Run the event loop
app.exec_()
Ejemplo n.º 7
0
    time_cnt = time_cnt + 1
    #print(time_cnt)
    label.send_text.emit(str(time_cnt))
    


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

    timer = QTimer()
    timer.start(1000)

    view = QQuickView()
    qml_file = "Source/away_from_keyboard/qml_test3.qml"
    view.setSource(QUrl.fromLocalFile(qml_file))
    if view.status() == QQuickView.Error:
        sys.exit(-1)
    root = view.rootObject()

    timer.timeout.connect(root.updateRotater)
    #timer.timeout.connect(root.updateTime, text)

    timer.timeout.connect(time_out)

    label = PyLabel()
    label.send_text.connect(root.updateTime)

    con = Console()

    # Expose the object to QML.