2017-06-06 17:13:26 +00:00
|
|
|
#!/usr/bin/env python3
|
2017-04-28 07:46:39 +00:00
|
|
|
|
|
|
|
# The main module that brings everything together.
|
|
|
|
|
2017-04-29 05:57:47 +00:00
|
|
|
from database import Database
|
2017-06-24 04:58:03 +00:00
|
|
|
import random
|
2017-04-28 19:51:42 +00:00
|
|
|
import scripter
|
2017-04-28 23:17:44 +00:00
|
|
|
import sys
|
|
|
|
import time
|
2017-04-28 07:46:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
def print_list(list_of_items):
|
|
|
|
# Print all the items in a list. Used for printing each Pokemon from a particular region.
|
2017-06-21 07:00:24 +00:00
|
|
|
print("\n".join(str(item) for item in list_of_items))
|
2017-04-28 07:46:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
def print_columns(items):
|
|
|
|
# Print a list as multiple columns instead of just one.
|
|
|
|
rows = []
|
2017-04-28 08:02:50 +00:00
|
|
|
items_per_column = int(len(items) / 4) + 1
|
2017-06-21 07:00:24 +00:00
|
|
|
for index, pokemon in enumerate(items):
|
2017-04-28 07:46:39 +00:00
|
|
|
if not pokemon.is_extra():
|
2017-04-28 07:55:40 +00:00
|
|
|
name = pokemon.get_id() + " " + str(pokemon.get_name()).capitalize()
|
2017-04-28 07:46:39 +00:00
|
|
|
else:
|
|
|
|
name = "--- " + pokemon.get_name()
|
|
|
|
name = name.ljust(20)
|
|
|
|
if len(rows) < items_per_column:
|
|
|
|
rows.append(name)
|
|
|
|
else:
|
|
|
|
rows[index % items_per_column] += name
|
|
|
|
print_list(rows)
|
|
|
|
|
2017-06-29 18:17:16 +00:00
|
|
|
def print_types(db):
|
|
|
|
print("All existent pokemon types are: ")
|
|
|
|
for x in db.get_pokemon_types():
|
|
|
|
print(x + " - ", end='')
|
|
|
|
print('\b\b\b ')
|
2017-04-28 07:46:39 +00:00
|
|
|
|
|
|
|
def prefix_search(db, arg):
|
|
|
|
# Find all Pokemon in database, db, with the prefix, arg.
|
2017-04-28 19:51:42 +00:00
|
|
|
result = db.names_with_prefix(arg)
|
2017-04-28 07:46:39 +00:00
|
|
|
if len(result) == 0:
|
|
|
|
print("No Pokemon found with prefix '" + arg + "'.")
|
|
|
|
else:
|
|
|
|
print_columns(result)
|
|
|
|
|
|
|
|
|
|
|
|
def print_extra(db):
|
|
|
|
# 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.")
|
|
|
|
else:
|
|
|
|
print_columns(result)
|
|
|
|
|
|
|
|
|
|
|
|
def print_usage():
|
|
|
|
# Print the instructions of usage.
|
|
|
|
print(
|
|
|
|
'''
|
|
|
|
Usage:
|
|
|
|
pokemon [parameter]
|
2017-06-19 00:19:00 +00:00
|
|
|
ichooseyou [parameter]
|
2017-04-28 07:46:39 +00:00
|
|
|
|
|
|
|
Parameters:
|
2017-04-28 08:02:50 +00:00
|
|
|
[name] - Change the terminal background to the specified Pokemon.
|
|
|
|
[index] - Change the terminal background to a Pokemon by its index.
|
|
|
|
[region] - List all the Pokemon of the specified region.
|
|
|
|
[one letter] - List all Pokemon who's names begin with a particular letter.
|
|
|
|
[two letters] - List all Pokemon who's names begin with those two letters.
|
2017-04-28 07:46:39 +00:00
|
|
|
|
|
|
|
Other Parameters:
|
2017-06-24 04:58:03 +00:00
|
|
|
all - List all the Pokemon supported.
|
|
|
|
regions - List all the available regions.
|
|
|
|
extra - List all the Pokemon from the 'Extra' folder.
|
|
|
|
random - Change the terminal background to a random Pokemon.
|
|
|
|
random-<region> - Change the terminal background to a random Pokemon from the specified region.
|
|
|
|
slideshow [time] - Iterate through each Pokemon. Optional time (in seconds) between Pokemon.
|
|
|
|
slideshow-<region> [time] - Iterate through each Pokemon in the specified region. Optional time (in seconds) between Pokemon.
|
|
|
|
rnd-slideshow [time] - Iterate through each Pokemon in a random order. Optional time (in seconds) between Pokemon.
|
|
|
|
rnd-slideshow-<region> [time] - Iterate through each Pokemon in the specified region in a random order. Optional time (in seconds) between Pokemon.
|
2017-06-25 20:07:45 +00:00
|
|
|
light - Change the terminal background to a random light-colored Pokemon.
|
|
|
|
dark - Change the terminal background to a random dark-colored Pokemon.
|
2017-06-29 18:17:16 +00:00
|
|
|
type [type] - Random pokemon of [type] omit the type for a list of types.
|
2017-06-24 04:58:03 +00:00
|
|
|
clear | disable | off - Clear the Pokemon in the terminal.
|
|
|
|
help - Display this menu.
|
2017-06-18 04:07:33 +00:00
|
|
|
|
|
|
|
Wallpaper Parameters:
|
|
|
|
pokemon _pikachu - Change the wallpaper to the specified Pokemon.
|
|
|
|
pokemon _random - Change the wallpaper to a random Pokemon.
|
|
|
|
pokemon _random-kanto - Change the wallpaper to a random Pokemon from the specified region.
|
2017-06-18 04:31:05 +00:00
|
|
|
|
|
|
|
Search System Information:
|
|
|
|
Any input containing 3 or more characters triggers the internal search system. Examples:
|
|
|
|
"pokemon pika" changes the terminal background to Pikachu.
|
|
|
|
"pokemon dos" changes the terminal background to Gyarados.
|
2017-04-28 07:46:39 +00:00
|
|
|
''')
|
|
|
|
|
|
|
|
|
2017-06-24 04:58:03 +00:00
|
|
|
def slideshow(db, start, end, seconds="0.25", rand=False):
|
|
|
|
delay = 0.25
|
|
|
|
if seconds is not None:
|
|
|
|
delay = float(seconds)
|
|
|
|
|
|
|
|
# Show each Pokemon, one by one.
|
|
|
|
r = list(range(start, end))
|
|
|
|
if rand:
|
|
|
|
random.shuffle(r)
|
2017-04-28 23:17:44 +00:00
|
|
|
try:
|
2017-06-24 04:58:03 +00:00
|
|
|
for x in r:
|
2017-07-03 16:31:50 +00:00
|
|
|
image_file_path = db.get_pokemon(x).get_path()
|
|
|
|
scripter.change_terminal(image_file_path)
|
2017-06-24 04:58:03 +00:00
|
|
|
time.sleep(delay)
|
2017-04-28 23:17:44 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
print("Program was terminated.")
|
|
|
|
sys.exit()
|
|
|
|
|
|
|
|
|
2017-04-28 22:26:00 +00:00
|
|
|
def change_terminal_background(db, arg):
|
|
|
|
# Change the terminal background to the specified Pokemon, if it exists.
|
|
|
|
if arg in db:
|
|
|
|
pokemon = db.get_pokemon(arg)
|
2017-07-03 16:31:50 +00:00
|
|
|
scripter.change_terminal(pokemon.get_path())
|
2017-04-29 05:57:47 +00:00
|
|
|
else: # If not found in the database, try to give suggestions.
|
|
|
|
suggestions = db.names_with_infix(arg)
|
2017-07-03 16:31:50 +00:00
|
|
|
try:
|
|
|
|
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:])
|
|
|
|
except IndexError:
|
2017-05-09 13:33:24 +00:00
|
|
|
print("No such Pokemon was found and no suggestions are available.")
|
2017-04-28 22:26:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
def change_wallpaper(db, arg):
|
|
|
|
# Change the wallpaper to the specified Pokemon, if it exists.
|
|
|
|
if arg in db:
|
|
|
|
pokemon = db.get_pokemon(arg)
|
2017-07-03 16:31:50 +00:00
|
|
|
scripter.change_wallpaper(pokemon.get_path())
|
2017-04-29 05:57:47 +00:00
|
|
|
else: # If not found in the database, try to give suggestions.
|
|
|
|
suggestions = db.names_with_infix(arg)
|
2017-07-03 16:31:50 +00:00
|
|
|
try:
|
|
|
|
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:])
|
|
|
|
except IndexError:
|
2017-05-09 13:13:35 +00:00
|
|
|
print("No such Pokemon was found and no suggestions are available.")
|
2017-04-28 22:26:00 +00:00
|
|
|
|
2017-06-18 04:07:33 +00:00
|
|
|
|
2017-06-29 19:36:16 +00:00
|
|
|
def multiple_argument_handler(arg, arg2, escape_code):
|
2017-06-12 00:05:19 +00:00
|
|
|
db = Database()
|
2017-06-24 04:58:03 +00:00
|
|
|
rand = arg.startswith("rnd")
|
2017-06-25 03:49:57 +00:00
|
|
|
if "slideshow" in arg:
|
2017-06-14 04:07:50 +00:00
|
|
|
try:
|
2017-06-24 04:58:03 +00:00
|
|
|
if arg.endswith("slideshow"):
|
|
|
|
slideshow(db, 1, 494, arg2, rand)
|
|
|
|
elif arg.endswith("slideshow-kanto"):
|
|
|
|
slideshow(db, 1, 152, arg2, rand)
|
|
|
|
elif arg.endswith("slideshow-johto"):
|
|
|
|
slideshow(db, 152, 252, arg2, rand)
|
|
|
|
elif arg.endswith("slideshow-hoenn"):
|
|
|
|
slideshow(db, 252, 387, arg2, rand)
|
|
|
|
elif arg.endswith("slideshow-sinnoh"):
|
|
|
|
slideshow(db, 387, 494, arg2, rand)
|
2017-06-14 04:07:50 +00:00
|
|
|
else:
|
2017-06-21 07:00:24 +00:00
|
|
|
print('Invalid slideshow command specified.'
|
|
|
|
'\nType "help" to see all the commands.')
|
2017-06-14 04:07:50 +00:00
|
|
|
except ValueError:
|
2017-06-21 07:00:24 +00:00
|
|
|
print('The slideshow time needs to be a positive number'
|
|
|
|
'\nType "help" to see all the commands.')
|
2017-06-29 18:17:16 +00:00
|
|
|
elif arg.lower() == 'type':
|
|
|
|
arg2 = arg2.lower()
|
|
|
|
if arg2 not in db.get_pokemon_types():
|
|
|
|
print("Invalid type specified")
|
|
|
|
else:
|
|
|
|
target = db.get_pokemon_of_type(arg2).get_name()
|
2017-06-29 19:36:16 +00:00
|
|
|
if escape_code:
|
2017-06-29 18:17:16 +00:00
|
|
|
change_wallpaper(db, target)
|
|
|
|
else:
|
|
|
|
change_terminal_background(db, target)
|
2017-06-14 04:07:50 +00:00
|
|
|
else:
|
2017-06-21 07:00:24 +00:00
|
|
|
print('Invalid command specified.'
|
|
|
|
'\nType "help" to see all the commands.')
|
2017-04-28 22:26:00 +00:00
|
|
|
|
2017-06-18 04:07:33 +00:00
|
|
|
|
2017-06-29 19:36:16 +00:00
|
|
|
def single_argument_handler(arg, escape_code):
|
2017-04-28 07:46:39 +00:00
|
|
|
# Handle the logic for when there is only one command line parameter inputted.
|
|
|
|
db = Database()
|
2017-04-29 06:20:17 +00:00
|
|
|
|
2017-04-28 07:46:39 +00:00
|
|
|
if len(arg) < 3 and arg.isalpha():
|
|
|
|
prefix_search(db, arg)
|
2017-04-29 05:57:47 +00:00
|
|
|
elif arg == "extra":
|
2017-04-28 07:46:39 +00:00
|
|
|
print_extra(db)
|
|
|
|
elif arg == "regions":
|
|
|
|
print_list(db.get_regions())
|
2017-06-18 04:31:05 +00:00
|
|
|
elif arg == "help" or arg.startswith("-h"):
|
2017-04-28 07:46:39 +00:00
|
|
|
print_usage()
|
|
|
|
elif arg == "kanto":
|
|
|
|
print_columns(db.get_kanto())
|
|
|
|
elif arg == "johto":
|
|
|
|
print_columns(db.get_johto())
|
|
|
|
elif arg == "hoenn":
|
|
|
|
print_columns(db.get_hoenn())
|
|
|
|
elif arg == "sinnoh":
|
|
|
|
print_columns(db.get_sinnoh())
|
2017-04-29 05:57:47 +00:00
|
|
|
elif arg == "all":
|
2017-04-28 07:46:39 +00:00
|
|
|
print_columns(db.get_all())
|
2017-06-24 05:08:57 +00:00
|
|
|
elif arg in ("clear", "disable", "off"):
|
2017-06-11 19:30:23 +00:00
|
|
|
scripter.clear_terminal()
|
2017-06-29 19:36:16 +00:00
|
|
|
elif arg == "random" and escape_code:
|
2017-04-29 06:20:17 +00:00
|
|
|
change_wallpaper(db, db.get_random().get_name())
|
2017-06-29 19:36:16 +00:00
|
|
|
elif arg == "random-kanto" and escape_code:
|
2017-06-07 09:03:52 +00:00
|
|
|
change_wallpaper(db, db.get_random_from_region("kanto").get_name())
|
2017-06-29 19:36:16 +00:00
|
|
|
elif arg == "random-johto" and escape_code:
|
2017-06-07 09:03:52 +00:00
|
|
|
change_wallpaper(db, db.get_random_from_region("johto").get_name())
|
2017-06-29 19:36:16 +00:00
|
|
|
elif arg == "random-hoenn" and escape_code:
|
2017-06-07 09:03:52 +00:00
|
|
|
change_wallpaper(db, db.get_random_from_region("hoenn").get_name())
|
2017-06-29 19:36:16 +00:00
|
|
|
elif arg == "random-sinnoh" and escape_code:
|
2017-06-07 09:03:52 +00:00
|
|
|
change_wallpaper(db, db.get_random_from_region("sinnoh").get_name())
|
2017-04-29 05:57:47 +00:00
|
|
|
elif arg == "random":
|
2017-04-28 22:26:00 +00:00
|
|
|
change_terminal_background(db, db.get_random().get_name())
|
2017-06-07 09:03:52 +00:00
|
|
|
elif arg == "random-kanto":
|
|
|
|
change_terminal_background(db, db.get_random_from_region("kanto").get_name())
|
|
|
|
elif arg == "random-johto":
|
|
|
|
change_terminal_background(db, db.get_random_from_region("johto").get_name())
|
|
|
|
elif arg == "random-hoenn":
|
|
|
|
change_terminal_background(db, db.get_random_from_region("hoenn").get_name())
|
|
|
|
elif arg == "random-sinnoh":
|
|
|
|
change_terminal_background(db, db.get_random_from_region("sinnoh").get_name())
|
2017-06-29 19:36:16 +00:00
|
|
|
elif arg == "light" and escape_code:
|
2017-06-25 18:12:45 +00:00
|
|
|
change_wallpaper(db, db.get_light().get_name())
|
2017-06-29 19:36:16 +00:00
|
|
|
elif arg == "dark" and escape_code:
|
2017-06-25 18:12:45 +00:00
|
|
|
change_wallpaper(db, db.get_dark().get_name())
|
2017-06-25 02:51:50 +00:00
|
|
|
elif arg == "light":
|
2017-06-25 20:07:45 +00:00
|
|
|
change_terminal_background(db, db.get_light())
|
2017-06-25 02:51:50 +00:00
|
|
|
elif arg == "dark":
|
2017-06-25 20:07:45 +00:00
|
|
|
change_terminal_background(db, db.get_dark())
|
2017-06-29 18:17:16 +00:00
|
|
|
elif arg in ("type", "types"):
|
|
|
|
print_types(db)
|
2017-04-28 23:17:44 +00:00
|
|
|
elif arg == "slideshow":
|
|
|
|
slideshow(db, 1, 494)
|
|
|
|
elif arg == "slideshow-kanto":
|
|
|
|
slideshow(db, 1, 152)
|
|
|
|
elif arg == "slideshow-johto":
|
|
|
|
slideshow(db, 152, 252)
|
|
|
|
elif arg == "slideshow-hoenn":
|
|
|
|
slideshow(db, 252, 387)
|
|
|
|
elif arg == "slideshow-sinnoh":
|
|
|
|
slideshow(db, 387, 494)
|
2017-06-24 04:58:03 +00:00
|
|
|
elif arg.endswith("slideshow"):
|
|
|
|
slideshow(db, 1, 494, rand=arg.startswith("rnd"))
|
|
|
|
elif arg.endswith("slideshow-kanto"):
|
|
|
|
slideshow(db, 1, 152, rand=arg.startswith("rnd"))
|
|
|
|
elif arg.endswith("slideshow-johto"):
|
|
|
|
slideshow(db, 152, 252, rand=arg.startswith("rnd"))
|
|
|
|
elif arg.endswith("slideshow-hoenn"):
|
|
|
|
slideshow(db, 252, 387, rand=arg.startswith("rnd"))
|
|
|
|
elif arg.endswith("slideshow-sinnoh"):
|
|
|
|
slideshow(db, 387, 494, rand=arg.startswith("rnd"))
|
2017-04-29 05:57:47 +00:00
|
|
|
elif arg == "?":
|
2017-06-18 04:07:33 +00:00
|
|
|
print("This function is deprecated.")
|
2017-06-29 19:36:16 +00:00
|
|
|
elif escape_code:
|
2017-04-29 06:20:17 +00:00
|
|
|
change_wallpaper(db, arg)
|
2017-04-28 19:51:42 +00:00
|
|
|
else:
|
2017-04-28 22:26:00 +00:00
|
|
|
change_terminal_background(db, arg)
|
|
|
|
|
2017-04-28 07:46:39 +00:00
|
|
|
|
2017-06-29 07:00:39 +00:00
|
|
|
def main(argv):
|
2017-04-28 07:46:39 +00:00
|
|
|
# Entrance to the program.
|
|
|
|
if len(argv) == 1:
|
2017-06-21 07:00:24 +00:00
|
|
|
print('No command line arguments specified.'
|
|
|
|
'\nTry typing in a Pokemon name or number.'
|
|
|
|
'\nOr type "help" to see all the commands.')
|
2017-06-29 18:17:16 +00:00
|
|
|
sys.exit(1)
|
|
|
|
# If there is an escape code, then change the wallpaper, not the terminal.
|
|
|
|
if str(argv[1]).startswith("_"):
|
|
|
|
ESCAPE_CODE = True
|
2017-06-29 19:36:16 +00:00
|
|
|
argv[1] = argv[1][1:]
|
2017-06-29 18:17:16 +00:00
|
|
|
else:
|
|
|
|
ESCAPE_CODE = False
|
|
|
|
|
|
|
|
if len(argv) == 2:
|
2017-06-29 19:36:16 +00:00
|
|
|
single_argument_handler(argv[1].lower(), ESCAPE_CODE)
|
2017-06-14 04:07:50 +00:00
|
|
|
elif len(argv) == 3:
|
2017-06-29 19:36:16 +00:00
|
|
|
multiple_argument_handler(argv[1].lower(), argv[2], ESCAPE_CODE)
|
2017-04-28 07:46:39 +00:00
|
|
|
else:
|
2017-06-21 07:00:24 +00:00
|
|
|
print('Invalid number of arguments.'
|
2017-06-21 23:26:14 +00:00
|
|
|
'\nType "help" to see all the commands.')
|
2017-06-29 07:00:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
# Entrance to the program.
|
|
|
|
main(sys.argv)
|