nicoaspra
commited on
Commit
·
13b4e72
1
Parent(s):
d554b02
update UI: separate line every error/warning
Browse files- gcode_analyzer_ui.py +30 -12
gcode_analyzer_ui.py
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from python_gcode_checker import run_checks
|
| 3 |
from settings_report_details import generate_detailed_report
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
st.title("G-code Programming Assistant (v0.1)")
|
| 7 |
|
| 8 |
st.markdown("""
|
| 9 |
-
Welcome to the G-code Assistant! This tool
|
| 10 |
|
| 11 |
**Note:** This tool is limited to simple carving operations on a CNC milling machine.
|
| 12 |
|
|
@@ -21,25 +38,26 @@ gcode_input = st.text_area("Input G-code", height=300, placeholder="Enter G-code
|
|
| 21 |
|
| 22 |
# Button to analyze G-code
|
| 23 |
if st.button("Analyze G-code"):
|
| 24 |
-
# Run analysis
|
| 25 |
-
errors, warnings =
|
| 26 |
-
config_report = generate_detailed_report(gcode_input)
|
| 27 |
-
|
| 28 |
-
# Display results
|
| 29 |
-
st.subheader("Analysis Results")
|
| 30 |
|
| 31 |
-
# Display
|
|
|
|
| 32 |
if errors:
|
| 33 |
-
|
|
|
|
| 34 |
else:
|
| 35 |
st.success("No errors found.")
|
| 36 |
|
|
|
|
|
|
|
| 37 |
if warnings:
|
| 38 |
-
|
|
|
|
| 39 |
else:
|
| 40 |
st.info("No warnings found.")
|
| 41 |
|
| 42 |
-
# Display
|
| 43 |
st.subheader("Configuration Settings")
|
| 44 |
st.text(config_report)
|
| 45 |
|
|
|
|
| 1 |
+
# app.py
|
| 2 |
+
|
| 3 |
import streamlit as st
|
| 4 |
from python_gcode_checker import run_checks
|
| 5 |
from settings_report_details import generate_detailed_report
|
| 6 |
|
| 7 |
+
def analyze_gcode(gcode, depth_max=0.1):
|
| 8 |
+
errors, warnings = run_checks(gcode, depth_max)
|
| 9 |
+
config_report = generate_detailed_report(gcode)
|
| 10 |
+
|
| 11 |
+
return errors, warnings, config_report
|
| 12 |
+
|
| 13 |
+
def format_issues(issues):
|
| 14 |
+
formatted = []
|
| 15 |
+
for line_num, message in issues:
|
| 16 |
+
if line_num > 0:
|
| 17 |
+
formatted.append(f"Line {line_num}: {message}")
|
| 18 |
+
else:
|
| 19 |
+
formatted.append(message) # No "Line 0" for general warnings/errors
|
| 20 |
+
return formatted
|
| 21 |
+
|
| 22 |
+
# Streamlit UI
|
| 23 |
st.title("G-code Programming Assistant (v0.1)")
|
| 24 |
|
| 25 |
st.markdown("""
|
| 26 |
+
Welcome to the G-code Assistant! This tool helps you verify and analyze your G-code for potential errors and warnings before running it on your machine.
|
| 27 |
|
| 28 |
**Note:** This tool is limited to simple carving operations on a CNC milling machine.
|
| 29 |
|
|
|
|
| 38 |
|
| 39 |
# Button to analyze G-code
|
| 40 |
if st.button("Analyze G-code"):
|
| 41 |
+
# Run analysis
|
| 42 |
+
errors, warnings, config_report = analyze_gcode(gcode_input, depth_max)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
+
# Display Errors with count in the subheader
|
| 45 |
+
st.subheader(f"Errors ({len(errors)})")
|
| 46 |
if errors:
|
| 47 |
+
for message in format_issues(errors):
|
| 48 |
+
st.error(message)
|
| 49 |
else:
|
| 50 |
st.success("No errors found.")
|
| 51 |
|
| 52 |
+
# Display Warnings with count in the subheader
|
| 53 |
+
st.subheader(f"Warnings ({len(warnings)})")
|
| 54 |
if warnings:
|
| 55 |
+
for message in format_issues(warnings):
|
| 56 |
+
st.warning(message)
|
| 57 |
else:
|
| 58 |
st.info("No warnings found.")
|
| 59 |
|
| 60 |
+
# Display Configuration Settings
|
| 61 |
st.subheader("Configuration Settings")
|
| 62 |
st.text(config_report)
|
| 63 |
|