2013-12-14 22:15:16 +01:00
|
|
|
import sys
|
2014-01-17 20:03:21 +01:00
|
|
|
import argparse
|
|
|
|
import logging
|
2013-12-15 20:33:43 +01:00
|
|
|
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-19 18:20:57 +01:00
|
|
|
class QuteBrowser(QApplication):
|
|
|
|
def __init__(self):
|
|
|
|
super().__init__(sys.argv)
|
|
|
|
args = self.parseopts()
|
|
|
|
self.initlog()
|
2014-01-17 20:03:21 +01:00
|
|
|
|
2014-01-19 18:20:57 +01:00
|
|
|
self.mainwindow = MainWindow()
|
|
|
|
self.commandparser = cmdutils.CommandParser()
|
|
|
|
self.keyparser = KeyParser(self.mainwindow)
|
2014-01-17 20:03:21 +01:00
|
|
|
|
2014-01-19 19:41:34 +01:00
|
|
|
self.mainwindow.tabs.keypress.connect(self.keyparser.handle)
|
2014-01-19 18:20:57 +01:00
|
|
|
self.keyparser.set_cmd_text.connect(self.mainwindow.status.cmd.set_cmd)
|
|
|
|
self.mainwindow.status.cmd.got_cmd.connect(self.commandparser.parse)
|
2014-01-19 19:41:34 +01:00
|
|
|
self.mainwindow.status.cmd.got_cmd.connect(self.mainwindow.tabs.setFocus)
|
2014-01-19 18:20:57 +01:00
|
|
|
self.commandparser.error.connect(self.mainwindow.status.disp_error)
|
2014-01-17 20:03:21 +01:00
|
|
|
|
2014-01-19 18:20:57 +01:00
|
|
|
self.init_cmds()
|
|
|
|
self.mainwindow.show()
|
2013-12-15 20:33:43 +01:00
|
|
|
|
2014-01-19 18:20:57 +01:00
|
|
|
def parseopts(self):
|
|
|
|
parser = argparse.ArgumentParser("usage: %(prog)s [options]")
|
|
|
|
parser.add_argument('-l', '--log', dest='loglevel',
|
|
|
|
help='Set loglevel', default=0)
|
|
|
|
self.args = parser.parse_args()
|
2013-12-15 20:33:43 +01:00
|
|
|
|
2014-01-19 18:20:57 +01:00
|
|
|
def initlog(self):
|
|
|
|
""" Initialisation of the log """
|
|
|
|
if self.args.loglevel:
|
|
|
|
loglevel = self.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')
|
2014-01-17 10:57:27 +01:00
|
|
|
|
2014-01-19 18:20:57 +01:00
|
|
|
def init_cmds(self):
|
|
|
|
cmdutils.register_all()
|
|
|
|
cmds = cmdutils.cmd_dict
|
2014-01-19 22:55:00 +01:00
|
|
|
for cmd in cmds.values():
|
|
|
|
cmd.signal.connect(self.cmd_handler)
|
2014-01-19 18:20:57 +01:00
|
|
|
self.keyparser.from_cmd_dict(cmdutils.cmd_dict)
|
2014-01-19 22:55:00 +01:00
|
|
|
|
|
|
|
def cmd_handler(self, tpl):
|
|
|
|
(count, argv) = tpl
|
|
|
|
cmd = argv[0]
|
|
|
|
args = argv[1:]
|
|
|
|
|
2014-01-19 23:03:06 +01:00
|
|
|
handlers = {
|
|
|
|
'open': self.mainwindow.tabs.openurl,
|
|
|
|
'tabopen': self.mainwindow.tabs.tabopen,
|
|
|
|
'quit': QApplication.closeAllWindows, # FIXME
|
|
|
|
'tabclose': self.mainwindow.tabs.close_act,
|
|
|
|
'tabprev': self.mainwindow.tabs.switch_prev,
|
|
|
|
'tabnext': self.mainwindow.tabs.switch_next,
|
|
|
|
'reload': self.mainwindow.tabs.reload_act,
|
|
|
|
'stop': self.mainwindow.tabs.stop_act,
|
|
|
|
'back': self.mainwindow.tabs.back_act,
|
|
|
|
'forward': self.mainwindow.tabs.forward_act,
|
|
|
|
'print': self.mainwindow.tabs.print_act,
|
|
|
|
'scrolldown': self.mainwindow.tabs.scroll_down_act,
|
|
|
|
'scrollup': self.mainwindow.tabs.scroll_up_act,
|
|
|
|
'scrollleft': self.mainwindow.tabs.scroll_left_act,
|
|
|
|
'scrollright': self.mainwindow.tabs.scroll_right_act,
|
|
|
|
'scrollstart': self.mainwindow.tabs.scroll_start_act,
|
|
|
|
'scrollend': self.mainwindow.tabs.scroll_end_act,
|
|
|
|
'undo': self.mainwindow.tabs.undo_close,
|
|
|
|
}
|
|
|
|
|
|
|
|
handler = handlers[cmd]
|
|
|
|
sender = self.sender()
|
|
|
|
|
|
|
|
if sender.count:
|
|
|
|
handler(*args, count=count)
|
|
|
|
else:
|
|
|
|
handler(*args)
|