mirror of
https://github.com/LazoCoder/Pokemon-Terminal
synced 2024-12-18 08:13:09 +00:00
Merge pull request #51 from cclauss/patch-2
Simplify with triple quoted strings and str.format()
This commit is contained in:
commit
d0d46cec4e
1 changed files with 11 additions and 15 deletions
26
scripter.py
26
scripter.py
|
@ -6,6 +6,12 @@ import subprocess
|
||||||
|
|
||||||
from adapter import identify
|
from adapter import identify
|
||||||
|
|
||||||
|
osa_script_fmt = """tell application "System Events"
|
||||||
|
\ttell current desktop
|
||||||
|
\t\tset picture to "{}"
|
||||||
|
\tend tell
|
||||||
|
end tell"""
|
||||||
|
|
||||||
|
|
||||||
def clear_terminal():
|
def clear_terminal():
|
||||||
adapter = identify()
|
adapter = identify()
|
||||||
|
@ -17,16 +23,6 @@ def change_terminal(pokemon):
|
||||||
adapter.set_pokemon(pokemon)
|
adapter.set_pokemon(pokemon)
|
||||||
|
|
||||||
|
|
||||||
def __wallpaper_script(pokemon):
|
|
||||||
# Create the content for the script that will change the wallpaper.
|
|
||||||
content = "tell application \"System Events\"\n"
|
|
||||||
content += "\ttell current desktop\n"
|
|
||||||
content += "\t\tset picture to \"" + pokemon.get_path() + "\"\n"
|
|
||||||
content += "\tend tell\n"
|
|
||||||
content += "end tell"
|
|
||||||
return content
|
|
||||||
|
|
||||||
|
|
||||||
def __run_osascript(stream):
|
def __run_osascript(stream):
|
||||||
p = subprocess.Popen(['osascript'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
|
p = subprocess.Popen(['osascript'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||||
p.stdin.write(stream)
|
p.stdin.write(stream)
|
||||||
|
@ -36,17 +32,17 @@ def __run_osascript(stream):
|
||||||
|
|
||||||
def change_wallpaper(pokemon):
|
def change_wallpaper(pokemon):
|
||||||
if sys.platform == "darwin":
|
if sys.platform == "darwin":
|
||||||
script = __wallpaper_script(pokemon)
|
script = osa_script_fmt.format(pokemon.get_path())
|
||||||
__run_osascript(str.encode(script))
|
__run_osascript(str.encode(script))
|
||||||
if sys.platform == "linux":
|
elif sys.platform == "linux":
|
||||||
os.system(__linux_create_wallpaper_script(pokemon))
|
os.system(__linux_create_wallpaper_script(pokemon))
|
||||||
|
|
||||||
|
|
||||||
def __linux_create_wallpaper_script(pokemon):
|
def __linux_create_wallpaper_script(pokemon):
|
||||||
# If its gnome... aka GDMSESSION=gnome-xorg, etc.
|
# If its gnome... aka GDMSESSION=gnome-xorg, etc.
|
||||||
if os.environ.get("GDMSESSION").find("gnome") >= 0:
|
if "gnome" in os.environ.get("GDMSESSION"):
|
||||||
return "gsettings set org.gnome.desktop.background picture-uri " + \
|
fmt = 'gsettings set org.gnome.desktop.background picture-uri "file://{}"'
|
||||||
"\"file://"+ pokemon.get_path()+"\""
|
return fmt.format(pokemon.get_path())
|
||||||
#elif condition of KDE...
|
#elif condition of KDE...
|
||||||
else:
|
else:
|
||||||
print("Window manager not supported ")
|
print("Window manager not supported ")
|
||||||
|
|
Loading…
Reference in a new issue