MichaelRKessler Claude Fable 5 commited on
Commit
8cc1ac6
·
1 Parent(s): 442e7e5

Polish G-Code Visualization and download UI

Browse files

- Fix intermittent bug where the Upload G-Code box stayed hidden after
certain source switches: toggle the box client-side instead of via a
racy server visibility update.
- Make all three G-code download boxes download-only (Shape 2 and 3 were
accidentally upload-enabled).
- Keep the download boxes the same compact height before and after
Generate by shrinking the empty-state placeholder.
- Reword the "all moves G1" toggle in plain language with a G0/G1
explanation in helper text.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +43 -15
app.py CHANGED
@@ -149,6 +149,25 @@ APP_CSS = """
149
  .gcode-view .cm-scroller {
150
  overflow: auto;
151
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
152
  """
153
 
154
  # Gradio 6.10's gr.Model3D leaves the Undo (reset view) button permanently
@@ -1043,10 +1062,6 @@ GCODE_SOURCE_SHAPE3 = "Use Shape 3 G-Code"
1043
  GCODE_SOURCE_UPLOAD = "Upload G-Code file"
1044
 
1045
 
1046
- def toggle_gcode_source(source: str) -> dict[str, Any]:
1047
- return gr.update(visible=(source == GCODE_SOURCE_UPLOAD))
1048
-
1049
-
1050
  def render_toolpath(
1051
  source: str,
1052
  uploaded_path: str | None,
@@ -1625,15 +1640,21 @@ def build_demo() -> gr.Blocks:
1625
  value=True,
1626
  )
1627
  gcode_all_g1 = gr.Checkbox(
1628
- label="Use G1 for all moves (no G0 travel commands) — applies to all shapes",
 
 
 
 
 
 
1629
  value=True,
1630
  )
1631
  gcode_button = gr.Button("Generate G-Code", variant="primary")
1632
 
1633
  with gr.Row():
1634
- gcode_file_1 = gr.File(label="Download G-Code Shape 1", interactive=False)
1635
- gcode_file_2 = gr.File(label="Download G-Code Shape 2")
1636
- gcode_file_3 = gr.File(label="Download G-Code Shape 3")
1637
 
1638
  # Per-shape G-code preview, aligned under each download box. Fixed
1639
  # height with internal scrolling so the files don't fill the page.
@@ -1730,10 +1751,11 @@ def build_demo() -> gr.Blocks:
1730
  value=GCODE_SOURCE_SHAPE1,
1731
  label="G-Code source",
1732
  )
1733
- # Visibility is toggled on this wrapper column rather than the
1734
- # File itself: a File that is the output of the toggle event
1735
- # gets stuck showing a progress overlay when first revealed.
1736
- with gr.Column(visible=False) as upload_col:
 
1737
  gcode_upload = gr.File(
1738
  label="Upload G-Code",
1739
  file_types=[".txt", ".gcode", ".nc"],
@@ -1815,10 +1837,16 @@ def build_demo() -> gr.Blocks:
1815
  render_mode = gr.State("tube")
1816
 
1817
  gcode_source.change(
1818
- fn=toggle_gcode_source,
1819
  inputs=[gcode_source],
1820
- outputs=[upload_col],
1821
- queue=False,
 
 
 
 
 
 
1822
  )
1823
  render_inputs = [gcode_source, gcode_upload, gcode_file_1, gcode_file_2, gcode_file_3, travel_opacity_slider, print_opacity_slider, travel_color_picker, print_color_picker, print_width_slider, travel_width_slider]
1824
  render_line_button.click(
 
149
  .gcode-view .cm-scroller {
150
  overflow: auto;
151
  }
152
+
153
+ /* Shrink the empty-state placeholder of the G-code download boxes so they are
154
+ the same compact height before and after Generate G-Code is pressed. */
155
+ .gcode-download .empty {
156
+ min-height: 0 !important;
157
+ height: 35px !important;
158
+ padding: 0 !important;
159
+ overflow: hidden !important;
160
+ }
161
+ .gcode-download .empty svg {
162
+ width: 22px !important;
163
+ height: 22px !important;
164
+ }
165
+
166
+ /* The G-code upload box starts hidden; it is shown client-side only when
167
+ "Upload G-Code file" is selected (see gcode_source.change). */
168
+ #gcode-upload-col {
169
+ display: none;
170
+ }
171
  """
172
 
173
  # Gradio 6.10's gr.Model3D leaves the Undo (reset view) button permanently
 
1062
  GCODE_SOURCE_UPLOAD = "Upload G-Code file"
1063
 
1064
 
 
 
 
 
1065
  def render_toolpath(
1066
  source: str,
1067
  uploaded_path: str | None,
 
1640
  value=True,
1641
  )
1642
  gcode_all_g1 = gr.Checkbox(
1643
+ label="Move at one constant speed (no fast travel moves)",
1644
+ info=(
1645
+ "Every move — including repositioning between deposits — uses the "
1646
+ "slower printing-speed command (G1) instead of a rapid travel command "
1647
+ "(G0). The valve still controls where material is actually dispensed. "
1648
+ "Applies to all shapes."
1649
+ ),
1650
  value=True,
1651
  )
1652
  gcode_button = gr.Button("Generate G-Code", variant="primary")
1653
 
1654
  with gr.Row():
1655
+ gcode_file_1 = gr.File(label="Download G-Code Shape 1", interactive=False, elem_classes=["gcode-download"])
1656
+ gcode_file_2 = gr.File(label="Download G-Code Shape 2", interactive=False, elem_classes=["gcode-download"])
1657
+ gcode_file_3 = gr.File(label="Download G-Code Shape 3", interactive=False, elem_classes=["gcode-download"])
1658
 
1659
  # Per-shape G-code preview, aligned under each download box. Fixed
1660
  # height with internal scrolling so the files don't fill the page.
 
1751
  value=GCODE_SOURCE_SHAPE1,
1752
  label="G-Code source",
1753
  )
1754
+ # Shown only when "Upload G-Code file" is selected. Visibility is
1755
+ # toggled client-side (see gcode_source.change below) instead of
1756
+ # via a server round-trip, which raced and intermittently left
1757
+ # the box hidden. Hidden initially by CSS (#gcode-upload-col).
1758
+ with gr.Column(elem_id="gcode-upload-col") as upload_col:
1759
  gcode_upload = gr.File(
1760
  label="Upload G-Code",
1761
  file_types=[".txt", ".gcode", ".nc"],
 
1837
  render_mode = gr.State("tube")
1838
 
1839
  gcode_source.change(
1840
+ fn=None,
1841
  inputs=[gcode_source],
1842
+ outputs=[],
1843
+ js="""(src) => {
1844
+ const col = document.getElementById('gcode-upload-col');
1845
+ if (col) col.style.display = (src === '"""
1846
+ + GCODE_SOURCE_UPLOAD
1847
+ + """') ? 'flex' : 'none';
1848
+ return [];
1849
+ }""",
1850
  )
1851
  render_inputs = [gcode_source, gcode_upload, gcode_file_1, gcode_file_2, gcode_file_3, travel_opacity_slider, print_opacity_slider, travel_color_picker, print_color_picker, print_width_slider, travel_width_slider]
1852
  render_line_button.click(