]> git.lizzy.rs Git - torbrowser-launcher.git/blobdiff - torbrowser_launcher/__init__.py
Fix pt_BR po file
[torbrowser-launcher.git] / torbrowser_launcher / __init__.py
index ccd4e33df33ad6cfb7f6550ce91eaf1226b7e4a0..bff3e8ea7f8974afc978cec50329743b2d6ee42f 100644 (file)
@@ -2,7 +2,7 @@
 Tor Browser Launcher
 https://github.com/micahflee/torbrowser-launcher/
 
-Copyright (c) 2013-2017 Micah Lee <micah@micahflee.com>
+Copyright (c) 2013-2021 Micah Lee <micah@micahflee.com>
 
 Permission is hereby granted, free of charge, to any person
 obtaining a copy of this software and associated documentation
@@ -29,6 +29,7 @@ OTHER DEALINGS IN THE SOFTWARE.
 import os
 import sys
 import argparse
+import signal
 
 from PyQt5 import QtCore, QtWidgets
 
@@ -41,6 +42,7 @@ class Application(QtWidgets.QApplication):
     """
     Qt's QApplication class. It has been overridden to support threads.
     """
+
     def __init__(self):
         self.setAttribute(QtCore.Qt.AA_X11InitThreads, True)
         QtWidgets.QApplication.__init__(self, sys.argv)
@@ -50,34 +52,54 @@ class Application(QtWidgets.QApplication):
 def main():
     # Parse arguments
     parser = argparse.ArgumentParser()
-    parser.add_argument('--settings', action='store_true', dest='settings', help='Open Tor Browser Launcher settings')
-    parser.add_argument('url', nargs='*', help='URL to load')
+    parser.add_argument(
+        "--settings",
+        action="store_true",
+        dest="settings",
+        help="Open Tor Browser Launcher settings",
+    )
+    parser.add_argument("url", nargs="*", help="URL to load")
     args = parser.parse_args()
 
     settings = bool(args.settings)
     url_list = args.url
 
     # Load the version and print the banner
-    with open(os.path.join(SHARE, 'version')) as buf:
+    with open(os.path.join(SHARE, "version")) as buf:
         tor_browser_launcher_version = buf.read().strip()
 
-    print(_('Tor Browser Launcher'))
-    print(_('By Micah Lee, licensed under MIT'))
-    print(_('version {0}').format(tor_browser_launcher_version))
-    print('https://github.com/micahflee/torbrowser-launcher')
+    print(_("Tor Browser Launcher"))
+    print(_("By Micah Lee, licensed under MIT"))
+    print(_("version {0}").format(tor_browser_launcher_version))
+    print("https://github.com/micahflee/torbrowser-launcher")
 
     common = Common(tor_browser_launcher_version)
     app = Application()
 
+    # Open the window
+    gui = None
+
     if settings:
         # Settings mode
-        gui = Settings(common)
-
+        gui = Settings(common, app)
     else:
         # Launcher mode
-        gui = Launcher(common, url_list)
+        gui = Launcher(common, app, url_list)
+
+    # Center the window
+    desktop = app.desktop()
+    window_size = gui.size()
+    gui.move(
+        (desktop.width() - window_size.width()) / 2,
+        (desktop.height() - window_size.height()) / 2,
+    )
+    gui.show()
+
+    # Allow ctrl-c to work
+    signal.signal(signal.SIGINT, signal.SIG_DFL)
 
     sys.exit(app.exec_())
 
+
 if __name__ == "__main__":
     main()