Skip to content

Option to look in a custom directory for keyboard layouts#623

Open
d-perl wants to merge 4 commits intolxqt:masterfrom
d-perl:feat/custom_keyboard_layouts
Open

Option to look in a custom directory for keyboard layouts#623
d-perl wants to merge 4 commits intolxqt:masterfrom
d-perl:feat/custom_keyboard_layouts

Conversation

@d-perl
Copy link
Copy Markdown

@d-perl d-perl commented Mar 31, 2026

Hi!
I'm working on trying to package QTermWidget as a pip-installable PySide6 package. For this, since the installation location can't be known at compile time, it would be very useful to be able to change the location searched for the keybindings. This solution is working for me but I'm happy to make any changes required.

@d-perl d-perl changed the title Feat/custom keyboard layouts Option to look in a custom directory for keyboard layouts Mar 31, 2026
@d-perl
Copy link
Copy Markdown
Author

d-perl commented Apr 28, 2026

Hi @tsujan, very sorry to ping you directly about this, but just wondering if you might have time to look at this sometime? I would like to avoid keeping my fork open forever if possible :)

@tsujan
Copy link
Copy Markdown
Member

tsujan commented Apr 28, 2026

It should be reviewed by someone who has mastery over this part of the code. Understandably, all changes/fixes I've done so far have been in those parts that I fully understand; sorry, this isn't one of them.

I'm afraid waiting for a reviewer may be the only choice. @yan12125?

@d-perl
Copy link
Copy Markdown
Author

d-perl commented Apr 28, 2026

Ah, I see. Sorry, I just saw your name a lot in the PRs so I didn't know who else to tag. Thanks a lot for passing the message on!

@tsujan
Copy link
Copy Markdown
Member

tsujan commented Apr 28, 2026

Let me also call a contributor who has done a nice work recently…

@liweitianux, any thought on this?

Copy link
Copy Markdown
Member

@yan12125 yan12125 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I touched this part several years ago 😀. Here are some comments based on my old memory.

Also, https://github.com/lxqt/qtermwidget/blob/master/pyqt/sip/qtermwidget.sip should be updated to include new APIs.

Comment thread lib/KeyboardTranslator.cpp Outdated
Comment thread lib/KeyboardTranslator.cpp
@d-perl d-perl force-pushed the feat/custom_keyboard_layouts branch from 9fb3aaf to 69fb8b6 Compare April 29, 2026 09:02
@d-perl d-perl force-pushed the feat/custom_keyboard_layouts branch from 69fb8b6 to ad536dc Compare April 29, 2026 09:08
@tsujan
Copy link
Copy Markdown
Member

tsujan commented Apr 29, 2026

Yeah, I touched this part several years ago

Ah, thanks! Feel free to merge it if you're satisfied with the changes.

@d-perl
Copy link
Copy Markdown
Author

d-perl commented Apr 29, 2026

Thanks for the comments @yan12125 ! I addressed them as best I could and rebased on master :)

Copy link
Copy Markdown

@liweitianux liweitianux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing, I find pyqt/pyproject.toml lists PyQt6 in the dependencies. Since we're adding QTermWidget to PySide6, a hard dependency on PyQt6 doesn't look good to me. Maybe better just drop PyQt6 here, or can we list both with OR-condition?

{
if (_translatorBaseDir.has_value() && _translatorBaseDir.value().exists()) {
return _translatorBaseDir.value().filePath(name + QLatin1String(".keytab"));
}
Copy link
Copy Markdown

@liweitianux liweitianux Apr 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to further check the existence of file = _translatorBaseDir.value().filePath(name + QLatin1String(".keytab")), and fallback to the bundled layout directory if it doesn't exist?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea but it could also lead to some weird behaviour, if you had similarly named ones for example. In my use case, the default path doesn't actually exist because it is not installed as a system package, and the default path is compiled in as an absolute path from a cmake variable. I'd love it if someone else would weigh in on this.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the default path doesn't actually exist because it is not installed as a system package, ...

It seems the PR's main concern is to make qtermwidget able to find layouts instead of overriding the system/bundled layouts. Because qtermwidget currently can only find layouts from the fixed KB_LAYOUT_DIR that's set by CMake at compile-time, so the Python binding must provide a way to set the correct keyboard layout directory as the Python package can be installed anywhere.

If my above understanding is correct, I think the better API to add might be setKBLayoutDir() and patch get_kb_layout_dir(). One more thing, we can also update get_kb_layout_dir() to prefer an environment variable like QTERMWIDGET_KB_LAYOUT_DIR.

@d-perl
Copy link
Copy Markdown
Author

d-perl commented Apr 29, 2026

@liweitianux thank you for the comments! I think that for a PySide6 build you would need a separate pyproject.toml file - each build is only compatible with the abi it was built against anyway, so the pyqt version has a hard dependency on pyqt and the PySide version has a hard dependency on PySide. By the way, we have a working PySide build setup here https://github.com/bec-project/pyside6-qtermwidget . It packages the keyboard layouts and colour schemes in the wheel and uses the command from this branch to set it to look in the python site-packages dir for them, so that it can be installed in a virtual environment and for various python versions. It's extremely hacky as we aren't cmake experts and had to work around quite a few baked in assumptions, but it works and could be useful for inspiration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants