From 63892c5fcef30c75fde8637a92d458c85477e372 Mon Sep 17 00:00:00 2001 From: Samuel Henrique Date: Wed, 7 Jun 2017 23:15:08 +0000 Subject: [PATCH 1/3] Terminology support --- scripter.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/scripter.py b/scripter.py index 6cb8c20..c34c3a2 100644 --- a/scripter.py +++ b/scripter.py @@ -1,6 +1,7 @@ # Used for creating, running and analyzing applescript and bash scripts. import os +import sys cwd = os.path.dirname(os.path.realpath(__file__)) @@ -25,7 +26,7 @@ def __wallpaper_script(pokemon): return content -def __create_terminal_script(pokemon): +def __iterm2_create_terminal_script(pokemon): # Create and save the script for changing the terminal background image. content = __terminal_script(pokemon) file = open(cwd + "/./Scripts/background.scpt", "wb") @@ -41,7 +42,7 @@ def __create_wallpaper_script(pokemon): file.close() -def __create_terminal_bash(): +def __darwin_create_terminal_bash(): # Create and save the run.sh that will execute the AppleScript if the correct run.sh doesn't already exist. content = "#!/bin/bash\n" + "osascript " + cwd + "/./Scripts/background.scpt" if open(cwd + "/./Scripts/run.sh", 'r').read() == content: @@ -63,10 +64,19 @@ def __create_wallpaper_bash(): def change_terminal(pokemon): # Create, save and run the bash script to change the terminal background. - __create_terminal_script(pokemon) - __create_terminal_bash() - os.system(cwd + "/./Scripts/run.sh") + if sys.platform == "darwin": + __iterm2_create_terminal_script(pokemon) + __darwin_create_terminal_bash() + os.system(cwd + "/./Scripts/run.sh") + if sys.platform == "linux": + os.system(__linux_create_terminal(pokemon)) +def __linux_create_terminal(pokemon): + if os.environ.get("TERMINOLOGY") == '1': + return "tybg " + pokemon.get_path() + else: + print ("Terminal emulator not supported") + exit(1) def change_wallpaper(pokemon): # Create, save and run the bash script to change the wallpaper. From 4cf4a686a2ac7559b934bdc5e9a571953ac826bf Mon Sep 17 00:00:00 2001 From: Samuel Henrique Date: Thu, 8 Jun 2017 02:30:27 +0000 Subject: [PATCH 2/3] Adds GNOME background changing --- scripter.py | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/scripter.py b/scripter.py index c34c3a2..78495bd 100644 --- a/scripter.py +++ b/scripter.py @@ -34,7 +34,7 @@ def __iterm2_create_terminal_script(pokemon): file.close() -def __create_wallpaper_script(pokemon): +def __darwin_create_wallpaper_script(pokemon): # Create and save the script for changing the wallpaper. content = __wallpaper_script(pokemon) file = open(cwd + "/./Scripts/wallpaper.scpt", "wb") @@ -52,7 +52,7 @@ def __darwin_create_terminal_bash(): file.close() -def __create_wallpaper_bash(): +def __darwin_create_wallpaper_bash(): # Create and save the run.sh that will execute the AppleScript if the correct run.sh doesn't already exist. content = "#!/bin/bash\n" + "osascript " + cwd + "/./Scripts/wallpaper.scpt" if open(cwd + "/./Scripts/run.sh", 'r').read() == content: @@ -79,11 +79,22 @@ def __linux_create_terminal(pokemon): exit(1) def change_wallpaper(pokemon): - # Create, save and run the bash script to change the wallpaper. - __create_wallpaper_script(pokemon) - __create_wallpaper_bash() - os.system(cwd + "/./Scripts/run.sh") + if sys.platform == "darwin": + # Create, save and run the bash script to change the wallpaper. + __darwin_create_wallpaper_script(pokemon) + __darwin_create_wallpaper_bash() + os.system(cwd + "/./Scripts/run.sh") + if sys.platform == "linux": + os.system(__linux_create_wallpapper_script(pokemon)) +def __linux_create_wallpapper_script(pokemon): + # If its gnome... + if os.environ.get("GDMSESSION") == 'gnome': + return "gsettings set org.gnome.desktop.background picture-uri file://" + pokemon.get_path() + #elif condition of KDE... + else: + print ("Window manager not supported ") + exit(1) def determine_terminal_pokemon(db): # Print the current Pokemon that is being used as the terminal background. From 0a185e0dd9c801d3d95ded36bf6ba9671127c6e7 Mon Sep 17 00:00:00 2001 From: Samuel Henrique Date: Wed, 7 Jun 2017 23:52:10 -0300 Subject: [PATCH 3/3] Bug fixing --- scripter.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/scripter.py b/scripter.py index 78495bd..9dcfbca 100644 --- a/scripter.py +++ b/scripter.py @@ -52,8 +52,9 @@ def __darwin_create_terminal_bash(): file.close() +# Create and save the run.sh that will execute the AppleScript if the correct run.sh +# doesn't already exist. def __darwin_create_wallpaper_bash(): - # Create and save the run.sh that will execute the AppleScript if the correct run.sh doesn't already exist. content = "#!/bin/bash\n" + "osascript " + cwd + "/./Scripts/wallpaper.scpt" if open(cwd + "/./Scripts/run.sh", 'r').read() == content: return @@ -63,8 +64,8 @@ def __darwin_create_wallpaper_bash(): def change_terminal(pokemon): - # Create, save and run the bash script to change the terminal background. if sys.platform == "darwin": + # Create, save and run the bash script to change the terminal background. __iterm2_create_terminal_script(pokemon) __darwin_create_terminal_bash() os.system(cwd + "/./Scripts/run.sh") @@ -73,9 +74,9 @@ def change_terminal(pokemon): def __linux_create_terminal(pokemon): if os.environ.get("TERMINOLOGY") == '1': - return "tybg " + pokemon.get_path() + return "tybg \"" + pokemon.get_path() + "\"" else: - print ("Terminal emulator not supported") + print("Terminal emulator not supported") exit(1) def change_wallpaper(pokemon): @@ -88,26 +89,27 @@ def change_wallpaper(pokemon): os.system(__linux_create_wallpapper_script(pokemon)) def __linux_create_wallpapper_script(pokemon): - # If its gnome... - if os.environ.get("GDMSESSION") == 'gnome': - return "gsettings set org.gnome.desktop.background picture-uri file://" + pokemon.get_path() + # If its gnome... aka GDMSESSION=gnome-xorg, etc. + if os.environ.get("GDMSESSION").find("gnome") >= 0: + return "gsettings set org.gnome.desktop.background picture-uri " + \ + "\"file://"+ pokemon.get_path()+"\"" #elif condition of KDE... else: - print ("Window manager not supported ") + print("Window manager not supported ") exit(1) +# Print the current Pokemon that is being used as the terminal background. def determine_terminal_pokemon(db): - # Print the current Pokemon that is being used as the terminal background. __determine_pokemon(db, "background.scpt") +# Print the current Pokemon that is being used the wallpaper. def determine_wallpaper_pokemon(db): - # Print the current Pokemon that is being used the wallpaper. __determine_pokemon(db, "wallpaper.scpt") +# Helper method to get the current Pokemon that is in the specified script. def __determine_pokemon(db, script_name): - # Helper method to get the current Pokemon that is in the specified script. path = cwd + "/Scripts/" + script_name try: content = open(path, "r+").readlines()