Skip to content

Commit

Permalink
webgui fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Dodoooh committed Dec 15, 2024
1 parent bb0388c commit 263d1b1
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from flask import Flask, request, render_template, jsonify
from flask import Flask, request, render_template, jsonify, redirect, url_for
from PIL import Image, ImageDraw, ImageFont
from html.parser import HTMLParser
from brother_ql.raster import BrotherQLRaster
Expand Down Expand Up @@ -60,16 +60,39 @@ def handle_data(self, data):
def handle_endtag(self, tag):
pass

@app.route("/")
def index():
"""
Renders the main page of the Web-GUI.
"""
return render_template("index.html", settings=settings)

@app.route("/settings", methods=["GET"])
def get_settings():
"""
Returns current settings in JSON format.
"""
return jsonify(settings)

@app.route("/update_settings", methods=["POST"])
def update_settings():
"""
Updates settings from the Web-GUI form and saves them.
"""
global settings
settings.update(request.json)
for key in DEFAULT_SETTINGS.keys():
if key in request.form:
value = request.form[key]
if isinstance(DEFAULT_SETTINGS[key], bool):
settings[key] = value.lower() == "true"
elif isinstance(DEFAULT_SETTINGS[key], int):
settings[key] = int(value)
elif isinstance(DEFAULT_SETTINGS[key], float):
settings[key] = float(value)
else:
settings[key] = value
save_settings(settings)
return jsonify({"success": True, "message": "Einstellungen gespeichert."})
return redirect(url_for("index"))

@app.route("/api/text/", methods=["POST"])
def api_text():
Expand Down

0 comments on commit 263d1b1

Please # to comment.