-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathweb_ui.py
More file actions
56 lines (48 loc) · 2.31 KB
/
web_ui.py
File metadata and controls
56 lines (48 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from flask import Flask, redirect, url_for
from flask import render_template
from flask import request
from stations_service import StationsServiceFactory
from bluetooth_service import BluetoothServiceFactory
class WebUi:
def __init__(self, mpc, host, port, showBluetoothControls, showVolumeControls):
self.darkMode = False
self.stationsService = StationsServiceFactory.getService()
app = Flask(__name__, template_folder="template")
@app.route("/enable-light-mode")
def enable_light_mode():
self.darkMode = False
return redirect(url_for('control_page'))
@app.route("/enable-dark-mode")
def enable_dark_mode():
self.darkMode = True
return redirect(url_for('control_page'))
@app.route("/", methods=["GET", "POST"])
def control_page(title="Radio control"):
if request.method == "POST":
if request.form["action"] == "play":
self.stationsService.currentStationIndex = int(request.form["stationIndex"])
currentStation = self.stationsService.getCurrentStation()
if currentStation is not None:
mpc.play(currentStation.get('url'))
elif request.form["action"] == "stop":
mpc.stop()
elif request.form["action"] == "volume_decrease":
mpc.volumeDecrease()
elif request.form["action"] == "volume_increase":
mpc.volumeIncrease()
elif request.form["action"] == "volume_decrease_fast":
mpc.volumeDecreaseFast()
elif request.form["action"] == "volume_increase_fast":
mpc.volumeIncreaseFast()
elif request.form["action"] == "pair_bt":
BluetoothServiceFactory.getService().pair()
return render_template(
"/control.html",
title=title,
stations=self.stationsService.getStations(),
currentStationIndex=self.stationsService.currentStationIndex,
showBluetoothControls=showBluetoothControls,
showVolumeControls=showVolumeControls,
darkMode=self.darkMode
)
app.run(host=host, port=port)