]> git.lizzy.rs Git - torbrowser-launcher.git/blob - torbrowser_launcher/__init__.py
Update copyright to 2021
[torbrowser-launcher.git] / torbrowser_launcher / __init__.py
1 """
2 Tor Browser Launcher
3 https://github.com/micahflee/torbrowser-launcher/
4
5 Copyright (c) 2013-2021 Micah Lee <micah@micahflee.com>
6
7 Permission is hereby granted, free of charge, to any person
8 obtaining a copy of this software and associated documentation
9 files (the "Software"), to deal in the Software without
10 restriction, including without limitation the rights to use,
11 copy, modify, merge, publish, distribute, sublicense, and/or sell
12 copies of the Software, and to permit persons to whom the
13 Software is furnished to do so, subject to the following
14 conditions:
15
16 The above copyright notice and this permission notice shall be
17 included in all copies or substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 OTHER DEALINGS IN THE SOFTWARE.
27 """
28
29 import os
30 import sys
31 import argparse
32 import signal
33
34 from PyQt5 import QtCore, QtWidgets
35
36 from .common import Common, SHARE
37 from .settings import Settings
38 from .launcher import Launcher
39
40
41 class Application(QtWidgets.QApplication):
42     """
43     Qt's QApplication class. It has been overridden to support threads.
44     """
45
46     def __init__(self):
47         self.setAttribute(QtCore.Qt.AA_X11InitThreads, True)
48         QtWidgets.QApplication.__init__(self, sys.argv)
49         self.installEventFilter(self)
50
51
52 def main():
53     # Parse arguments
54     parser = argparse.ArgumentParser()
55     parser.add_argument(
56         "--settings",
57         action="store_true",
58         dest="settings",
59         help="Open Tor Browser Launcher settings",
60     )
61     parser.add_argument("url", nargs="*", help="URL to load")
62     args = parser.parse_args()
63
64     settings = bool(args.settings)
65     url_list = args.url
66
67     # Load the version and print the banner
68     with open(os.path.join(SHARE, "version")) as buf:
69         tor_browser_launcher_version = buf.read().strip()
70
71     print(_("Tor Browser Launcher"))
72     print(_("By Micah Lee, licensed under MIT"))
73     print(_("version {0}").format(tor_browser_launcher_version))
74     print("https://github.com/micahflee/torbrowser-launcher")
75
76     common = Common(tor_browser_launcher_version)
77     app = Application()
78
79     # Open the window
80     gui = None
81
82     if settings:
83         # Settings mode
84         gui = Settings(common, app)
85     else:
86         # Launcher mode
87         gui = Launcher(common, app, url_list)
88
89     # Center the window
90     desktop = app.desktop()
91     window_size = gui.size()
92     gui.move(
93         (desktop.width() - window_size.width()) / 2,
94         (desktop.height() - window_size.height()) / 2,
95     )
96     gui.show()
97
98     # Allow ctrl-c to work
99     signal.signal(signal.SIGINT, signal.SIG_DFL)
100
101     sys.exit(app.exec_())
102
103
104 if __name__ == "__main__":
105     main()