New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KeyboardLayout show all layouts instead of current #373
Comments
Can use skb? http://plhk.ru/static/skb/skb-0.4.tar.gz import subprocess
keyboard = subprocess.check_output(['skb', '-now']).strip()
print(unicode(keyboard)) |
As a variant, yes. This code is suitable. But I still hope to find solution which uses no external tools (only default X environment). |
Looking at the code for setxkbmap, it looks pretty dumb (i.e. it just takes whatever string the X server gives it and prints that). Are these in any particular order? |
The order doesn't depend on current layout. Guess it is the same as in This solution requeres no external tools, but works only for one or two layouts. Not ideal, but cover ~98% cases. I'll write the fix if noone will propose a better solution. |
Another method. Using kbdd(https://github.com/qnikst/kbdd). import dbus
languages = {
'0': 'EN',
'1': 'RU',
}
def main():
remote_bus = dbus.SessionBus()
# Check if kbdd is running.
system_service_list = remote_bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus').ListNames()
kbdd_api_found = 0
for service in system_service_list:
if service == 'ru.gentoo.KbddService':
kbdd_api_found = 1
break
if not kbdd_api_found:
return -1
# Get kbdd dbus api
kbdd_service = remote_bus.get_object('ru.gentoo.KbddService', '/ru/gentoo/KbddService')
# Connect to kdbb.
answer = kbdd_service.getCurrentLayout()
return answer
if __name__ == "__main__":
result = main()
print(languages[unicode(result)]) |
import subprocess
import re
languages = {
'first': 'EN',
'second': 'RU',
}
regular_strings = {
'hexadecimal': {
'first': """\w{4}e\w{3}""",
'second': """\w{4}f\w{3}""",
},
'binary': {
'first': """\w{4}0\w{3}""",
'second': """\w{4}1\w{3}""",
},
"inetger": "\d{8}",
"led_mask": """LED mask:\s\s\w{8}""",
}
data = subprocess.check_output(['xset', '-q'])
raw_list = []
for item in data.strip().splitlines():
if re.search(regular_strings['led_mask'], item):
raw_led_mask = re.search(regular_strings['led_mask'], item).group()
raw_list = raw_led_mask.split(':')
led_mask = raw_list[1].strip()
break
print("led_mask", led_mask)
if not re.search(regular_strings['inetger'], led_mask):
cur_regular_strings = regular_strings['hexadecimal']
else:
cur_regular_strings = regular_strings['binary']
if re.search(cur_regular_strings['first'], led_mask):
print languages['first']
elif re.search(cur_regular_strings['second'], led_mask):
print languages['second']
else:
print(None) |
I did some tests for this case.
I suggest to close this issue |
KeyboardLayout
widget usessetxkbmap -query
to get current layout, but in my case this command prints all layouts instead of current:This situation is also described here
The text was updated successfully, but these errors were encountered: