Skip to content

Commit

Permalink
Fix file_browser when virtual_sdcard is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
Franklyn Tackitt committed Oct 14, 2024
1 parent 888e3c4 commit 3c79033
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion klippy/extras/display/menu.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ gcode:
### menu virtual sdcard, using new file_browser ###
[menu __main __sdcard]
type: file_browser
enable: {('virtual_sdcard' in printer) and (not printer.virtual_sdcard.file_path)}
enable: {('virtual_sdcard' in printer) and (printer.print_stats.state not in ("printing", "paused"))}
name: SD Card

### menu tune ###
Expand Down
11 changes: 10 additions & 1 deletion klippy/extras/display/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,10 @@ def __init__(self, manager, config, **kwargs):
.lower()
)

sdcard = self.manager.printer.lookup_object("virtual_sdcard", None)
if not self.manager.virtual_sdcard:
return

sdcard = self.manager.virtual_sdcard
self.root_dir = pathlib.Path(sdcard.sdcard_dirname)
self.path = self.root_dir

Expand All @@ -826,6 +829,9 @@ def __init__(self, manager, config, **kwargs):
gcode=lambda el, context: el.manager.back(),
)

def is_enabled(self):
return self.manager.virtual_sdcard and super().is_enabled()

def _dir_contains_gcode(self, path):
return any(
file
Expand Down Expand Up @@ -1042,6 +1048,9 @@ def __init__(self, config, display):
)
# load printer objects
self.gcode_macro = self.printer.load_object(config, "gcode_macro")
self.virtual_sdcard = self.printer.load_object(
config, "virtual_sdcard", None
)
# register itself for printer callbacks
self.printer.add_object("menu", self)
self.printer.register_event_handler("klippy:ready", self.handle_ready)
Expand Down
6 changes: 3 additions & 3 deletions test/klippy/menu.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ max_accel: 3000
max_z_velocity: 5
max_z_accel: 100

[virtual_sdcard]
path: gcodes

[board_pins]
aliases:
# Common EXP1 header found on many "all-in-one" ramps clones
Expand All @@ -84,3 +81,6 @@ click_pin: ^!EXP1_2
type: list
name: Main Menu

# Put this last to try and break MenuFileBrowser
[virtual_sdcard]
path: gcodes

0 comments on commit 3c79033

Please sign in to comment.