Update to local copy that supports animations
Also some lint fixes, but not all because this is a big enough change.
This commit is contained in:
parent
603fad46f9
commit
1e88c125f9
16 changed files with 179 additions and 99 deletions
129
config.py
129
config.py
|
@ -6,10 +6,7 @@ import yaml
|
|||
class Config:
|
||||
def __init__(self):
|
||||
# Load initial config file
|
||||
if len(sys.argv) > 1:
|
||||
config_file = sys.argv[1]
|
||||
else:
|
||||
config_file = os.path.join(os.path.dirname(__file__), "ptv.yaml")
|
||||
config_file = sys.argv[1] if len(sys.argv) > 1 else os.path.join(os.path.dirname(__file__), "ptv.yaml")
|
||||
self.load_config(config_file)
|
||||
|
||||
# Load the profile explicitly at the end of initiailization so that
|
||||
|
@ -17,7 +14,7 @@ class Config:
|
|||
self.load_config(os.path.join(self.profile, "profile.yaml"))
|
||||
|
||||
def load_config(self, filename):
|
||||
with open(filename, "r") as infile:
|
||||
with open(filename, encoding="utf-8") as infile:
|
||||
self._image_closed = None
|
||||
self._image_open = None
|
||||
self._image_blink_closed = None
|
||||
|
@ -75,20 +72,25 @@ class Config:
|
|||
@image_closed.setter
|
||||
def image_closed(self, filename):
|
||||
# Check filename is a string
|
||||
if not isinstance(filename, str):
|
||||
print("Config parameter image_closed must be a valid filename")
|
||||
if not isinstance(filename, str) and not isinstance(filename, list):
|
||||
print("Config parameter image_closed must be a valid filename or list")
|
||||
|
||||
# Look for the file in profile dir, script dir, and working dir
|
||||
targets = [os.path.join(self.profile, filename), os.path.join(os.path.dirname(__file__), filename), filename]
|
||||
if not isinstance(filename, list):
|
||||
filename = [filename]
|
||||
|
||||
for target in targets:
|
||||
if os.path.exists(target):
|
||||
self._image_closed = target
|
||||
return
|
||||
self._image_closed = []
|
||||
for i in filename:
|
||||
# Look for the file in profile dir, script dir, and working dir
|
||||
targets = [os.path.join(self.profile, i), os.path.join(os.path.dirname(__file__), i), i]
|
||||
|
||||
# Can't find the image, fail
|
||||
print(f"Cannot find file {filename}")
|
||||
sys.exit(1)
|
||||
for target in targets:
|
||||
if os.path.exists(target):
|
||||
self._image_closed.append(target)
|
||||
break
|
||||
else:
|
||||
# Can't find the image, fail
|
||||
print(f"Cannot find file {i}")
|
||||
sys.exit(1)
|
||||
|
||||
@property
|
||||
def image_open(self):
|
||||
|
@ -100,20 +102,25 @@ class Config:
|
|||
@image_open.setter
|
||||
def image_open(self, filename):
|
||||
# Check filename is a string
|
||||
if not isinstance(filename, str):
|
||||
print("Config parameter image_open must be a valid filename")
|
||||
if not isinstance(filename, str) and not isinstance(filename, list):
|
||||
print("Config parameter image_open must be a valid filename or list")
|
||||
|
||||
# Look for the file in profile dir, script dir, and working dir
|
||||
targets = [os.path.join(self.profile, filename), os.path.join(os.path.dirname(__file__), filename), filename]
|
||||
if not isinstance(filename, list):
|
||||
filename = [filename]
|
||||
|
||||
for target in targets:
|
||||
if os.path.exists(target):
|
||||
self._image_open = target
|
||||
return
|
||||
self._image_open = []
|
||||
for i in filename:
|
||||
# Look for the file in profile dir, script dir, and working dir
|
||||
targets = [os.path.join(self.profile, i), os.path.join(os.path.dirname(__file__), i), i]
|
||||
|
||||
# Can't find the image, fail
|
||||
print(f"Cannot find file {filename}")
|
||||
sys.exit(1)
|
||||
for target in targets:
|
||||
if os.path.exists(target):
|
||||
self._image_open.append(target)
|
||||
break
|
||||
else:
|
||||
# Can't find the image, fail
|
||||
print(f"Cannot find file {i}")
|
||||
sys.exit(1)
|
||||
|
||||
@property
|
||||
def image_blink_open(self):
|
||||
|
@ -125,20 +132,25 @@ class Config:
|
|||
@image_blink_open.setter
|
||||
def image_blink_open(self, filename):
|
||||
# Check filename is a string
|
||||
if not isinstance(filename, str):
|
||||
print("Config parameter image_blink_open must be a valid filename")
|
||||
if not isinstance(filename, str) and not isinstance(filename, list):
|
||||
print("Config parameter image_blink_open must be a valid filename or list")
|
||||
|
||||
# Look for the file in profile dir, script dir, and working dir
|
||||
targets = [os.path.join(self.profile, filename), os.path.join(os.path.dirname(__file__), filename), filename]
|
||||
if not isinstance(filename, list):
|
||||
filename = [filename]
|
||||
|
||||
for target in targets:
|
||||
if os.path.exists(target):
|
||||
self._image_blink_open = target
|
||||
return
|
||||
self._image_blink_open = []
|
||||
for i in filename:
|
||||
# Look for the file in profile dir, script dir, and working dir
|
||||
targets = [os.path.join(self.profile, i), os.path.join(os.path.dirname(__file__), i), i]
|
||||
|
||||
# Can't find the image, fail
|
||||
print(f"Cannot find file {filename}")
|
||||
sys.exit(1)
|
||||
for target in targets:
|
||||
if os.path.exists(target):
|
||||
self._image_blink_open.append(target)
|
||||
break
|
||||
else:
|
||||
# Can't find the image, fail
|
||||
print(f"Cannot find file {i}")
|
||||
sys.exit(1)
|
||||
|
||||
@property
|
||||
def image_blink_closed(self):
|
||||
|
@ -150,20 +162,25 @@ class Config:
|
|||
@image_blink_closed.setter
|
||||
def image_blink_closed(self, filename):
|
||||
# Check filename is a string
|
||||
if not isinstance(filename, str):
|
||||
print("Config parameter image_blink_closed must be a valid filename")
|
||||
if not isinstance(filename, str) and not isinstance(filename, list):
|
||||
print("Config parameter image_blink_closed must be a valid filename or list")
|
||||
|
||||
# Look for the file in profile dir, script dir, and working dir
|
||||
targets = [os.path.join(self.profile, filename), os.path.join(os.path.dirname(__file__), filename), filename]
|
||||
if not isinstance(filename, list):
|
||||
filename = [filename]
|
||||
|
||||
for target in targets:
|
||||
if os.path.exists(target):
|
||||
self._image_blink_closed = target
|
||||
return
|
||||
self._image_blink_closed = []
|
||||
for i in filename:
|
||||
# Look for the file in profile dir, script dir, and working dir
|
||||
targets = [os.path.join(self.profile, i), os.path.join(os.path.dirname(__file__), i), i]
|
||||
|
||||
# Can't find the image, fail
|
||||
print(f"Cannot find file {filename}")
|
||||
sys.exit(1)
|
||||
for target in targets:
|
||||
if os.path.exists(target):
|
||||
self._image_blink_closed.append(target)
|
||||
break
|
||||
else:
|
||||
# Can't find the image, fail
|
||||
print(f"Cannot find file {i}")
|
||||
sys.exit(1)
|
||||
|
||||
@property
|
||||
def bg_color(self):
|
||||
|
@ -304,3 +321,17 @@ class Config:
|
|||
print("Config parameter shake_intensity must be an integer")
|
||||
sys.exit(1)
|
||||
self._shake_intensity = intensity
|
||||
|
||||
@property
|
||||
def animation_delay(self):
|
||||
try:
|
||||
return self._animation_delay
|
||||
except AttributeError:
|
||||
return 10
|
||||
|
||||
@animation_delay.setter
|
||||
def animation_delay(self, delay):
|
||||
if not isinstance(delay, int):
|
||||
print("Config paramter animation_delay must be an integer")
|
||||
sys.exit(1)
|
||||
self._animation_delay = delay
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue