Example #1
0
    qmlfile = sys.argv[1] if len(
        sys.argv) > 1 else re.sub(r'^(.*)[.]py$', r'\1', sys.argv[0]) + '.qml'
    qmlRegisterType(FileIO, "FileIOPlugin", 1, 0, "FileIO")
    qmlRegisterType(syntaxhighlighter, "SyntaxHighlighter", 1, 0,
                    "SyntaxHighlighter")
    reinstance = Re()
    # if re.search(r'(?:\w+)?Window\s*{',open(qmlfile).read()):
    if re.search(r'^(?<!//)\s*(?:\w+)?Window\s*{\s*$',
                 open(qmlfile).read(),
                 flags=re.MULTILINE) and (
                     not re.search(r'/[*](?![*]/)*?\n\s*(?:\w+)?Window\s*{',
                                   open(qmlfile).read(),
                                   flags=re.DOTALL)
                     or re.search(r'[*]/(?!/[*])*?\n\s*(?:\w+)?Window\s*{',
                                  open(qmlfile).read(),
                                  flags=re.DOTALL)):
        print('applicationwindow->', qmlfile)
        engine = QQmlApplicationEngine()
        engine.rootContext().setContextProperty("re", reinstance)
        engine.load(qmlfile)
    else:
        print('qquickitem->', qmlfile)
        engine = QQuickView()
        engine.setResizeMode(QQuickView.SizeRootObjectToView)
        engine.rootContext().setContextProperty("re", reinstance)
        engine.setSource(qmlfile)
        engine.show()
    res = app.exec()
    del engine
    sys.exit(res)
Example #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_()
Example #3
0
## (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$
##
#############################################################################

"""PySide6 port of the QML Polar Chart Example from Qt v5.x"""

import sys
import os
from PySide6.QtQuick import QQuickView
from PySide6.QtCore import Qt, QUrl
from PySide6.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_())