Code refactor and make config assertions more verbose on fail

This commit is contained in:
Peder Bergebakken Sundt 2018-03-01 13:56:31 +01:00
parent eb6f3cf9db
commit 6bd24cdd3e
2 changed files with 11 additions and 11 deletions

14
gui.py
View File

@ -9,6 +9,7 @@ import api
#globals:
COLOR_BLUE = "rgb(33, 150, 243)"
COLOR_BLUE_SHADOW = "rgba(33, 150, 243, 0.75)"
WIDTH = 512
class MyApp(App):
def __init__(self, *args):
@ -16,12 +17,11 @@ class MyApp(App):
super(MyApp, self).__init__(*args, static_file_path=res_path)
def main(self):
container = gui.VBox(width=512)
container.style["margin-left"] = "auto"
container.style["margin-right"] = "auto"
container = gui.VBox(width=WIDTH)
container.style.update({"margin-left": "auto", "margin-right":"auto"})
#logo:
container.append(gui.Image('/res/logo.jpg', width=512))
container.append(gui.Image('/res/logo.png', width=WIDTH))
#playback controls
self.playback = Namespace()
@ -38,8 +38,8 @@ class MyApp(App):
self.playback.volume_label = gui.Label("Volume:")
self.playback.volume_label.style["font-size"] = "0.8em"
self.playback.volume_slider = gui.Slider(100, 0, 100, 1, width="150px")
self.playback.volume_slider.style["margin-left"] = "20px"
self.playback.volume_slider.style["margin-bottom"] = "13px"
self.playback.volume_slider \
.style.update({"margin-left": "20px", "margin-bottom":"13px"})
self.playback.volume_slider.set_oninput_listener(self.change_volume)
self.playback.seek_slider = gui.Slider(0, 0, 100, 1, width="85%", height=20, margin='10px')
@ -67,7 +67,7 @@ class MyApp(App):
#input
container.append(gui.Label("Add songs:"))
inputContainer = gui.HBox(width=512)
inputContainer = gui.HBox(width=WIDTH)
self.input = Namespace()
self.input.field = gui.TextInput(single_line=True, height="20px", margin="5px")
self.input.field.style["border"] = "1px solid %s" % COLOR_BLUE

View File

@ -10,10 +10,10 @@ import gui
# config.start_browser: bool
# config.multiple_instance: bool
def main(config):
assert hasattr(config, "host")
assert hasattr(config, "port")
assert hasattr(config, "start_browser")
assert hasattr(config, "multiple_instance")
assert hasattr(config, "host"), "Config has no attr 'host'!"
assert hasattr(config, "port"), "Config has no attr 'port'!"
assert hasattr(config, "start_browser"), "Config has no attr 'start_browser'!"
assert hasattr(config, "multiple_instance"), "Config has no attr 'multiple_instance'!"
# start the webserver:
api.BASE_URL = config.api_base