def _call_cb(self, callback, found, text, flags, caller): """Call the given callback if it's non-None. Delays the call via a QTimer so the website is re-rendered in between. Args: callback: What to call found: If the text was found text: The text searched for flags: The flags searched with caller: Name of the caller. """ found_text = 'found' if found else "didn't find" # Removing FindWrapsAroundDocument to get the same logging as with # QtWebEngine debug_flags = debug.qflags_key( QWebPage, flags & ~QWebPage.FindWrapsAroundDocument, klass=QWebPage.FindFlag) if debug_flags != '0x0000': flag_text = 'with flags {}'.format(debug_flags) else: flag_text = '' log.webview.debug(' '.join([caller, found_text, text, flag_text]) .strip()) if callback is not None: QTimer.singleShot(0, functools.partial(callback, found))
def _on_fullscreen_requested(self, on): if not config.val.content.windowed_fullscreen: if on: self.state_before_fullscreen = self.windowState() self.setWindowState( Qt.WindowFullScreen | self.state_before_fullscreen) elif self.isFullScreen(): self.setWindowState(self.state_before_fullscreen) log.misc.debug('on: {}, state before fullscreen: {}'.format( on, debug.qflags_key(Qt, self.state_before_fullscreen)))
def wrapped_callback(found): """Wrap the callback to do debug logging.""" found_text = 'found' if found else "didn't find" if flags: flag_text = 'with flags {}'.format(debug.qflags_key( QWebEnginePage, flags, klass=QWebEnginePage.FindFlag)) else: flag_text = '' log.webview.debug(' '.join([caller, found_text, text, flag_text]) .strip()) if callback is not None: callback(found)
def wrapped_callback(found): """Wrap the callback to do debug logging.""" self._pending_searches -= 1 if self._pending_searches > 0: # See https://github.com/qutebrowser/qutebrowser/issues/2442 # and https://github.com/qt/qtwebengine/blob/5.10/src/core/web_contents_adapter.cpp#L924-L934 log.webview.debug("Ignoring cancelled search callback with " "{} pending searches".format( self._pending_searches)) return found_text = 'found' if found else "didn't find" if flags: flag_text = 'with flags {}'.format(debug.qflags_key( QWebEnginePage, flags, klass=QWebEnginePage.FindFlag)) else: flag_text = '' log.webview.debug(' '.join([caller, found_text, text, flag_text]) .strip()) if callback is not None: callback(found)
def wrapped_callback(found): """Wrap the callback to do debug logging.""" self._pending_searches -= 1 if self._pending_searches > 0: # See https://github.com/qutebrowser/qutebrowser/issues/2442 # and https://github.com/qt/qtwebengine/blob/5.10/src/core/web_contents_adapter.cpp#L924-L934 log.webview.debug("Ignoring cancelled search callback with " "{} pending searches".format( self._pending_searches)) return found_text = 'found' if found else "didn't find" if flags: flag_text = 'with flags {}'.format( debug.qflags_key(QWebEnginePage, flags, klass=QWebEnginePage.FindFlag)) else: flag_text = '' log.webview.debug(' '.join([caller, found_text, text, flag_text]).strip()) if callback is not None: callback(found)
def test_int(): """Test passing an int with explicit klass given.""" flags = debug.qflags_key(Qt, 0x0021, klass=Qt.Alignment) assert flags == 'AlignLeft|AlignTop'
def test_unknown(): """Test passing an unknown value.""" flags = debug.qflags_key(Qt, 0x1100, klass=Qt.Alignment) assert flags == '0x0100|0x1000'
def test_multiple(): """Test with multiple values.""" flags = debug.qflags_key(Qt, Qt.AlignLeft | Qt.AlignTop) assert flags == 'AlignLeft|AlignTop'
def test_combined(): """Test with a combined value.""" flags = debug.qflags_key(Qt, Qt.AlignCenter) assert flags == 'AlignHCenter|AlignVCenter'
def test_single(self): """Test with single value.""" flags = debug.qflags_key(Qt, Qt.AlignTop) self.assertEqual(flags, 'AlignTop')
def test_single(): """Test with single value.""" flags = debug.qflags_key(Qt, Qt.AlignTop) assert flags == 'AlignTop'
def test_int(self): """Test passing an int with explicit klass given.""" flags = debug.qflags_key(Qt, 0x0021, klass=Qt.Alignment) self.assertEqual(flags, 'AlignLeft|AlignTop')
def test_int_noklass(self): """Test passing an int without explicit klass given.""" with pytest.raises(TypeError): debug.qflags_key(Qt, 42)
def test_unknown(self): """Test passing an unknown value.""" flags = debug.qflags_key(Qt, 0x1100, klass=Qt.Alignment) self.assertEqual(flags, '0x0100|0x1000')
def test_combined(self): """Test with a combined value.""" flags = debug.qflags_key(Qt, Qt.AlignCenter) self.assertEqual(flags, 'AlignHCenter|AlignVCenter')
def test_multiple(self): """Test with multiple values.""" flags = debug.qflags_key(Qt, Qt.AlignLeft | Qt.AlignTop) self.assertEqual(flags, 'AlignLeft|AlignTop')
def test_qflags_key(self, base, value, klass, expected): flags = debug.qflags_key(base, value, klass=klass) assert flags == expected
def test_add_base(self): """Test with add_base=True.""" flags = debug.qflags_key(Qt, Qt.AlignTop, add_base=True) assert flags == 'Qt.AlignTop'
def test_add_base(self): """Test with add_base=True.""" flags = debug.qflags_key(Qt, Qt.AlignTop, add_base=True) self.assertEqual(flags, 'Qt.AlignTop')