Updating printer configuration on printer_ready in case anything has changed.

This commit is contained in:
Jordan Ruthe
2020-11-03 21:35:26 -05:00
parent bbf730de5a
commit cdab7cba37
8 changed files with 47 additions and 29 deletions

View File

@@ -163,7 +163,8 @@ class MoonrakerApi:
)
def get_file_list(self, callback=None, *args):
logger.debug("Sending server.files.list")
#Commenting this log for being too noisy
#logger.debug("Sending server.files.list")
self._ws.send_method(
"server.files.list",
{},

View File

@@ -123,10 +123,6 @@ class JobStatusPanel(ScreenPanel):
self._screen._ws.klippy.print_cancel(self._response_callback, "enable_button", "pause", "cancel")
def emergency_stop(self, widget):
self._screen._ws.klippy.emergency_stop()
def _response_callback(self, response, method, params, func, *args):
if func == "enable_button":
self.enable_button(*args)

View File

@@ -97,9 +97,6 @@ class MovePanel(ScreenPanel):
self.panel = grid
self._screen.add_subscription(panel_name)
def home(self, widget):
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
def process_update(self, data):
if "toolhead" in data and "position" in data["toolhead"]:
self.labels['pos_x'].set_text("X: %.2f" % (data["toolhead"]["position"][0]))

View File

@@ -17,10 +17,16 @@ class ScreenPanel:
# Create gtk items here
return
def emergency_stop(self, widget):
self._screen._ws.klippy.emergency_stop()
def get(self):
# Return gtk item
return self.panel
def home(self, widget):
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
def menu_item_clicked(self, widget, panel, item):
print("### Creating panel "+ item['panel'])
if "items" in item:

View File

@@ -17,7 +17,7 @@ class SystemPanel(ScreenPanel):
restart = KlippyGtk.ButtonImage('reboot','Klipper Restart','color1')
restart.connect("clicked", self.restart_klippy)
firmrestart = KlippyGtk.ButtonImage('restart','Firmware Restart','color2')
restart.connect("clicked", self.restart_klippy, "firmware")
firmrestart.connect("clicked", self.restart_klippy, "firmware")
back = KlippyGtk.ButtonImage('back', 'Back')
back.connect("clicked", self._screen._menu_go_back)

View File

@@ -19,12 +19,8 @@ class ZCalibratePanel:
self._screen = screen
def initialize(self, panel_name):
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
self._screen._ws.klippy.gcode_script(KlippyGcodes.PROBE_CALIBRATE)
grid = KlippyGtk.HomogeneousGrid()
label = Gtk.Label("Z Offset: ")
label.get_style_context().add_class('temperature_entry')
self.labels['zpos'] = Gtk.Label("Homing")
@@ -39,10 +35,6 @@ class ZCalibratePanel:
zneg = KlippyGtk.ButtonImage('z-offset-increase',"Lower Nozzle")
zneg.connect("clicked", self.move, "-")
distgrid = Gtk.Grid()
j = 0;
for i in self.distances:
@@ -67,10 +59,6 @@ class ZCalibratePanel:
space_grid.attach(distgrid,0,1,1,1)
space_grid.attach(Gtk.Label(" "),0,2,1,1)
complete = KlippyGtk.ButtonImage('complete','Accept','color2')
complete.connect("clicked", self.accept)
@@ -90,10 +78,9 @@ class ZCalibratePanel:
self.grid = grid
self._screen.add_subscription(panel_name)
def get(self):
# Return gtk item
return self.grid
def activate(self):
self._screen._ws.klippy.gcode_script(KlippyGcodes.HOME)
self._screen._ws.klippy.gcode_script(KlippyGcodes.PROBE_CALIBRATE)
def process_update(self, data):
if "toolhead" in data and "position" in data['toolhead']:

View File

@@ -33,8 +33,6 @@ class Printer:
"target": 0
}
print (self.devices)
print (self.tools)
logging.info("### Toolcount: " + str(self.toolcount) + " Heaters: " + str(self.extrudercount))
def process_update(self, data):
@@ -44,6 +42,14 @@ class Printer:
for y in data[x]:
self.data[x][y] = data[x][y]
def get_config_section_list(self):
return list(self.config)
def get_config_section(self, section):
if section not in self.config:
return False
return self.config[section]
def get_stat(self, stat, substat = None):
if substat != None:
return self.data[stat][substat]

View File

@@ -104,8 +104,7 @@ class KlipperScreen(Gtk.Window):
if not hasattr(self, "_ws"):
self.create_websocket()
if (info['result']['klippy_state'] == "ready" and "state_message" in info['result'] and
"M112" in info['result']['state_message']):
if info['result']['klippy_state'] == "error":
logger.warning("Printer is emergency stopped")
self.printer_initializing("Shutdown due to Emergency Stop")
@@ -138,6 +137,7 @@ class KlipperScreen(Gtk.Window):
self.last_update[x] = data[x]
self.printer_config = data['configfile']['config']
#logger.debug("Printer config: %s" % json.dumps(self.printer_config, indent=2))
self.printer = Printer(data)
# Initialize target values. TODO: methodize this
@@ -207,6 +207,9 @@ class KlipperScreen(Gtk.Window):
if hasattr(self.panels[panel_name],"process_update"):
self.panels[panel_name].process_update(self.last_update)
if hasattr(self.panels[panel_name],"activate"):
self.panels[panel_name].activate()
self.add(self.panels[panel_name].get())
self.show_all()
self._cur_panels.append(panel_name)
@@ -370,6 +373,28 @@ class KlipperScreen(Gtk.Window):
def printer_ready(self):
self.shutdown = False
status_objects = [
'idle_timeout',
'configfile',
'toolhead',
'virtual_sdcard',
'print_stats',
'heater_bed',
'extruder',
'pause_resume'
]
r = requests.get("http://127.0.0.1:7125/printer/objects/query?" + "&".join(status_objects))
#TODO: Check that we get good data
data = json.loads(r.content)
self.printer_config = data['result']['status']['configfile']['config']
logger.debug("Printer config: %s" % json.dumps(self.printer_config, indent=2))
self.printer = Printer(data['result']['status'])
logger.debug("Config sections: %s", self.printer.get_config_section_list())
logger.debug("Bed_screws: %s", self.printer.get_config_section("bed_screws"))
self.show_panel('main_panel', "MainPanel", 2, items=self._config['mainmenu'], extrudercount=self.printer.get_extruder_count())
def printer_printing(self):