qutebrowser/qutebrowser/utils/message.py

81 lines
2.3 KiB
Python
Raw Normal View History

2014-04-09 20:47:24 +02:00
# 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/>.
2014-05-05 17:56:14 +02:00
"""Message singleton so we don't have to define unneeded signals."""
2014-04-09 20:47:24 +02:00
2014-05-05 22:36:08 +02:00
import logging
2014-05-09 17:01:05 +02:00
from PyQt5.QtCore import QObject, pyqtSignal, QCoreApplication
2014-04-09 20:47:24 +02:00
2014-05-05 17:56:14 +02:00
def instance():
"""Get the global messagebridge instance."""
2014-05-09 17:01:05 +02:00
return QCoreApplication.instance().messagebridge
2014-04-09 20:47:24 +02:00
def error(message, queue=False):
2014-05-16 17:21:43 +02:00
"""Display an error message in the statusbar.
Args:
message: The message to display.
queue: If set, message gets queued rather than being displayed
immediately.
2014-05-16 17:21:43 +02:00
"""
2014-05-14 18:00:40 +02:00
message = str(message)
2014-05-05 22:36:08 +02:00
logging.error(message)
instance().error.emit(message, queue)
2014-04-09 20:47:24 +02:00
def info(message, queue=False):
2014-05-16 17:21:43 +02:00
"""Display a temporary info message in the statusbar.
Args:
message: The message to display.
queue: If set, message gets queued rather than being displayed
immediately.
2014-05-16 17:21:43 +02:00
"""
2014-05-14 18:00:40 +02:00
message = str(message)
2014-05-05 22:36:08 +02:00
logging.info(message)
instance().info.emit(message, queue)
2014-04-17 17:44:27 +02:00
def text(message):
"""Display a persistent message in the statusbar."""
2014-05-14 18:00:40 +02:00
message = str(message)
2014-05-05 22:36:08 +02:00
logging.debug(message)
2014-05-05 17:56:14 +02:00
instance().text.emit(message)
def clear():
"""Clear a persistent message in the statusbar."""
2014-05-05 17:56:14 +02:00
instance().text.emit('')
2014-04-24 22:49:06 +02:00
def set_cmd_text(txt):
2014-04-24 21:28:24 +02:00
"""Set the statusbar command line to a preset text."""
2014-05-05 17:56:14 +02:00
instance().set_cmd_text.emit(txt)
2014-04-24 21:28:24 +02:00
2014-04-17 17:44:27 +02:00
class MessageBridge(QObject):
"""Bridge for messages to be shown in the statusbar."""
2014-05-16 17:21:43 +02:00
error = pyqtSignal(str, bool)
info = pyqtSignal(str, bool)
text = pyqtSignal(str)
2014-04-24 21:28:24 +02:00
set_cmd_text = pyqtSignal(str)