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