Handle statusbar messages centrally

This commit is contained in:
Florian Bruhin 2014-04-09 20:47:24 +02:00
parent 4b0b9d884c
commit 72ab405040
4 changed files with 74 additions and 19 deletions

View File

@ -49,6 +49,7 @@ import qutebrowser
import qutebrowser.commands.utils as cmdutils import qutebrowser.commands.utils as cmdutils
import qutebrowser.config.config as config import qutebrowser.config.config as config
import qutebrowser.network.qutescheme as qutescheme import qutebrowser.network.qutescheme as qutescheme
import qutebrowser.utils.message as message
from qutebrowser.widgets.mainwindow import MainWindow from qutebrowser.widgets.mainwindow import MainWindow
from qutebrowser.widgets.crash import CrashDialog from qutebrowser.widgets.crash import CrashDialog
from qutebrowser.commands.keys import KeyParser from qutebrowser.commands.keys import KeyParser
@ -124,13 +125,12 @@ class QuteBrowser(QApplication):
self.searchparser.search_rev) self.searchparser.search_rev)
self.mainwindow.status.cmd.returnPressed.connect( self.mainwindow.status.cmd.returnPressed.connect(
self.mainwindow.tabs.setFocus) self.mainwindow.tabs.setFocus)
self.commandparser.error.connect(self.mainwindow.status.disp_error)
self.searchparser.do_search.connect( self.searchparser.do_search.connect(
self.mainwindow.tabs.cur.search) self.mainwindow.tabs.cur.search)
self.keyparser.commandparser.error.connect(
self.mainwindow.status.disp_error)
self.keyparser.keystring_updated.connect( self.keyparser.keystring_updated.connect(
self.mainwindow.status.keystring.setText) self.mainwindow.status.keystring.setText)
message.bridge.error.connect(self.mainwindow.status.disp_error)
message.bridge.info.connect(self.mainwindow.status.disp_tmp_text)
self.mainwindow.show() self.mainwindow.show()
self._python_hacks() self._python_hacks()
@ -175,6 +175,7 @@ class QuteBrowser(QApplication):
os.environ['QT_FATAL_WARNINGS'] = '1' os.environ['QT_FATAL_WARNINGS'] = '1'
self.setApplicationName("qutebrowser") self.setApplicationName("qutebrowser")
self.setApplicationVersion(qutebrowser.__version__) self.setApplicationVersion(qutebrowser.__version__)
message.init()
def _init_cmds(self): def _init_cmds(self):
"""Initialisation of the qutebrowser commands. """Initialisation of the qutebrowser commands.

View File

@ -24,6 +24,7 @@ from PyQt5.QtWebKitWidgets import QWebPage
import qutebrowser.config.config as config import qutebrowser.config.config as config
import qutebrowser.commands.utils as cmdutils import qutebrowser.commands.utils as cmdutils
import qutebrowser.utils.message as message
from qutebrowser.commands.exceptions import (ArgumentCountError, from qutebrowser.commands.exceptions import (ArgumentCountError,
NoSuchCommandError) NoSuchCommandError)
@ -108,7 +109,7 @@ class SearchParser(QObject):
self.do_search.emit(self._text, self._flags) self.do_search.emit(self._text, self._flags)
class CommandParser(QObject): class CommandParser:
"""Parse qutebrowser commandline commands. """Parse qutebrowser commandline commands.
@ -116,16 +117,9 @@ class CommandParser(QObject):
_cmd: The command which was parsed. _cmd: The command which was parsed.
_args: The arguments which were parsed. _args: The arguments which were parsed.
Signals:
error: Emitted if there was an error.
arg: The error message.
""" """
error = pyqtSignal(str)
def __init__(self, parent=None): def __init__(self, parent=None):
super().__init__(parent)
self._cmd = None self._cmd = None
self._args = [] self._args = []
@ -205,9 +199,6 @@ class CommandParser(QObject):
True if command was called (handler returnstatus is ignored!). True if command was called (handler returnstatus is ignored!).
False if command wasn't called (there was an ignored exception). False if command wasn't called (there was an ignored exception).
Emit:
error: If there was an error parsing a command.
""" """
if ';;' in text: if ';;' in text:
retvals = [] retvals = []
@ -219,14 +210,14 @@ class CommandParser(QObject):
self._check() self._check()
except ArgumentCountError: except ArgumentCountError:
if ignore_exc: if ignore_exc:
self.error.emit("{}: invalid argument count".format( message.error("{}: invalid argument count".format(
self._cmd.name)) self._cmd.name))
return False return False
else: else:
raise raise
except NoSuchCommandError as e: except NoSuchCommandError as e:
if ignore_exc: if ignore_exc:
self.error.emit("{}: no such command".format(e)) message.error("{}: no such command".format(e))
return False return False
else: else:
raise raise

View File

@ -33,6 +33,7 @@ from configparser import ConfigParser, ExtendedInterpolation
#from qutebrowser.utils.misc import read_file #from qutebrowser.utils.misc import read_file
import qutebrowser.config.configdata as configdata import qutebrowser.config.configdata as configdata
import qutebrowser.commands.utils as cmdutils import qutebrowser.commands.utils as cmdutils
import qutebrowser.utils.message as message
config = None config = None
state = None state = None
@ -166,8 +167,10 @@ class Config:
@cmdutils.register(name='get', instance='config', completion=['setting'], @cmdutils.register(name='get', instance='config', completion=['setting'],
split_args=False) split_args=False)
def get_wrapper(self, sectopt): def get_wrapper(self, secopt):
"""Wrapper for the get-command to have section/option in one arg. """Get the value from a section/option.
Wrapper for the get-command to have section/option in one arg.
Arguments: Arguments:
secopt: Section and option, delimited by a space. secopt: Section and option, delimited by a space.
@ -176,7 +179,10 @@ class Config:
The value of the section/option. The value of the section/option.
""" """
return self.get(*sectopt.split()) sect, opt = secopt.split()
val = self.get(sect, opt)
message.info("{} {} = {}".format(sect, opt, val))
def get(self, section, option, fallback=_UNSET, raw=False): def get(self, section, option, fallback=_UNSET, raw=False):
"""Get the value from a section/option. """Get the value from a section/option.

View File

@ -0,0 +1,57 @@
# Copyright 2014 Florian Bruhin (The Compiler) <mail@qutebrowser.org>
#
# 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/>.
"""Message singleton so we don't have to define unneeded signals."""
from PyQt5.QtCore import QObject, pyqtSignal
class MessageBridge(QObject):
"""Bridge for messages to be shown in the statusbar."""
error = pyqtSignal(str)
info = pyqtSignal(str)
def __init__(self, parent=None):
print("=====> initializing bridge")
super().__init__(parent)
bridge = None
def init():
"""Initialize the global MessageBridge.
This needs to be done by hand because the import time is before Qt is ready
for everything.
"""
global bridge
bridge = MessageBridge()
def error(message):
"""Display an error message in the statusbar."""
bridge.error.emit(message)
def info(message):
"""Display an info message in the statusbar."""
bridge.info.emit(message)