Add set_cmd_text to MessageBridge
This commit is contained in:
parent
0c15517352
commit
9320c813f7
@ -259,10 +259,7 @@ class QuteBrowser(QApplication):
|
|||||||
# status bar
|
# status bar
|
||||||
modes.manager.entered.connect(status.on_mode_entered)
|
modes.manager.entered.connect(status.on_mode_entered)
|
||||||
modes.manager.left.connect(status.on_mode_left)
|
modes.manager.left.connect(status.on_mode_left)
|
||||||
# FIXME what to do here?
|
|
||||||
modes.manager.key_pressed.connect(status.on_key_pressed)
|
modes.manager.key_pressed.connect(status.on_key_pressed)
|
||||||
for obj in [kp["normal"], tabs]:
|
|
||||||
obj.set_cmd_text.connect(cmd.set_cmd_text)
|
|
||||||
|
|
||||||
# commands
|
# commands
|
||||||
cmd.got_cmd.connect(self.commandparser.run)
|
cmd.got_cmd.connect(self.commandparser.run)
|
||||||
@ -282,6 +279,7 @@ class QuteBrowser(QApplication):
|
|||||||
message.bridge.error.connect(status.disp_error)
|
message.bridge.error.connect(status.disp_error)
|
||||||
message.bridge.info.connect(status.txt.set_temptext)
|
message.bridge.info.connect(status.txt.set_temptext)
|
||||||
message.bridge.text.connect(status.txt.set_normaltext)
|
message.bridge.text.connect(status.txt.set_normaltext)
|
||||||
|
message.bridge.set_cmd_text.connect(cmd.set_cmd_text)
|
||||||
|
|
||||||
# config
|
# config
|
||||||
self.config.style_changed.connect(style.invalidate_caches)
|
self.config.style_changed.connect(style.invalidate_caches)
|
||||||
|
@ -62,7 +62,6 @@ class HintManager(QObject):
|
|||||||
arg 0: URL to open as a string.
|
arg 0: URL to open as a string.
|
||||||
arg 1: true if it should be opened in a new tab, else false.
|
arg 1: true if it should be opened in a new tab, else false.
|
||||||
set_open_target: Set a new target to open the links in.
|
set_open_target: Set a new target to open the links in.
|
||||||
set_cmd_text: Emitted when the commandline text should be set.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
HINT_CSS = """
|
HINT_CSS = """
|
||||||
@ -81,7 +80,6 @@ class HintManager(QObject):
|
|||||||
hint_strings_updated = pyqtSignal(list)
|
hint_strings_updated = pyqtSignal(list)
|
||||||
mouse_event = pyqtSignal('QMouseEvent')
|
mouse_event = pyqtSignal('QMouseEvent')
|
||||||
set_open_target = pyqtSignal(str)
|
set_open_target = pyqtSignal(str)
|
||||||
set_cmd_text = pyqtSignal(str)
|
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
"""Constructor.
|
"""Constructor.
|
||||||
@ -244,19 +242,6 @@ class HintManager(QObject):
|
|||||||
message.info('URL yanked to {}'.format('primary selection' if sel
|
message.info('URL yanked to {}'.format('primary selection' if sel
|
||||||
else 'clipboard'))
|
else 'clipboard'))
|
||||||
|
|
||||||
def _set_cmd_text(self, link, command):
|
|
||||||
"""Fill the command line with an element link.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
link: The URL to open.
|
|
||||||
command: The command to use.
|
|
||||||
|
|
||||||
Emit:
|
|
||||||
set_cmd_text: Always emitted.
|
|
||||||
"""
|
|
||||||
self.set_cmd_text.emit(':{} {}'.format(command,
|
|
||||||
urlutils.urlstring(link)))
|
|
||||||
|
|
||||||
def _resolve_link(self, elem):
|
def _resolve_link(self, elem):
|
||||||
"""Resolve a link and check if we want to keep it.
|
"""Resolve a link and check if we want to keep it.
|
||||||
|
|
||||||
@ -368,7 +353,8 @@ class HintManager(QObject):
|
|||||||
'cmd_tab': 'tabopen',
|
'cmd_tab': 'tabopen',
|
||||||
'cmd_bgtab': 'backtabopen',
|
'cmd_bgtab': 'backtabopen',
|
||||||
}
|
}
|
||||||
self._set_cmd_text(link, commands[self._target])
|
message.set_cmd_text(':{} {}'.format(commands[self._target],
|
||||||
|
urlutils.urlstring(link)))
|
||||||
if self._target != 'rapid':
|
if self._target != 'rapid':
|
||||||
self.stop()
|
self.stop()
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import logging
|
|||||||
|
|
||||||
from PyQt5.QtCore import pyqtSignal
|
from PyQt5.QtCore import pyqtSignal
|
||||||
|
|
||||||
|
import qutebrowser.utils.message as message
|
||||||
from qutebrowser.keyinput.keyparser import KeyChainParser
|
from qutebrowser.keyinput.keyparser import KeyChainParser
|
||||||
from qutebrowser.commands.parsers import (CommandParser, ArgumentCountError,
|
from qutebrowser.commands.parsers import (CommandParser, ArgumentCountError,
|
||||||
NoSuchCommandError)
|
NoSuchCommandError)
|
||||||
@ -41,13 +42,8 @@ class CommandKeyParser(KeyChainParser):
|
|||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
commandparser: Commandparser instance.
|
commandparser: Commandparser instance.
|
||||||
|
|
||||||
Signals:
|
|
||||||
set_cmd_text: Emitted when the statusbar should set a partial command.
|
|
||||||
arg: Text to set.
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
set_cmd_text = pyqtSignal(str)
|
|
||||||
supports_count = True
|
supports_count = True
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
@ -62,10 +58,6 @@ class CommandKeyParser(KeyChainParser):
|
|||||||
cmdstr: The command string.
|
cmdstr: The command string.
|
||||||
count: Optional command count.
|
count: Optional command count.
|
||||||
ignore_exc: Ignore exceptions.
|
ignore_exc: Ignore exceptions.
|
||||||
|
|
||||||
Emit:
|
|
||||||
set_cmd_text: If a partial command should be printed to the
|
|
||||||
statusbar.
|
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
self.commandparser.run(cmdstr, count=count, ignore_exc=ignore_exc)
|
self.commandparser.run(cmdstr, count=count, ignore_exc=ignore_exc)
|
||||||
@ -74,7 +66,7 @@ class CommandKeyParser(KeyChainParser):
|
|||||||
except ArgumentCountError:
|
except ArgumentCountError:
|
||||||
logging.debug('Filling statusbar with partial command {}'.format(
|
logging.debug('Filling statusbar with partial command {}'.format(
|
||||||
cmdstr))
|
cmdstr))
|
||||||
self.set_cmd_text.emit(':{} '.format(cmdstr))
|
message.set_cmd_text(':{} '.format(cmdstr))
|
||||||
|
|
||||||
def _handle_single_key(self, e):
|
def _handle_single_key(self, e):
|
||||||
"""Override _handle_single_key to abort if the key is a startchar.
|
"""Override _handle_single_key to abort if the key is a startchar.
|
||||||
@ -82,15 +74,12 @@ class CommandKeyParser(KeyChainParser):
|
|||||||
Args:
|
Args:
|
||||||
e: the KeyPressEvent from Qt.
|
e: the KeyPressEvent from Qt.
|
||||||
|
|
||||||
Emit:
|
|
||||||
set_cmd_text: If the keystring should be shown in the statusbar.
|
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
True if event has been handled, False otherwise.
|
True if event has been handled, False otherwise.
|
||||||
"""
|
"""
|
||||||
txt = e.text().strip()
|
txt = e.text().strip()
|
||||||
if not self._keystring and any(txt == c for c in STARTCHARS):
|
if not self._keystring and any(txt == c for c in STARTCHARS):
|
||||||
self.set_cmd_text.emit(txt)
|
message.set_cmd_text(txt)
|
||||||
return True
|
return True
|
||||||
return super()._handle_single_key(e)
|
return super()._handle_single_key(e)
|
||||||
|
|
||||||
|
@ -57,6 +57,11 @@ def clear():
|
|||||||
bridge.text.emit('')
|
bridge.text.emit('')
|
||||||
|
|
||||||
|
|
||||||
|
def set_cmd_text(text):
|
||||||
|
"""Set the statusbar command line to a preset text."""
|
||||||
|
bridge.set_cmd_text.emit(text)
|
||||||
|
|
||||||
|
|
||||||
class MessageBridge(QObject):
|
class MessageBridge(QObject):
|
||||||
|
|
||||||
"""Bridge for messages to be shown in the statusbar."""
|
"""Bridge for messages to be shown in the statusbar."""
|
||||||
@ -64,3 +69,4 @@ class MessageBridge(QObject):
|
|||||||
error = pyqtSignal(str)
|
error = pyqtSignal(str)
|
||||||
info = pyqtSignal(str)
|
info = pyqtSignal(str)
|
||||||
text = pyqtSignal(str)
|
text = pyqtSignal(str)
|
||||||
|
set_cmd_text = pyqtSignal(str)
|
||||||
|
@ -84,7 +84,6 @@ class TabbedBrowser(TabWidget):
|
|||||||
cur_link_hovered = pyqtSignal(str, str, str)
|
cur_link_hovered = pyqtSignal(str, str, str)
|
||||||
cur_scroll_perc_changed = pyqtSignal(int, int)
|
cur_scroll_perc_changed = pyqtSignal(int, int)
|
||||||
hint_strings_updated = pyqtSignal(list)
|
hint_strings_updated = pyqtSignal(list)
|
||||||
set_cmd_text = pyqtSignal(str)
|
|
||||||
shutdown_complete = pyqtSignal()
|
shutdown_complete = pyqtSignal()
|
||||||
quit = pyqtSignal()
|
quit = pyqtSignal()
|
||||||
resized = pyqtSignal('QRect')
|
resized = pyqtSignal('QRect')
|
||||||
@ -137,7 +136,6 @@ class TabbedBrowser(TabWidget):
|
|||||||
tab.urlChanged.connect(self._filter.create(self.cur_url_changed))
|
tab.urlChanged.connect(self._filter.create(self.cur_url_changed))
|
||||||
# hintmanager
|
# hintmanager
|
||||||
tab.hintmanager.hint_strings_updated.connect(self.hint_strings_updated)
|
tab.hintmanager.hint_strings_updated.connect(self.hint_strings_updated)
|
||||||
tab.hintmanager.set_cmd_text.connect(self.set_cmd_text)
|
|
||||||
# misc
|
# misc
|
||||||
tab.titleChanged.connect(self.on_title_changed)
|
tab.titleChanged.connect(self.on_title_changed)
|
||||||
tab.open_tab.connect(self.tabopen)
|
tab.open_tab.connect(self.tabopen)
|
||||||
@ -235,23 +233,15 @@ class TabbedBrowser(TabWidget):
|
|||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs', hide=True)
|
@cmdutils.register(instance='mainwindow.tabs', hide=True)
|
||||||
def tabopencur(self):
|
def tabopencur(self):
|
||||||
"""Set the statusbar to :tabopen and the current URL.
|
"""Set the statusbar to :tabopen and the current URL."""
|
||||||
|
|
||||||
Emit:
|
|
||||||
set_cmd_text prefilled with :tabopen $URL
|
|
||||||
"""
|
|
||||||
url = urlutils.urlstring(self.currentWidget().url())
|
url = urlutils.urlstring(self.currentWidget().url())
|
||||||
self.set_cmd_text.emit(':tabopen ' + url)
|
message.set_cmd_text(':tabopen ' + url)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs', hide=True)
|
@cmdutils.register(instance='mainwindow.tabs', hide=True)
|
||||||
def opencur(self):
|
def opencur(self):
|
||||||
"""Set the statusbar to :open and the current URL.
|
"""Set the statusbar to :open and the current URL."""
|
||||||
|
|
||||||
Emit:
|
|
||||||
set_cmd_text prefilled with :open $URL
|
|
||||||
"""
|
|
||||||
url = urlutils.urlstring(self.currentWidget().url())
|
url = urlutils.urlstring(self.currentWidget().url())
|
||||||
self.set_cmd_text.emit(':open ' + url)
|
message.set_cmd_text(':open ' + url)
|
||||||
|
|
||||||
@cmdutils.register(instance='mainwindow.tabs', name='undo')
|
@cmdutils.register(instance='mainwindow.tabs', name='undo')
|
||||||
def undo_close(self):
|
def undo_close(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user