Refactor app.py
This commit is contained in:
parent
0dd204b182
commit
9f9f5c41f7
@ -1,4 +1,6 @@
|
||||
from qutebrowser import app
|
||||
from qutebrowser.app import QuteBrowser
|
||||
import sys
|
||||
|
||||
if __name__ == '__main__':
|
||||
app.main()
|
||||
app = QuteBrowser()
|
||||
sys.exit(app.exec_())
|
||||
|
@ -6,60 +6,63 @@ from qutebrowser.widgets.mainwindow import MainWindow
|
||||
from qutebrowser.commands.keys import KeyParser
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
|
||||
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
|
||||
class QuteBrowser(QApplication):
|
||||
def __init__(self):
|
||||
super().__init__(sys.argv)
|
||||
args = self.parseopts()
|
||||
self.initlog()
|
||||
|
||||
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')
|
||||
self.mainwindow = MainWindow()
|
||||
self.commandparser = cmdutils.CommandParser()
|
||||
self.keyparser = KeyParser(self.mainwindow)
|
||||
|
||||
def main():
|
||||
args = parseopts()
|
||||
initlog(args)
|
||||
self.keyparser.set_cmd_text.connect(self.mainwindow.status.cmd.set_cmd)
|
||||
self.mainwindow.status.cmd.got_cmd.connect(self.commandparser.parse)
|
||||
self.mainwindow.status.cmd.got_cmd.connect(self.mainwindow.setFocus)
|
||||
self.commandparser.error.connect(self.mainwindow.status.disp_error)
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
self.init_cmds()
|
||||
self.mainwindow.show()
|
||||
|
||||
mw = MainWindow()
|
||||
cp = cmdutils.CommandParser()
|
||||
kp = KeyParser(mw)
|
||||
kp.set_cmd_text.connect(mw.status.cmd.set_cmd)
|
||||
mw.status.cmd.got_cmd.connect(cp.parse)
|
||||
mw.status.cmd.got_cmd.connect(mw.setFocus)
|
||||
cp.error.connect(mw.status.disp_error)
|
||||
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()
|
||||
|
||||
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)
|
||||
cmds['scrolldown'].signal.connect(mw.tabs.scroll_down_act)
|
||||
cmds['scrollup'].signal.connect(mw.tabs.scroll_up_act)
|
||||
cmds['scrollleft'].signal.connect(mw.tabs.scroll_left_act)
|
||||
cmds['scrollright'].signal.connect(mw.tabs.scroll_right_act)
|
||||
cmds['undo'].signal.connect(mw.tabs.undo_close)
|
||||
kp.from_cmd_dict(cmds)
|
||||
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')
|
||||
|
||||
mw.show()
|
||||
sys.exit(app.exec_())
|
||||
def init_cmds(self):
|
||||
cmdutils.register_all()
|
||||
cmds = cmdutils.cmd_dict
|
||||
cmds['open'].signal.connect(self.mainwindow.tabs.openurl)
|
||||
cmds['tabopen'].signal.connect(self.mainwindow.tabs.tabopen)
|
||||
cmds['quit'].signal.connect(QApplication.closeAllWindows) # FIXME
|
||||
cmds['tabclose'].signal.connect(self.mainwindow.tabs.close_act)
|
||||
cmds['tabprev'].signal.connect(self.mainwindow.tabs.switch_prev)
|
||||
cmds['tabnext'].signal.connect(self.mainwindow.tabs.switch_next)
|
||||
cmds['reload'].signal.connect(self.mainwindow.tabs.reload_act)
|
||||
cmds['stop'].signal.connect(self.mainwindow.tabs.stop_act)
|
||||
cmds['back'].signal.connect(self.mainwindow.tabs.back_act)
|
||||
cmds['forward'].signal.connect(self.mainwindow.tabs.forward_act)
|
||||
cmds['print'].signal.connect(self.mainwindow.tabs.print_act)
|
||||
cmds['scrolldown'].signal.connect(self.mainwindow.tabs.scroll_down_act)
|
||||
cmds['scrollup'].signal.connect(self.mainwindow.tabs.scroll_up_act)
|
||||
cmds['scrollleft'].signal.connect(self.mainwindow.tabs.scroll_left_act)
|
||||
cmds['scrollright'].signal.connect(
|
||||
self.mainwindow.tabs.scroll_right_act)
|
||||
cmds['undo'].signal.connect(self.mainwindow.tabs.undo_close)
|
||||
self.keyparser.from_cmd_dict(cmdutils.cmd_dict)
|
||||
|
Loading…
Reference in New Issue
Block a user