1#!/usr/local/bin/python3.8
2# -*- coding: utf-8 -*-
3
4# Copyright (c) 2006 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
5#
6
7"""
8eric Compare.
9
10This is the main Python script that performs the necessary initialization
11of the Compare module and starts the Qt event loop. This is a standalone
12version of the integrated Compare module.
13"""
14
15import sys
16import os
17
18sys.path.insert(1, os.path.dirname(__file__))
19
20for arg in sys.argv[:]:
21    if arg.startswith("--config="):
22        import Globals
23        configDir = arg.replace("--config=", "")
24        Globals.setConfigDir(configDir)
25        sys.argv.remove(arg)
26    elif arg.startswith("--settings="):
27        from PyQt5.QtCore import QSettings
28        settingsDir = os.path.expanduser(arg.replace("--settings=", ""))
29        if not os.path.isdir(settingsDir):
30            os.makedirs(settingsDir)
31        QSettings.setPath(
32            QSettings.Format.IniFormat, QSettings.Scope.UserScope, settingsDir)
33        sys.argv.remove(arg)
34
35from Globals import AppInfo
36
37from Toolbox import Startup
38
39
40def createMainWidget(argv):
41    """
42    Function to create the main widget.
43
44    @param argv list of commandline parameters (list of strings)
45    @return reference to the main widget (QWidget)
46    """
47    from UI.CompareDialog import CompareWindow
48    if len(argv) >= 6:
49        # assume last two entries are the files to compare
50        file1 = (argv[-4], argv[-2])
51        file2 = (argv[-3], argv[-1])
52        return CompareWindow([file1, file2])
53    elif len(argv) >= 2:
54        return CompareWindow([("", argv[-2]), ("", argv[-1])])
55    else:
56        return CompareWindow()
57
58
59def main():
60    """
61    Main entry point into the application.
62    """
63    from PyQt5.QtGui import QGuiApplication
64    QGuiApplication.setDesktopFileName("eric6_compare.desktop")
65
66    options = [
67        ("--config=configDir",
68         "use the given directory as the one containing the config files"),
69        ("--settings=settingsDir",
70         "use the given directory to store the settings files"),
71    ]
72    appinfo = AppInfo.makeAppInfo(sys.argv,
73                                  "eric Compare",
74                                  "",
75                                  "Simple graphical compare tool",
76                                  options)
77    res = Startup.simpleAppStartup(sys.argv,
78                                   appinfo,
79                                   createMainWidget)
80    sys.exit(res)
81
82if __name__ == '__main__':
83    main()
84