qutebrowser/qutebrowser/qutebrowser.py

126 lines
5.6 KiB
Python
Raw Normal View History

# vim: ft=python fileencoding=utf-8 sts=4 sw=4 et:
2014-06-04 14:11:55 +02:00
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
2014-06-04 14:11:55 +02:00
# This file is part of qutebrowser.
#
# qutebrowser is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# qutebrowser is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with qutebrowser. If not, see <http://www.gnu.org/licenses/>.
"""Early initialization and main entry point."""
2014-06-04 14:11:55 +02:00
import sys
2014-06-04 14:11:55 +02:00
2014-07-18 07:48:33 +02:00
import qutebrowser
try:
from qutebrowser.misc.checkpyver import check_python_version
except ImportError:
try:
# python2
from .misc.checkpyver import check_python_version
except (SystemError, ValueError):
# Import without module - SystemError on Python3, ValueError (?!?) on
# Python2
sys.stderr.write("Please don't run this script directly, do something "
"like python3 -m qutebrowser instead.\n")
sys.stderr.flush()
sys.exit(100)
2014-06-04 14:11:55 +02:00
check_python_version()
2014-08-26 19:10:14 +02:00
import argparse
from qutebrowser.misc import earlyinit
2014-06-04 14:11:55 +02:00
2014-07-18 07:48:33 +02:00
def get_argparser():
"""Get the argparse parser."""
2014-08-26 19:10:14 +02:00
parser = argparse.ArgumentParser("usage: qutebrowser",
description=qutebrowser.__description__)
2014-06-06 15:52:37 +02:00
parser.add_argument('-c', '--confdir', help="Set config directory (empty "
"for no config storage)")
parser.add_argument('-V', '--version', help="Show version and quit.",
action='store_true')
debug = parser.add_argument_group('debug arguments')
debug.add_argument('-l', '--loglevel', dest='loglevel',
2014-06-06 16:40:49 +02:00
help="Set loglevel", default='info')
2014-06-06 15:52:37 +02:00
debug.add_argument('--logfilter',
2014-06-06 16:40:49 +02:00
help="Comma-separated list of things to be logged "
"to the debug log on stdout.")
debug.add_argument('--loglines',
help="How many lines of the debug log to keep in RAM "
"(-1: unlimited).",
default=1000, type=int)
2014-06-06 15:52:37 +02:00
debug.add_argument('--debug', help="Turn on debugging options.",
2014-06-06 16:40:49 +02:00
action='store_true')
2014-06-06 15:52:37 +02:00
debug.add_argument('--nocolor', help="Turn off colored logging.",
2014-06-06 16:40:49 +02:00
action='store_false', dest='color')
2014-06-06 15:52:37 +02:00
debug.add_argument('--harfbuzz', choices=['old', 'new', 'system', 'auto'],
2014-06-06 16:40:49 +02:00
default='auto', help="HarfBuzz engine version to use. "
"Default: auto.")
2014-08-02 00:47:04 +02:00
debug.add_argument('--nowindow', action='store_true', help="Don't show "
"the main window.")
debug.add_argument('--debug-exit', help="Turn on debugging of late exit.",
action='store_true')
2014-12-06 00:39:33 +01:00
debug.add_argument('--no-crash-dialog', action='store_true', help="Don't "
"show a crash dialog.")
2014-06-20 06:53:41 +02:00
# For the Qt args, we use store_const with const=True rather than
# store_true because we want the default to be None, to make
# utils.qt:get_args easier.
2014-06-06 16:32:57 +02:00
debug.add_argument('--qt-style', help="Set the Qt GUI style to use.",
metavar='STYLE')
debug.add_argument('--qt-stylesheet', help="Override the Qt application "
"stylesheet.", metavar='STYLESHEET')
2014-06-16 14:42:01 +02:00
debug.add_argument('--qt-widgetcount', help="Print debug message at the "
2014-06-06 16:32:57 +02:00
"end about number of widgets left undestroyed and "
"maximum number of widgets existed at the same time.",
2014-06-06 16:40:49 +02:00
action='store_const', const=True)
2014-06-06 16:32:57 +02:00
debug.add_argument('--qt-reverse', help="Set the application's layout "
2014-06-06 16:40:49 +02:00
"direction to right-to-left.", action='store_const',
const=True)
2014-06-06 16:32:57 +02:00
debug.add_argument('--qt-qmljsdebugger', help="Activate the QML/JS "
"debugger with a specified port. 'block' is optional "
"and will make the application wait until a debugger "
"connects to it.", metavar='port:PORT[,block]')
2014-06-04 14:11:55 +02:00
parser.add_argument('command', nargs='*', help="Commands to execute on "
"startup.", metavar=':command')
# URLs will actually be in command
parser.add_argument('url', nargs='*', help="URLs to open on startup "
"(empty as a window separator).")
2014-07-18 07:48:33 +02:00
return parser
2014-06-04 14:11:55 +02:00
def main():
"""Main entry point for qutebrowser."""
2014-07-18 07:48:33 +02:00
parser = get_argparser()
args = parser.parse_args()
earlyinit.earlyinit(args)
# We do this imports late as earlyinit needs to be run first (because of
# the harfbuzz fix and version checking).
2014-08-26 19:10:14 +02:00
from qutebrowser import app
import PyQt5.QtWidgets as QtWidgets
2014-08-26 19:10:14 +02:00
app = app.Application(args)
def qt_mainloop():
"""Simple wrapper to get a nicer stack trace for segfaults."""
return app.exec_() # pylint: disable=maybe-no-member
# We set qApp explicitely here to reduce the risk of segfaults while
# quitting.
# See https://bugs.launchpad.net/ubuntu/+source/python-qt4/+bug/561303/comments/7
# While this is a workaround for PyQt4 which should be fixed in PyQt, it
# seems this still reduces segfaults.
# FIXME: We should do another attempt at contacting upstream about this.
QtWidgets.qApp = app
ret = qt_mainloop()
QtWidgets.qApp = None
return ret