qutebrowser/qutebrowser/app.py

63 lines
2.1 KiB
Python
Raw Normal View History

2013-12-14 22:15:16 +01:00
import sys
2014-01-17 20:03:21 +01:00
import argparse
import logging
from PyQt5.QtWidgets import QWidget, QApplication
from qutebrowser.widgets.mainwindow import MainWindow
2014-01-17 12:01:21 +01:00
from qutebrowser.commands.keys import KeyParser
2014-01-17 10:57:27 +01:00
import qutebrowser.commands.utils as cmdutils
2013-12-14 22:15:16 +01:00
2014-01-17 20:03:21 +01:00
def parseopts():
parser = argparse.ArgumentParser("usage: %(prog)s [options]")
parser.add_argument('-l', '--log', dest='loglevel', help='Set loglevel',
default=0)
args = parser.parse_args()
return args
def initlog(args):
""" Initialisation of the log """
if (args.loglevel):
loglevel = args.loglevel
else:
loglevel = 'info'
numeric_level = getattr(logging, loglevel.upper(), None)
if not isinstance(numeric_level, int):
raise ValueError('Invalid log level: %s' % loglevel)
logging.basicConfig(
level=numeric_level,
format='%(asctime)s [%(levelname)s] [%(module)s:%(funcName)s:%(lineno)s] %(message)s',
datefmt='%Y-%m-%d %H:%M:%S')
2013-12-14 22:15:16 +01:00
def main():
2014-01-17 20:03:21 +01:00
args = parseopts()
initlog(args)
2013-12-14 22:15:16 +01:00
app = QApplication(sys.argv)
2013-12-15 22:24:47 +01:00
mw = MainWindow()
2014-01-17 10:57:27 +01:00
cp = cmdutils.CommandParser()
2014-01-17 12:00:13 +01:00
kp = KeyParser(mw)
2014-01-17 06:51:21 +01:00
kp.set_cmd_text.connect(mw.status.cmd.set_cmd)
2014-01-16 17:49:57 +01:00
mw.status.cmd.got_cmd.connect(cp.parse)
2014-01-16 21:59:50 +01:00
mw.status.cmd.got_cmd.connect(mw.setFocus)
2014-01-17 07:04:24 +01:00
cp.error.connect(mw.status.disp_error)
2014-01-17 10:57:27 +01:00
cmdutils.register_all()
cmds = cmdutils.cmd_dict
cmds['open'].signal.connect(mw.tabs.openurl)
cmds['tabopen'].signal.connect(mw.tabs.tabopen)
cmds['quit'].signal.connect(QApplication.closeAllWindows) # FIXME
cmds['tabclose'].signal.connect(mw.tabs.close_act)
cmds['tabprev'].signal.connect(mw.tabs.switch_prev)
cmds['tabnext'].signal.connect(mw.tabs.switch_next)
cmds['reload'].signal.connect(mw.tabs.reload_act)
cmds['stop'].signal.connect(mw.tabs.stop_act)
cmds['back'].signal.connect(mw.tabs.back_act)
cmds['forward'].signal.connect(mw.tabs.forward_act)
cmds['print'].signal.connect(mw.tabs.print_act)
2014-01-17 22:02:11 +01:00
cmds['scrolldown'].signal.connect(mw.tabs.scroll_down_act)
cmds['scrollup'].signal.connect(mw.tabs.scroll_up_act)
2014-01-17 12:00:13 +01:00
kp.from_cmd_dict(cmds)
2014-01-17 10:57:27 +01:00
mw.show()
2013-12-14 22:15:16 +01:00
sys.exit(app.exec_())