Пример #1
0
    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))
Пример #2
0
 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)))
Пример #3
0
 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)
Пример #4
0
        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)
Пример #5
0
        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)
Пример #6
0
def test_int():
    """Test passing an int with explicit klass given."""
    flags = debug.qflags_key(Qt, 0x0021, klass=Qt.Alignment)
    assert flags == 'AlignLeft|AlignTop'
Пример #7
0
def test_unknown():
    """Test passing an unknown value."""
    flags = debug.qflags_key(Qt, 0x1100, klass=Qt.Alignment)
    assert flags == '0x0100|0x1000'
Пример #8
0
def test_multiple():
    """Test with multiple values."""
    flags = debug.qflags_key(Qt, Qt.AlignLeft | Qt.AlignTop)
    assert flags == 'AlignLeft|AlignTop'
Пример #9
0
def test_combined():
    """Test with a combined value."""
    flags = debug.qflags_key(Qt, Qt.AlignCenter)
    assert flags == 'AlignHCenter|AlignVCenter'
Пример #10
0
 def test_single(self):
     """Test with single value."""
     flags = debug.qflags_key(Qt, Qt.AlignTop)
     self.assertEqual(flags, 'AlignTop')
Пример #11
0
def test_single():
    """Test with single value."""
    flags = debug.qflags_key(Qt, Qt.AlignTop)
    assert flags == 'AlignTop'
Пример #12
0
 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')
Пример #13
0
 def test_int_noklass(self):
     """Test passing an int without explicit klass given."""
     with pytest.raises(TypeError):
         debug.qflags_key(Qt, 42)
Пример #14
0
 def test_unknown(self):
     """Test passing an unknown value."""
     flags = debug.qflags_key(Qt, 0x1100, klass=Qt.Alignment)
     self.assertEqual(flags, '0x0100|0x1000')
Пример #15
0
 def test_single(self):
     """Test with single value."""
     flags = debug.qflags_key(Qt, Qt.AlignTop)
     self.assertEqual(flags, 'AlignTop')
Пример #16
0
 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')
Пример #17
0
 def test_combined(self):
     """Test with a combined value."""
     flags = debug.qflags_key(Qt, Qt.AlignCenter)
     self.assertEqual(flags, 'AlignHCenter|AlignVCenter')
Пример #18
0
 def test_multiple(self):
     """Test with multiple values."""
     flags = debug.qflags_key(Qt, Qt.AlignLeft | Qt.AlignTop)
     self.assertEqual(flags, 'AlignLeft|AlignTop')
Пример #19
0
 def test_qflags_key(self, base, value, klass, expected):
     flags = debug.qflags_key(base, value, klass=klass)
     assert flags == expected
Пример #20
0
 def test_add_base(self):
     """Test with add_base=True."""
     flags = debug.qflags_key(Qt, Qt.AlignTop, add_base=True)
     assert flags == 'Qt.AlignTop'
Пример #21
0
 def test_add_base(self):
     """Test with add_base=True."""
     flags = debug.qflags_key(Qt, Qt.AlignTop, add_base=True)
     assert flags == 'Qt.AlignTop'
Пример #22
0
 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')
Пример #23
0
 def test_multiple(self):
     """Test with multiple values."""
     flags = debug.qflags_key(Qt, Qt.AlignLeft | Qt.AlignTop)
     self.assertEqual(flags, 'AlignLeft|AlignTop')
Пример #24
0
 def test_unknown(self):
     """Test passing an unknown value."""
     flags = debug.qflags_key(Qt, 0x1100, klass=Qt.Alignment)
     self.assertEqual(flags, '0x0100|0x1000')
Пример #25
0
 def test_qflags_key(self, base, value, klass, expected):
     flags = debug.qflags_key(base, value, klass=klass)
     assert flags == expected
Пример #26
0
 def test_combined(self):
     """Test with a combined value."""
     flags = debug.qflags_key(Qt, Qt.AlignCenter)
     self.assertEqual(flags, 'AlignHCenter|AlignVCenter')
Пример #27
0
 def test_int_noklass(self):
     """Test passing an int without explicit klass given."""
     with pytest.raises(TypeError):
         debug.qflags_key(Qt, 42)
Пример #28
0
 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')