]> git.lizzy.rs Git - torbrowser-launcher.git/blob - torbrowser_launcher/__init__.py
0f99d05f570c3993d59f68174ffdd97d797ed450
[torbrowser-launcher.git] / torbrowser_launcher / __init__.py
1 """
2 Tor Browser Launcher
3 https://github.com/micahflee/torbrowser-launcher/
4
5 Copyright (c) 2013-2017 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
33 from PyQt5 import QtCore, QtWidgets
34
35 from .common import Common, SHARE
36 from .settings import Settings
37 from .launcher import Launcher
38
39
40 class Application(QtWidgets.QApplication):
41     """
42     Qt's QApplication class. It has been overridden to support threads.
43     """
44     def __init__(self):
45         self.setAttribute(QtCore.Qt.AA_X11InitThreads, True)
46         QtWidgets.QApplication.__init__(self, sys.argv)
47         self.installEventFilter(self)
48
49
50 def main():
51     # Parse arguments
52     parser = argparse.ArgumentParser()
53     parser.add_argument('--settings', action='store_true', dest='settings', help='Open Tor Browser Launcher settings')
54     parser.add_argument('url', nargs='*', help='URL to load')
55     args = parser.parse_args()
56
57     settings = bool(args.settings)
58     url_list = args.url
59
60     # Load the version and print the banner
61     with open(os.path.join(SHARE, 'version')) as buf:
62         tor_browser_launcher_version = buf.read().strip()
63
64     print(_('Tor Browser Launcher'))
65     print(_('By Micah Lee, licensed under MIT'))
66     print(_('version {0}').format(tor_browser_launcher_version))
67     print('https://github.com/micahflee/torbrowser-launcher')
68
69     common = Common(tor_browser_launcher_version)
70     app = Application()
71
72     if settings:
73         # Settings mode
74         gui = Settings(common, app)
75
76     else:
77         # Launcher mode
78         gui = Launcher(common, app, url_list)
79
80     sys.exit(app.exec_())
81
82 if __name__ == "__main__":
83     main()