Add utils.supports_selection()
This commit is contained in:
parent
3e6ac28c66
commit
b9b6f357da
@ -688,7 +688,7 @@ class CommandDispatcher:
|
||||
s = self._current_url().toString(flags)
|
||||
what = 'URL'
|
||||
|
||||
if sel and QApplication.clipboard().supportsSelection():
|
||||
if sel and utils.supports_selection():
|
||||
target = "primary selection"
|
||||
else:
|
||||
sel = False
|
||||
@ -833,7 +833,7 @@ class CommandDispatcher:
|
||||
bg: Open in a background tab.
|
||||
window: Open in new window.
|
||||
"""
|
||||
if sel and QApplication.clipboard().supportsSelection():
|
||||
if sel and utils.supports_selection():
|
||||
target = "Primary selection"
|
||||
else:
|
||||
sel = False
|
||||
@ -1756,7 +1756,7 @@ class CommandDispatcher:
|
||||
message.info(self._win_id, "Nothing to yank")
|
||||
return
|
||||
|
||||
if sel and QApplication.clipboard().supportsSelection():
|
||||
if sel and utils.supports_selection():
|
||||
target = "primary selection"
|
||||
else:
|
||||
sel = False
|
||||
|
@ -28,7 +28,6 @@ import string
|
||||
from PyQt5.QtCore import (pyqtSignal, pyqtSlot, QObject, QEvent, Qt, QUrl,
|
||||
QTimer)
|
||||
from PyQt5.QtGui import QMouseEvent
|
||||
from PyQt5.QtWidgets import QApplication
|
||||
from PyQt5.QtWebKit import QWebElement
|
||||
from PyQt5.QtWebKitWidgets import QWebPage
|
||||
|
||||
@ -492,7 +491,7 @@ class HintManager(QObject):
|
||||
context: The HintContext to use.
|
||||
"""
|
||||
if (context.target == Target.yank_primary and
|
||||
QApplication.clipboard().supportsSelection()):
|
||||
utils.supports_selection()):
|
||||
sel = True
|
||||
else:
|
||||
sel = False
|
||||
|
@ -757,22 +757,20 @@ def newest_slice(iterable, count):
|
||||
|
||||
def set_clipboard(data, selection=False):
|
||||
"""Set the clipboard to some given data."""
|
||||
clipboard = QApplication.clipboard()
|
||||
if selection and not clipboard.supportsSelection():
|
||||
if selection and not supports_selection():
|
||||
raise SelectionUnsupportedError
|
||||
if log_clipboard:
|
||||
what = 'primary selection' if selection else 'clipboard'
|
||||
log.misc.debug("Setting fake {}: {}".format(what, json.dumps(data)))
|
||||
else:
|
||||
mode = QClipboard.Selection if selection else QClipboard.Clipboard
|
||||
clipboard.setText(data, mode=mode)
|
||||
QApplication.clipboard().setText(data, mode=mode)
|
||||
|
||||
|
||||
def get_clipboard(selection=False):
|
||||
"""Get data from the clipboard."""
|
||||
global fake_clipboard
|
||||
clipboard = QApplication.clipboard()
|
||||
if selection and not clipboard.supportsSelection():
|
||||
if selection and not supports_selection():
|
||||
raise SelectionUnsupportedError
|
||||
|
||||
if fake_clipboard is not None:
|
||||
@ -780,6 +778,11 @@ def get_clipboard(selection=False):
|
||||
fake_clipboard = None
|
||||
else:
|
||||
mode = QClipboard.Selection if selection else QClipboard.Clipboard
|
||||
data = clipboard.text(mode=mode)
|
||||
data = QApplication.clipboard().text(mode=mode)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def supports_selection():
|
||||
"""Check if the OS supports primary selection."""
|
||||
return QApplication.clipboard().supportsSelection()
|
||||
|
@ -979,3 +979,8 @@ class TestGetSetClipboard:
|
||||
utils.fake_clipboard = 'fake clipboard text'
|
||||
utils.get_clipboard(selection=selection)
|
||||
assert utils.fake_clipboard is None
|
||||
|
||||
@pytest.mark.parametrize('selection', [True, False])
|
||||
def test_supports_selection(self, clipboard_mock, selection):
|
||||
clipboard_mock.supportsSelection.return_value = selection
|
||||
assert utils.supports_selection == selection
|
||||
|
Loading…
Reference in New Issue
Block a user