Exemple #1
0
def main():
    print(f'PySide6=={PySideVer} Qt=={QtVer}')

    parser = ArgumentParser(
        description='cappuccino: Simple image viewer with download')
    parser.add_argument('download_keyword',
                        nargs='?',
                        default='',
                        help='image keyword to download')
    args = parser.parse_args()

    download_keyword = args.download_keyword
    if not download_keyword and not exist_images():
        download_keyword = DEFAULT_KEYWORD

    initialize_qt()

    app = QGuiApplication(sys.argv)
    app.setWindowIcon(QIcon(resource_path('cappuccino.ico')))

    is_download = download_keyword != ''
    mmodel = MainModel(is_download, IMAGES_DIR_NAME)
    dmodel = DownloaderModel(download_keyword, IMAGES_DIR_NAME)
    imodel = ImageViewerModel(IMAGES_DIR_NAME)
    dmodel.download_completed.connect(mmodel.on_download_completed)

    engine = QQmlApplicationEngine()
    engine.rootContext().setContextProperty('mmodel', mmodel)
    engine.rootContext().setContextProperty('dmodel', dmodel)
    engine.rootContext().setContextProperty('imodel', imodel)
    engine.load(f'file:///{resource_path("qml/Main.qml")}')

    if not engine.rootObjects():
        sys.exit(-1)
    sys.exit(app.exec())
Exemple #2
0
import sys

from PySide6.QtGui import QGuiApplication, QIcon
from PySide6.QtQml import QQmlApplicationEngine

from backend import BackEnd
import resources_rc

app = QGuiApplication(sys.argv)
app.setWindowIcon(QIcon(r"icons\icon.ico"))

backend = BackEnd(app)

engine = QQmlApplicationEngine()
engine.quit.connect(app.quit)
engine.load('main.qml')
engine.rootContext().setContextProperty('backend', backend)

sys.exit(app.exec())