Use the current layout instead of the us layout (#2495)
* use the current layout instead of the us layout * fix linting erros and add exception handling for SysCommand
This commit is contained in:
parent
bab06e4d75
commit
39d096b79f
|
|
@ -1,7 +1,7 @@
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Dict, Any, TYPE_CHECKING, Optional
|
from typing import Dict, Any, TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from .utils import list_keyboard_languages, list_locales, set_kb_layout
|
from .utils import list_keyboard_languages, list_locales, set_kb_layout, get_kb_layout
|
||||||
from ..menu import Selector, AbstractSubMenu, MenuSelectionType, Menu
|
from ..menu import Selector, AbstractSubMenu, MenuSelectionType, Menu
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
|
|
@ -16,7 +16,10 @@ class LocaleConfiguration:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def default() -> 'LocaleConfiguration':
|
def default() -> 'LocaleConfiguration':
|
||||||
return LocaleConfiguration('us', 'en_US', 'UTF-8')
|
layout = get_kb_layout()
|
||||||
|
if layout == "":
|
||||||
|
return LocaleConfiguration('us', 'en_US', 'UTF-8')
|
||||||
|
return LocaleConfiguration(layout, 'en_US', 'UTF-8')
|
||||||
|
|
||||||
def json(self) -> Dict[str, str]:
|
def json(self) -> Dict[str, str]:
|
||||||
return {
|
return {
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,30 @@ def verify_x11_keyboard_layout(layout :str) -> bool:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def get_kb_layout() -> str:
|
||||||
|
try:
|
||||||
|
lines = SysCommand(
|
||||||
|
"localectl --no-pager status",
|
||||||
|
environment_vars={'SYSTEMD_COLORS': '0'}
|
||||||
|
).decode().splitlines()
|
||||||
|
except:
|
||||||
|
return ""
|
||||||
|
|
||||||
|
vcline = ""
|
||||||
|
for line in lines:
|
||||||
|
if "VC Keymap: " in line:
|
||||||
|
vcline = line
|
||||||
|
|
||||||
|
if vcline == "":
|
||||||
|
return ""
|
||||||
|
|
||||||
|
layout = vcline.split(": ")[1]
|
||||||
|
if not verify_keyboard_layout(layout):
|
||||||
|
return ""
|
||||||
|
|
||||||
|
return layout
|
||||||
|
|
||||||
|
|
||||||
def set_kb_layout(locale :str) -> bool:
|
def set_kb_layout(locale :str) -> bool:
|
||||||
if len(locale.strip()):
|
if len(locale.strip()):
|
||||||
if not verify_keyboard_layout(locale):
|
if not verify_keyboard_layout(locale):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue