maj
This commit is contained in:
@@ -69,41 +69,48 @@ def getGcode():
|
|||||||
|
|
||||||
return render_template("form.html")
|
return render_template("form.html")
|
||||||
|
|
||||||
|
|
||||||
@app.route("/text", methods=["POST", "GET"])
|
@app.route("/text", methods=["POST", "GET"])
|
||||||
def getText():
|
def getText():
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
txt = request.form["txt"].strip()
|
txt = request.form["txt"].strip() # Récupère le texte de la textarea
|
||||||
print(txt)
|
print(txt)
|
||||||
if txt:
|
if txt:
|
||||||
formatted_text = ""
|
# Conserver les retours à la ligne dans le texte saisi
|
||||||
|
formatted_text = ""
|
||||||
|
for line in txt.splitlines():
|
||||||
|
words = line.split()
|
||||||
current_line = ""
|
current_line = ""
|
||||||
for word in txt.split():
|
for word in words:
|
||||||
if len(current_line) + len(word) + 1 > 20:
|
if len(current_line) + len(word) + 1 > 20: # Limite de caractères par ligne
|
||||||
formatted_text += current_line.strip() + "\n"
|
formatted_text = formatted_text + current_line.strip() + "\n"
|
||||||
current_line = word + " "
|
current_line = word + " "
|
||||||
else:
|
else:
|
||||||
current_line += word + " " # Ajoute le mot à la ligne actuelle
|
current_line = current_line + word + " "
|
||||||
|
if current_line.strip(): # Ajoute la dernière ligne
|
||||||
|
formatted_text = formatted_text + current_line.strip() + "\n"
|
||||||
|
|
||||||
# Ajoute la dernière ligne si elle n'est pas vide
|
print("Formatted text with line breaks:")
|
||||||
if current_line.strip():
|
print(formatted_text)
|
||||||
formatted_text += current_line.strip()
|
|
||||||
|
|
||||||
print("Formatted text with line breaks:")
|
# Générez le G-code à partir du texte formaté
|
||||||
print(formatted_text)
|
gcode_output = convert_text(formatted_text)
|
||||||
|
print("G-code generated:")
|
||||||
|
print(gcode_output)
|
||||||
|
|
||||||
gcode_output = convert_text(formatted_text)
|
# Sauvegardez le fichier G-code
|
||||||
print("G-code generated:")
|
gcode_filename = "retourligne.gcode"
|
||||||
print(gcode_output)
|
with open(gcode_filename, "w") as gcode_file:
|
||||||
|
gcode_file.write(gcode_output)
|
||||||
|
|
||||||
gcode_filename = "retourligne.gcode"
|
print(f"G-code saved to {gcode_filename}")
|
||||||
with open(gcode_filename, "w") as gcode_file:
|
else:
|
||||||
gcode_file.write(gcode_output)
|
print('empty text')
|
||||||
|
|
||||||
print(f"G-code saved to {gcode_filename}")
|
|
||||||
|
|
||||||
else:
|
|
||||||
print('empty text')
|
|
||||||
return render_template("form.html")
|
return render_template("form.html")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user