Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
FUSS
fuss-utility
Commits
791d340f
Commit
791d340f
authored
Oct 25, 2019
by
Elena Grandi
Browse files
Migrated set-session-language from fuss-client
parent
46307a0d
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/set-session-language.desktop
0 → 100644
View file @
791d340f
[Desktop Entry]
Type=Application
Encoding=UTF-8
Exec=set-session-language
Name=Set Language for Next Session
Terminal=False
Categories=Settings;
src/set_session_language.py
0 → 100755
View file @
791d340f
#!/usr/bin/env python3
import
os.path
import
subprocess
import
tkinter
as
tk
from
gettext
import
gettext
as
_
class
App
(
tk
.
Frame
):
def
__init__
(
self
,
master
=
None
):
super
().
__init__
(
master
)
self
.
master
.
title
(
_
(
"Set session locale"
))
self
.
chosen_locale
=
tk
.
StringVar
(
self
)
self
.
find_locales
()
self
.
pack
()
self
.
create_widgets
()
def
find_locales
(
self
):
res
=
locales
=
subprocess
.
run
(
[
'locale'
,
'-a'
],
stdout
=
subprocess
.
PIPE
,
)
self
.
locales
=
[]
for
l
in
res
.
stdout
.
split
(
b
'
\n
'
):
if
b
'utf8'
in
l
:
self
.
locales
.
append
(
l
.
decode
())
def
create_widgets
(
self
):
self
.
text
=
tk
.
Label
(
self
,
text
=
_
(
"Select the locale for your future sessions."
)
)
self
.
text
.
pack
(
side
=
"top"
)
self
.
chosen_locale
.
set
(
self
.
locales
[
0
])
self
.
locale_menu
=
tk
.
OptionMenu
(
self
,
self
.
chosen_locale
,
*
self
.
locales
)
self
.
locale_menu
.
pack
(
side
=
"top"
)
self
.
set_button
=
tk
.
Button
(
self
)
self
.
set_button
[
'text'
]
=
"Set locale"
self
.
set_button
[
'command'
]
=
self
.
set_locale
self
.
set_button
.
pack
(
side
=
"bottom"
)
def
set_locale
(
self
):
dmfname
=
os
.
path
.
expanduser
(
'~/.dmrc'
)
lines
=
[]
try
:
with
open
(
dmfname
,
'r'
)
as
fp
:
not_found
=
True
for
l
in
fp
.
readlines
():
if
l
.
startswith
(
'Language'
):
lines
.
append
(
"Language={l}
\n
"
.
format
(
l
=
self
.
chosen_locale
.
get
())
)
not_found
=
False
else
:
lines
.
append
(
l
)
if
not_found
:
lines
.
append
(
"Language={l}
\n
"
.
format
(
l
=
self
.
chosen_locale
.
get
())
)
except
FileNotFoundError
:
lines
=
[
"[Desktop]
\n
"
,
"Language={l}
\n
"
.
format
(
l
=
self
.
chosen_locale
.
get
()),
]
with
open
(
dmfname
,
'w'
)
as
wfp
:
for
l
in
lines
:
wfp
.
write
(
l
)
root
.
destroy
()
root
=
tk
.
Tk
()
app
=
App
(
master
=
root
)
app
.
mainloop
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment