mirror of
https://github.com/LazoCoder/Pokemon-Terminal
synced 2024-11-23 04:13:20 +00:00
Merge pull request #84 from cclauss/patch-2
Scripter accepts an image_file_path, not a pokemon
This commit is contained in:
commit
eee1106466
7 changed files with 62 additions and 67 deletions
|
@ -7,11 +7,11 @@ class TerminalAdapterInterface(object):
|
|||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def set_pokemon(self, pokemon):
|
||||
def set_image_file_path(self, image_file_path):
|
||||
"""
|
||||
Set the background image of the terminal.
|
||||
:param pokemon: Information about a Pokémon.
|
||||
:type pokemon: dict
|
||||
:param image_file_path: Path to an image file.
|
||||
:rtype str
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
|
|
|
@ -22,8 +22,8 @@ class ITerm(TerminalAdapterInterface):
|
|||
p.communicate()
|
||||
p.stdin.close()
|
||||
|
||||
def set_pokemon(self, pokemon):
|
||||
stdin = osa_script_fmt.format(pokemon.get_path())
|
||||
def set_image_file_path(self, image_file_path):
|
||||
stdin = osa_script_fmt.format(image_file_path)
|
||||
self.__run_osascript(str.encode(stdin))
|
||||
|
||||
def clear(self):
|
||||
|
|
|
@ -8,7 +8,7 @@ class NullAdapter(TerminalAdapterInterface):
|
|||
def is_available():
|
||||
return True
|
||||
|
||||
def set_pokemon(self, pokemon):
|
||||
def set_image_file_path(self, image_file_path):
|
||||
print(self.err)
|
||||
|
||||
def clear(self):
|
||||
|
|
|
@ -8,8 +8,8 @@ class Terminology(TerminalAdapterInterface):
|
|||
def is_available():
|
||||
return os.environ.get("TERMINOLOGY") == '1'
|
||||
|
||||
def set_pokemon(self, pokemon):
|
||||
os.system('tybg "{}"'.format(pokemon.get_path()))
|
||||
def set_image_file_path(self, image_file_path):
|
||||
os.system('tybg "{}"'.format(image_file_path))
|
||||
|
||||
def clear(self):
|
||||
os.system("tybg")
|
||||
|
|
|
@ -11,11 +11,11 @@ class Tilix(TerminalAdapterInterface):
|
|||
def is_available():
|
||||
return "TILIX_ID" in os.environ
|
||||
|
||||
def set_pokemon(self, pokemon):
|
||||
def set_image_file_path(self, image_file_path):
|
||||
command = 'gsettings set {} {} "{}"'
|
||||
os.system(command.format(self.setting_key,
|
||||
self.setting_field,
|
||||
pokemon.get_path()))
|
||||
image_file_path))
|
||||
|
||||
def clear(self):
|
||||
command = 'gsettings set {} {}'
|
||||
|
|
67
main.py
67
main.py
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
# The main module that brings everything together.
|
||||
"""The main module that brings everything together."""
|
||||
|
||||
from database import Database
|
||||
import random
|
||||
|
@ -10,17 +10,17 @@ import time
|
|||
|
||||
|
||||
def print_list(list_of_items):
|
||||
# Print all the items in a list. Used for printing each Pokemon from a particular region.
|
||||
"""Print all the items in a list. Used for printing each Pokemon from a particular region."""
|
||||
print("\n".join(str(item) for item in list_of_items))
|
||||
|
||||
|
||||
def print_columns(items):
|
||||
# Print a list as multiple columns instead of just one.
|
||||
"""Print a list as multiple columns instead of just one."""
|
||||
rows = []
|
||||
items_per_column = int(len(items) / 4) + 1
|
||||
for index, pokemon in enumerate(items):
|
||||
if not pokemon.is_extra():
|
||||
name = pokemon.get_id() + " " + str(pokemon.get_name()).capitalize()
|
||||
name = pokemon.get_id() + " " + str(pokemon.get_name()).title()
|
||||
else:
|
||||
name = "--- " + pokemon.get_name()
|
||||
name = name.ljust(20)
|
||||
|
@ -37,7 +37,7 @@ def print_types(db):
|
|||
print('\b\b\b ')
|
||||
|
||||
def prefix_search(db, arg):
|
||||
# Find all Pokemon in database, db, with the prefix, arg.
|
||||
"""Find all Pokemon in database, db, with the prefix, arg."""
|
||||
result = db.names_with_prefix(arg)
|
||||
if len(result) == 0:
|
||||
print("No Pokemon found with prefix '" + arg + "'.")
|
||||
|
@ -46,7 +46,7 @@ def prefix_search(db, arg):
|
|||
|
||||
|
||||
def print_extra(db):
|
||||
# Print all the 'Extra' Pokemon from the 'Extra' folder.
|
||||
"""Print all the 'Extra' Pokemon from the 'Extra' folder."""
|
||||
result = db.get_extra()
|
||||
if len(result) == 0:
|
||||
print("No Pokemon were found in Images/Extra.")
|
||||
|
@ -55,7 +55,7 @@ def print_extra(db):
|
|||
|
||||
|
||||
def print_usage():
|
||||
# Print the instructions of usage.
|
||||
"""Print the instructions of usage."""
|
||||
print(
|
||||
'''
|
||||
Usage:
|
||||
|
@ -109,52 +109,47 @@ def slideshow(db, start, end, seconds="0.25", rand=False):
|
|||
try:
|
||||
for x in r:
|
||||
pokemon = db.get_pokemon(x)
|
||||
scripter.change_terminal(pokemon)
|
||||
scripter.change_terminal(pokemon.get_path())
|
||||
time.sleep(delay)
|
||||
except KeyboardInterrupt:
|
||||
print("Program was terminated.")
|
||||
sys.exit()
|
||||
|
||||
|
||||
def change_terminal_background(db, arg):
|
||||
# Change the terminal background to the specified Pokemon, if it exists.
|
||||
def change_terminal_background(db, arg): # arg is a pokemon_name
|
||||
"""Change the terminal background to the specified Pokemon, if it exists."""
|
||||
if arg in db:
|
||||
pokemon = db.get_pokemon(arg)
|
||||
scripter.change_terminal(pokemon)
|
||||
scripter.change_terminal(pokemon.get_path())
|
||||
else: # If not found in the database, try to give suggestions.
|
||||
suggestions = db.names_with_infix(arg)
|
||||
if len(suggestions) == 0:
|
||||
print("No such Pokemon was found and no suggestions are available.")
|
||||
elif len(suggestions) == 1:
|
||||
scripter.change_terminal(suggestions[0])
|
||||
print("Did you mean " + suggestions[0].get_name().capitalize() + "?")
|
||||
scripter.change_terminal(suggestions[0])
|
||||
else:
|
||||
print("Did you mean " + suggestions[0].get_name().capitalize() + "?")
|
||||
print("Other suggestions:")
|
||||
print_columns(suggestions[1:])
|
||||
scripter.change_terminal(suggestions[0])
|
||||
pokemon = suggestions[0]
|
||||
scripter.change_terminal(pokemon.get_path())
|
||||
print("Did you mean {}?".format(pokemon.get_name().title()))
|
||||
if suggestions[1:]:
|
||||
print("Other suggestions:")
|
||||
print_columns(suggestions[1:])
|
||||
|
||||
|
||||
|
||||
def change_wallpaper(db, arg):
|
||||
# Change the wallpaper to the specified Pokemon, if it exists.
|
||||
def change_wallpaper(db, arg): # arg is a pokemon_name
|
||||
"""Change the wallpaper to the specified Pokemon, if it exists."""
|
||||
if arg in db:
|
||||
pokemon = db.get_pokemon(arg)
|
||||
scripter.change_wallpaper(pokemon)
|
||||
scripter.change_wallpaper(pokemon.get_path())
|
||||
else: # If not found in the database, try to give suggestions.
|
||||
suggestions = db.names_with_infix(arg)
|
||||
if len(suggestions) == 0:
|
||||
print("No such Pokemon was found and no suggestions are available.")
|
||||
elif len(suggestions) == 1:
|
||||
scripter.change_wallpaper(suggestions[0])
|
||||
print("Did you mean " + suggestions[0].get_name().capitalize() + "?")
|
||||
scripter.change_wallpaper(suggestions[0])
|
||||
else:
|
||||
print("Result: " + arg)
|
||||
print("Did you mean " + suggestions[0].get_name().capitalize() + "?")
|
||||
print("Other suggestions:")
|
||||
print_columns(suggestions[1:])
|
||||
scripter.change_wallpaper(suggestions[0])
|
||||
pokemon = suggestions[0]
|
||||
scripter.change_wallpaper(pokemon.get_path())
|
||||
print("Did you mean {}?".format(pokemon.get_name().title()))
|
||||
if suggestions[1:]: # if there are other suggestions
|
||||
print("Other suggestions:")
|
||||
print_columns(suggestions[1:])
|
||||
|
||||
|
||||
def multiple_argument_handler(arg, arg2, escape_code):
|
||||
|
@ -194,7 +189,7 @@ def multiple_argument_handler(arg, arg2, escape_code):
|
|||
|
||||
|
||||
def single_argument_handler(arg, escape_code):
|
||||
# Handle the logic for when there is only one command line parameter inputted.
|
||||
"""Handle the logic for when there is only one command line parameter inputted."""
|
||||
db = Database()
|
||||
|
||||
if len(arg) < 3 and arg.isalpha():
|
||||
|
@ -242,9 +237,9 @@ def single_argument_handler(arg, escape_code):
|
|||
elif arg == "dark" and escape_code:
|
||||
change_wallpaper(db, db.get_dark().get_name())
|
||||
elif arg == "light":
|
||||
change_terminal_background(db, db.get_light())
|
||||
change_terminal_background(db, db.get_light().get_name())
|
||||
elif arg == "dark":
|
||||
change_terminal_background(db, db.get_dark())
|
||||
change_terminal_background(db, db.get_dark().get_name())
|
||||
elif arg in ("type", "types"):
|
||||
print_types(db)
|
||||
elif arg == "slideshow":
|
||||
|
@ -276,7 +271,7 @@ def single_argument_handler(arg, escape_code):
|
|||
|
||||
|
||||
def main(argv):
|
||||
# Entrance to the program.
|
||||
"""Entrance to the program."""
|
||||
if len(argv) == 1:
|
||||
print('No command line arguments specified.'
|
||||
'\nTry typing in a Pokemon name or number.'
|
||||
|
|
42
scripter.py
42
scripter.py
|
@ -13,16 +13,6 @@ osa_script_fmt = """tell application "System Events"
|
|||
end tell"""
|
||||
|
||||
|
||||
def clear_terminal():
|
||||
adapter = identify()
|
||||
adapter.clear()
|
||||
|
||||
|
||||
def change_terminal(pokemon):
|
||||
adapter = identify()
|
||||
adapter.set_pokemon(pokemon)
|
||||
|
||||
|
||||
def __run_osascript(stream):
|
||||
p = subprocess.Popen(['osascript'], stdout=subprocess.PIPE, stdin=subprocess.PIPE)
|
||||
p.stdin.write(stream)
|
||||
|
@ -30,20 +20,30 @@ def __run_osascript(stream):
|
|||
p.stdin.close()
|
||||
|
||||
|
||||
def change_wallpaper(pokemon):
|
||||
if sys.platform == "darwin":
|
||||
script = osa_script_fmt.format(pokemon.get_path())
|
||||
__run_osascript(str.encode(script))
|
||||
elif sys.platform == "linux":
|
||||
os.system(__linux_create_wallpaper_script(pokemon))
|
||||
|
||||
|
||||
def __linux_create_wallpaper_script(pokemon):
|
||||
def __linux_create_wallpaper_script(image_file_path):
|
||||
# If its gnome... aka GDMSESSION=gnome-xorg, etc.
|
||||
if "gnome" in os.environ.get("GDMSESSION"):
|
||||
fmt = 'gsettings set org.gnome.desktop.background picture-uri "file://{}"'
|
||||
return fmt.format(pokemon.get_path())
|
||||
#elif condition of KDE...
|
||||
return fmt.format(image_file_path)
|
||||
# elif condition of KDE...
|
||||
else:
|
||||
print("Window manager not supported ")
|
||||
exit(1)
|
||||
|
||||
|
||||
def clear_terminal():
|
||||
adapter = identify()
|
||||
adapter.clear()
|
||||
|
||||
|
||||
def change_terminal(image_file_path):
|
||||
adapter = identify()
|
||||
adapter.set_pokemon(image_file_path)
|
||||
|
||||
|
||||
def change_wallpaper(image_file_path):
|
||||
if sys.platform == "darwin":
|
||||
script = osa_script_fmt.format(image_file_path)
|
||||
__run_osascript(str.encode(script))
|
||||
elif sys.platform == "linux":
|
||||
os.system(__linux_create_wallpaper_script(image_file_path))
|
||||
|
|
Loading…
Reference in a new issue