aboutsummaryrefslogtreecommitdiffstats
path: root/examples/demos/documentviewer/main.py
blob: 2af373ef33dd3af1a45f4ff4a89e953792d80fbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# Copyright (C) 2023 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

"""PySide6 port of the Qt Document Viewer demo from Qt v6.x"""

import sys
from argparse import ArgumentParser, RawTextHelpFormatter

from PySide6.QtWidgets import QApplication
from PySide6.QtCore import QCoreApplication

from mainwindow import MainWindow


DESCRIPTION = "A viewer for JSON, PDF and text files"


if __name__ == "__main__":

    app = QApplication([])
    QCoreApplication.setOrganizationName("QtExamples")
    QCoreApplication.setApplicationName("DocumentViewer")
    QCoreApplication.setApplicationVersion("1.0")

    arg_parser = ArgumentParser(description=DESCRIPTION,
                                formatter_class=RawTextHelpFormatter)
    arg_parser.add_argument("file", type=str, nargs="?",
                            help="JSON, PDF or text file to open")
    args = arg_parser.parse_args()
    fileName = args.file

    w = MainWindow()
    w.show()
    if args.file and not w.openFile(args.file):
        sys.exit(-1)

    sys.exit(app.exec())