Commit Graph

196 Commits

Author SHA1 Message Date
Florian Bruhin 5c2076ab2d tests: Add Qt.Key.Key_Keyboard
New in Qt 6.10:
https://codereview.qt-project.org/c/qt/qtbase/+/605015
2025-10-12 13:32:01 +02:00
Florian Bruhin 4d069b8fc3 Use str.removeprefix() and str.removesuffix()
https://docs.python.org/3/whatsnew/3.9.html#new-string-methods-to-remove-prefixes-and-suffixes
2024-10-13 18:24:44 +02:00
Florian Bruhin 72d7e2327b Update for new pylint/astroid releases
- Add a couple new "raise utils.Unreachable" to avoid
  possibly-used-before-assignment issues.
- Simplify an "if" for the same reason
- Remove an unneeded "return"
- Use "NoReturn" to prepare for pylint knowing about it in the future:
  https://github.com/pylint-dev/pylint/issues/9674
- Add some ignores for used-before-assignment false-positives
- Ignore new undefined-variable messages for Qt wrapers
- Ignore a new no-member warning for KeySequence:
  https://github.com/pylint-dev/astroid/issues/2448#issuecomment-2130124755
2024-05-24 21:46:04 +02:00
Philipp Albrecht 51aa7abe54 Handle count exceeding string to int conversion
When handling counts during keyparsing we convert the count string to an integer. If the
count is too high (i.e. the count string has too many digits), we run into Python's
integer string conversion length limit[1]:
```
ValueError: Exceeds the limit (4300 digits) for integer string conversion: value has
4301 digits; use sys.set_int_max_str_digits() to increase the limit
```

Instead of blowing up with an exception, we now handle this more gracefully by showing
an error message.

Reproducer:
```
$ qutebrowser --temp-basedir ":later 500 fake-key -g $(printf '1%.0s' {1..4301})j"
```

**NOTE:**
I had to rename `_debug_log()`'s `message` argument to `msg`, because pylint yelled at
me for redefined-outer-name[2].

[1] https://docs.python.org/3/library/stdtypes.html#integer-string-conversion-length-limitation
[2] https://pylint.readthedocs.io/en/stable/user_guide/messages/warning/redefined-outer-name.html
2023-08-27 13:31:11 +02:00
Florian Bruhin 3eb826f664 reuse: Update remaining copyright texts
git ls-files | \
    xargs sed -Ei 's/Copyright [0-9]{4}(-[0-9]{4}) ([^<]*)<([^>]*)>/SPDX-FileCopyrightText: \2<\3>/'
2023-07-23 12:52:01 +02:00
Florian Bruhin 0718b25796 reuse: Initial copyright text update for myself
git ls-files | \
    xargs sed -Ei 's/Copyright [0-9]{4}(-[0-9]{4}) Florian Bruhin \(The Compiler\) <mail@qutebrowser\.org>/SPDX-FileCopyrightText: Florian Bruhin (The Compiler) <mail@qutebrowser.org>/'
2023-07-23 12:49:05 +02:00
Florian Bruhin b2aaba6043 reuse: Adjust most license headers
git ls-files | xargs grep -l "is free software"  | xargs reuse annotate --license="GPL-3.0-or-later" --skip-unrecognised
2023-07-23 12:11:07 +02:00
Florian Bruhin 4e67a1727a Fix lint/test issues 2023-06-30 19:29:28 +02:00
Florian Bruhin 37791422bf qt6: Make sure KeyInfo never has ints as members
This used to be possible in some situations and was handled in somewhat
unexpected places (e.g. .to_qt()). Instead, we now assume that KeyInfo
is always "clean", and we handle the conversion from an int to a Qt.Key
elsewhere.

This only seems to affect tests, since otherwise we already made sure
we get a Qt.Key and Qt.KeyboardModifier(s) e.g. in .from_event().
2023-06-30 19:29:28 +02:00
Philipp Albrecht d9e8b638bf Remove vim modelines
We're deprecating vim modelines in favor of `.editorconfig`.

Removing vim modelines could be done using two one-liners. Most of the vim modelines
were followed by an empty line, so this one-liner took care of these ones:

```sh
rg '^# vim: .+\n\n' -l | xargs sed -i '/^# vim: /,+1d'
```

Then some of the vim modelines were followed by a pylint configuration line, so running
this one-liner afterwards took care of that:

```sh
rg '^# vim:' -l | xargs sed -i '/^# vim: /d'
```
2023-06-30 11:03:06 +02:00
Florian Bruhin 48ea86fcb5 Rename some qt6 FIXMEs
Not relevant for v3 and qt6
2023-06-25 23:32:59 +02:00
Florian Bruhin f7753550f2 keyutils: Move public functions to KeyInfo
This avoids the temptation of creating a Qt.Key() manually, which needs
to be checked for ValueError with PyQt 6.2 due to its handling of unknown enum
values.

This is exactly what happened in RegisterKeyParser, which caused such a
ValueError:
https://github.com/qutebrowser/qutebrowser/issues/7047#issuecomment-1163288560

Closes #7047
2022-08-23 18:31:42 +02:00
Florian Bruhin 769ef6859f Adjust some fixme comments 2022-08-23 18:31:42 +02:00
Florian Bruhin 3ba56bcc6e old qt: Remove unneeded multimedia key names
Those were added to Qt 5.14:
https://codereview.qt-project.org/c/qt/qtbase/+/278803

TODO: Changelog for different names for "To-do list" and
"Adjust contrast"?
2022-08-23 18:31:41 +02:00
Florian Bruhin e658ce6acf lint: Remove unused imports
Via autoflake and git add -p
2022-08-23 18:31:41 +02:00
Florian Bruhin 805e43cf97 WIP: Avoid line-too-long
TODO: Revert once we use black
2022-08-23 18:31:41 +02:00
Florian Bruhin c13bf667d9 qt6 tests: Also apply pyqt_enum_workaround() for modeparsers 2022-08-23 18:31:41 +02:00
Florian Bruhin 6534e2d899 Fix return value for FakeKeyParser.handle
TODO: Pick to master?

In 42e2438efb, we changed "_handle_key" to return
a QKeySequence.SequenceMatch instead of a bool.

Later in b85fe8f678, that change propagated to
"handle" too.

However, the FakeKeyParser introduced in
c1d3a94936 still returned a bool.

This wasn't a problem because we still just checked "if match:".
However, with 756db287ac4c65350aaf53d6f93b6a0a2b356a77, we now check
"if match != QKeySequence.SequenceMatch.NoMatch:", thus the comparsison
with the FakeKeyParser is now the wrong way around.
2022-08-23 18:31:41 +02:00
Florian Bruhin e555c2e0a0 keyutils: Make sure KeyInfo has separate key/mod
If we test for this in KeyInfo() directly (via __post_init__), all code using a
KeyInfo can be sure it has a properly split key/modifier. This is especially
important on Qt 5, where lots of Qt internals use a split value (Qt 6 introduced
QKeyCombination instead).

This however leads to different behaviour when -1 is passed as a key, that now
fails with an AssertionError. However, I believe that to be more correct:

- Testing for -1 was originally introduced in
  866c758660, expecting an AssertionError.
- It was updated in d1854eddaf, still
  expecting an AssertionError
- In 0ee7fac727, we changed that to KeyParseError
  (in the tests only), probably in response to
  78f6ad14c2.

Now that we properly check for this, it's fine to expect an AssertionError
again. I don't think we can ever get -1 from Qt anyways.
2022-08-23 18:31:41 +02:00
Florian Bruhin 1f3e7e19f8 Make keyutils._assert_plain_* work on Qt 6 2022-08-23 18:31:41 +02:00
Florian Bruhin fe4c2d278d qt6: Handle invalid Qt.Key members in more places
Everything in keyutils constructing a Qt.Key should catch ValueError and reraise
it as InvalidKeyError (low-level). Anything in KeySequence that calls such
methods should re-raise that as a KeyParseError to user code (high-level).

The tests skip anything that relies on constructing things with "strange" keys.
Maybe some of them could be gotten to work, but most probably won't work until
PyQt gets fixed, see e.g.:
https://www.riverbankcomputing.com/pipermail/pyqt/2022-April/044607.html
2022-08-23 18:31:41 +02:00
Florian Bruhin 232bea57e3 Add a KeyInfo.__repr__ 2022-08-23 18:31:41 +02:00
Florian Bruhin 437caf4516 qt 6: Fix getting enum members in tests 2022-08-23 18:31:41 +02:00
Florian Bruhin a512d6527b qt6 tests: Fix some enum issues around test_keyutils.py 2022-08-23 18:31:40 +02:00
Florian Bruhin 623b06bc3d Fix remaining enum/flag issues 2022-08-23 18:31:40 +02:00
Florian Bruhin ef9e4a6663 qt6 tests: Small collection fixes 2022-08-23 18:31:40 +02:00
Florian Bruhin f8520b0a76 Simplify KeyInfo.to_qt 2022-08-23 18:31:40 +02:00
Florian Bruhin 3e21c8214a Store KeyInfo in KeySequence 2022-08-23 18:31:40 +02:00
Florian Bruhin 76f9262def Fix missed enum scope changes
For some reason, QtMsgType was not included and missing.
(cherry picked from commit 6afa00c465)

For completiondelegate.py, we accessed the enum members via self instead of
properly using the class.
(cherry picked from commit d37cc4ac73)

For interceptor.py, line breaks broke our script.

QKeyEvent.KeyPress was used inherited from QEvent.KeyPress, thus not
renamed.
2022-08-23 18:31:40 +02:00
Florian Bruhin 0877fb0d78 Run scripts/dev/rewrite_enums.py 2022-08-23 18:31:38 +02:00
Florian Bruhin d47cfd99d7 Run scripts/dev/rewrite_qt_imports.sh 2022-08-23 18:09:11 +02:00
Philipp Albrecht b900f1dd30 Make interpreting number keys as counts configurable
By default numbers are interpreted as counts for bindings. Making this
behavior configurable allows for emacs-like bindings, where number keys
are passed through.
2021-11-28 15:50:04 +01:00
Florian Bruhin 5b6d2c60b4 Fix bindings.key_mappings with multiple keys
Otherwise, when e.g. doing "<Meta+Up>": "gg" in bindings.key_mappings,
there's a crash like:

    Traceback (most recent call last):
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/eventfilter.py", line 105, in eventFilter
        return handler(typing.cast(QKeyEvent, event))
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/eventfilter.py", line 75, in _handle_key_event
        return man.handle_event(event)
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/modeman.py", line 462, in handle_event
        return handler(cast(QKeyEvent, event))
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/modeman.py", line 283, in _handle_keypress
        match = parser.handle(event, dry_run=dry_run)
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/modeparsers.py", line 105, in handle
        match = super().handle(e, dry_run=dry_run)
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/basekeyparser.py", line 309, in handle
        result = self._match_key_mapping(result.sequence)
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/basekeyparser.py", line 246, in _match_key_mapping
        mapped = sequence.with_mappings(
      File "/usr/lib/python3.9/site-packages/qutebrowser/keyinput/keyutils.py", line 675, in with_mappings
        assert len(new_seq) == 1
    AssertionError

While this isn't the intended way to use this setting, we shouldn't
crash - and let's just make it work instead of forbidding it.
2021-03-20 11:10:30 +01:00
Lembrun e8b05af233 Qtbot methods changed to snake case,snake case check added 2021-02-26 22:07:08 +01:00
Florian Bruhin d0d7114923 Revert "old qt: Use ApplicationAttribute to switch Ctrl/Meta on Mac"
This reverts commit 1132324db9.

Causes various issues with Qt/QtWebEngine shortcuts.
Fixes #6174
Closes #6149
2021-02-24 09:57:06 +01:00
Florian Bruhin 1a4fff1a42 doc: Switch URLs to https 2021-01-26 15:19:01 +01:00
Florian Bruhin 41afe0febe Support Super as modifier name
See https://github.com/qutebrowser/qutebrowser/discussions/5999#discussioncomment-297309
2021-01-22 17:37:42 +01:00
Florian Bruhin 222f1f19a1 Bump copyright years
Closes #6015
2021-01-20 20:06:19 +01:00
Florian Bruhin 14373db9c7 dataclasses: Adjust import order
See #6023
2021-01-13 20:26:57 +01:00
Florian Bruhin 124fe5676b dataclasses: Fix ordering
See #6023
2021-01-13 20:26:51 +01:00
Florian Bruhin c970c63355 dataclasses: Initial switch
See #6023
2021-01-13 20:26:41 +01:00
Florian Bruhin c175823020 Add objects.qapp to avoid needing to None-check
We know that QApplication.instance() will always be non-None for
practical purposes, but the stubs now (correctly) declare it as
Optional.

See https://github.com/stlehmann/PyQt5-stubs/pull/126
2021-01-11 18:47:15 +01:00
Florian Bruhin 19586576c5 Revert "Work around PyQt 5.15.1 waitSignals issues"
This reverts commit b55675ad4a.
2020-11-24 18:48:19 +01:00
Florian Bruhin 1132324db9 old qt: Use ApplicationAttribute to switch Ctrl/Meta on Mac 2020-11-04 18:30:04 +01:00
Florian Bruhin b55675ad4a Work around PyQt 5.15.1 waitSignals issues
This should be reverted with PyQt 5.15.2.
See #5719
2020-09-15 13:56:00 +02:00
Florian Bruhin 2e992d3a74 Fix tests/lint 2020-06-17 17:36:49 +02:00
Florian Bruhin 6031827103 Fix lint 2020-06-17 16:53:34 +02:00
Florian Bruhin d6eebbd3f9 tests: Get rid of fake_keyevent
Use keyutils.KeyInfo(...).to_event() instead.
2020-06-17 16:00:23 +02:00
Florian Bruhin bc88e67395 Add BindingTrie.__str__ 2020-06-17 15:42:42 +02:00
Florian Bruhin b25c7d5b36 modeparsers: Refactor how hints are handled
Instead of binding hints to fake :follow-hint commands, we now use a separate
CommandKeyParser and ask that for its match result.

If the key matches with the command parser, it is bound in hint mode, so we
clear the hint keystring and defer to the command handling instead.

If it doesn't, we continue hint handling as usual - however, the HintKeyParser
is now not a CommandKeyParser anymore, so we don't have to deal with command
parsing (and have a custom execute implementation instead).

Closes #4504
Fixes #4392
Fixes #4368
Helps with #5084, though it doesn't completely fix that yet.
Supersedes #3742 (fix for #3735)
Supersedes #4691 (fix for #4264)
2020-06-17 15:42:42 +02:00