Pokemon-Terminal/pokemonterminal/scripter.py
Samuel Henrique Oliveira da Silva b1c4b2c619 Moves the provider checking logic to run only once
- Importing modules with __ caused strange behavior, rolling back to all imports with  single underscore
2017-11-19 12:36:57 -02:00

59 lines
1.9 KiB
Python

# Used for creating, running and analyzing applescript and bash scripts.
import sys
from pokemonterminal.adapter import identify
from .wallpaper import get_current_adapters
WALLPAPER_PROVIDER = None
def __init_wallpaper_provider():
global WALLPAPER_PROVIDER
if WALLPAPER_PROVIDER is not None:
return
providers = get_current_adapters()
if len(providers) > 1:
# All this if is really not supposed to happen at all whatsoever
# really what kind of person has 2 simultaneous D.E???
print("Multiple providers found select the appropriate one:")
[print(str(x)) for x in providers]
print("If some of these make no sense or are irrelevant please file" +
"an issue in https://github.com/LazoCoder/Pokemon-Terminal")
print("=> ", end='')
inp = None
while inp is None:
try:
inp = int(input())
if inp >= len(providers):
raise ValueError()
except ValueError as _:
print("Invalid number, try again!")
WALLPAPER_PROVIDER = providers[inp]
elif len(providers) <= 0:
print("Your desktop environment isn't supported at this time.")
sys.exit()
else:
WALLPAPER_PROVIDER = providers[0]
def clear_terminal():
adapter = identify()
adapter.clear()
def change_terminal(image_file_path):
if not isinstance(image_file_path, str):
print("A image path must be passed to the change terminal function.")
return
adapter = identify()
if adapter is None:
print("Terminal not supported")
adapter.set_image_file_path(image_file_path)
def change_wallpaper(image_file_path):
if not isinstance(image_file_path, str):
print("A image path must be passed to the change wallpapper function.")
return
__init_wallpaper_provider()
WALLPAPER_PROVIDER.change_wallpaper(image_file_path)