Start implementing config storage
This commit is contained in:
parent
da7a95d6ec
commit
7ed257467b
@ -5,7 +5,9 @@ from PyQt5.QtWidgets import QWidget, QApplication
|
||||
from PyQt5.QtCore import QUrl
|
||||
from qutebrowser.widgets.mainwindow import MainWindow
|
||||
from qutebrowser.commands.keys import KeyParser
|
||||
from qutebrowser.utils.config import Config
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
from qutebrowser.utils.appdirs import AppDirs
|
||||
|
||||
class QuteBrowser(QApplication):
|
||||
def __init__(self):
|
||||
@ -13,6 +15,9 @@ class QuteBrowser(QApplication):
|
||||
args = self.parseopts()
|
||||
self.initlog()
|
||||
|
||||
self.dirs = AppDirs('qutebrowser')
|
||||
self.config = Config(self.dirs.user_data_dir)
|
||||
|
||||
self.mainwindow = MainWindow()
|
||||
self.commandparser = cmdutils.CommandParser()
|
||||
self.keyparser = KeyParser(self.mainwindow)
|
||||
@ -54,7 +59,7 @@ class QuteBrowser(QApplication):
|
||||
cmds = cmdutils.cmd_dict
|
||||
for cmd in cmds.values():
|
||||
cmd.signal.connect(self.cmd_handler)
|
||||
self.keyparser.from_cmd_dict(cmdutils.cmd_dict)
|
||||
self.keyparser.from_config_sect(self.config['keybind'])
|
||||
|
||||
def cmd_handler(self, tpl):
|
||||
(count, argv) = tpl
|
||||
@ -64,7 +69,7 @@ class QuteBrowser(QApplication):
|
||||
handlers = {
|
||||
'open': self.mainwindow.tabs.openurl,
|
||||
'tabopen': self.mainwindow.tabs.tabopen,
|
||||
'quit': QApplication.closeAllWindows, # FIXME
|
||||
'quit': self.exit,
|
||||
'tabclose': self.mainwindow.tabs.close_act,
|
||||
'tabprev': self.mainwindow.tabs.switch_prev,
|
||||
'tabnext': self.mainwindow.tabs.switch_next,
|
||||
@ -103,3 +108,7 @@ class QuteBrowser(QApplication):
|
||||
tab.setUrl(QUrl('about:pyeval'))
|
||||
tab.setContent(out.encode('UTF-8'), 'text/plain')
|
||||
|
||||
def exit(self, status=0):
|
||||
self.config.save()
|
||||
QApplication.closeAllWindows()
|
||||
# FIXME do this right
|
||||
|
@ -3,78 +3,63 @@ from qutebrowser.commands.utils import Command
|
||||
|
||||
class Open(Command):
|
||||
nargs = 1
|
||||
key = 'o'
|
||||
split_args = False
|
||||
|
||||
class TabOpen(Command):
|
||||
nargs = 1
|
||||
key = 'O'
|
||||
split_args = False
|
||||
|
||||
class TabClose(Command):
|
||||
nargs = 0
|
||||
key = 'd'
|
||||
|
||||
class TabNext(Command):
|
||||
nargs = 0
|
||||
key = 'J'
|
||||
|
||||
class TabPrev(Command):
|
||||
nargs = 0
|
||||
key = 'K'
|
||||
|
||||
class Quit(Command):
|
||||
nargs = 0
|
||||
|
||||
class Reload(Command):
|
||||
nargs = 0
|
||||
key = 'r'
|
||||
|
||||
class Stop(Command):
|
||||
nargs = 0
|
||||
|
||||
class Back(Command):
|
||||
nargs = 0
|
||||
key = 'H'
|
||||
|
||||
class Forward(Command):
|
||||
nargs = 0
|
||||
key = 'L'
|
||||
|
||||
class Print(Command):
|
||||
nargs = 0
|
||||
|
||||
class ScrollLeft(Command):
|
||||
nargs = 0
|
||||
key = 'h'
|
||||
count = True
|
||||
|
||||
class ScrollDown(Command):
|
||||
nargs = 0
|
||||
key = 'j'
|
||||
count = True
|
||||
|
||||
class ScrollUp(Command):
|
||||
nargs = 0
|
||||
key = 'k'
|
||||
count = True
|
||||
|
||||
class ScrollRight(Command):
|
||||
nargs = 0
|
||||
key = 'l'
|
||||
count = True
|
||||
|
||||
class Undo(Command):
|
||||
nargs = 0
|
||||
key = 'u'
|
||||
|
||||
class ScrollStart(Command):
|
||||
nargs = 0
|
||||
key = 'gg'
|
||||
|
||||
class ScrollEnd(Command):
|
||||
nargs = 0
|
||||
key = 'G'
|
||||
|
||||
class PyEval(Command):
|
||||
nargs = 1
|
||||
|
@ -1,6 +1,7 @@
|
||||
from PyQt5.QtCore import QObject, Qt, pyqtSignal
|
||||
from PyQt5.QtWidgets import QShortcut
|
||||
from PyQt5.QtGui import QKeySequence
|
||||
import qutebrowser.commands.utils as cmdutils
|
||||
import logging
|
||||
import re
|
||||
|
||||
@ -10,11 +11,10 @@ class KeyParser(QObject):
|
||||
keystring_updated = pyqtSignal(str)
|
||||
key_to_cmd = {}
|
||||
|
||||
def from_cmd_dict(self, d):
|
||||
for cmd in d.values():
|
||||
if cmd.key is not None:
|
||||
logging.debug('registered: {} -> {}'.format(cmd.name, cmd.key))
|
||||
self.key_to_cmd[cmd.key] = cmd
|
||||
def from_config_sect(self, sect):
|
||||
for (key, cmd) in sect.items():
|
||||
logging.debug('registered: {} -> {}'.format(key, cmd))
|
||||
self.key_to_cmd[key] = cmdutils.cmd_dict[cmd]
|
||||
|
||||
def handle(self, e):
|
||||
self._handle(e)
|
||||
|
@ -50,7 +50,6 @@ class CommandParser(QObject):
|
||||
class Command(QObject):
|
||||
nargs = 0
|
||||
name = None
|
||||
key = None
|
||||
signal = None
|
||||
count = False
|
||||
bind = True
|
||||
|
Loading…
Reference in New Issue
Block a user