|
1 | 1 | from __future__ import annotations |
2 | | - |
3 | 2 | import re |
4 | 3 | import typing |
5 | 4 | from functools import partial |
| 5 | +import logging |
6 | 6 |
|
7 | 7 | from helper_methods import normalize |
8 | 8 | from lib.moonrakerComm import MoonWebSocket |
|
18 | 18 | from PyQt6 import QtCore, QtGui, QtWidgets |
19 | 19 |
|
20 | 20 |
|
| 21 | +_logger = logging.getLogger(__name__) |
| 22 | + |
| 23 | + |
21 | 24 | class ControlTab(QtWidgets.QStackedWidget): |
22 | 25 | """Printer Control Stacked Widget""" |
23 | 26 |
|
@@ -252,24 +255,6 @@ def __init__( |
252 | 255 | self.numpadPage.request_back.connect(self.request_back_button) |
253 | 256 | self.addWidget(self.numpadPage) |
254 | 257 |
|
255 | | - self.panel.extruder_temp_display.clicked.connect( |
256 | | - lambda: self.request_numpad[str, int, "PyQt_PyObject", int, int].emit( |
257 | | - "Extruder Temperature", |
258 | | - int(round(float(self.panel.extruder_temp_display.secondary_text))), |
259 | | - self.on_numpad_change, |
260 | | - 0, |
261 | | - 370, # TODO: Get this value from printer objects |
262 | | - ) |
263 | | - ) |
264 | | - self.panel.bed_temp_display.clicked.connect( |
265 | | - lambda: self.request_numpad[str, int, "PyQt_PyObject", int, int].emit( |
266 | | - "Bed Temperature", |
267 | | - int(round(float(self.panel.bed_temp_display.secondary_text))), |
268 | | - self.on_numpad_change, |
269 | | - 0, |
270 | | - 120, # TODO: Get this value from printer objects |
271 | | - ) |
272 | | - ) |
273 | 258 | self.request_numpad[str, int, "PyQt_PyObject", int, int].connect( |
274 | 259 | self.on_numpad_request |
275 | 260 | ) |
@@ -304,6 +289,8 @@ def __init__( |
304 | 289 | self.printer.fan_update[str, str, float].connect(self.on_fan_object_update) |
305 | 290 | self.printer.fan_update[str, str, int].connect(self.on_fan_object_update) |
306 | 291 |
|
| 292 | + self.printer.printer_config.connect(self.on_printer_config) |
| 293 | + |
307 | 294 | def _handle_z_tilt_object_update(self, value, state): |
308 | 295 | if state: |
309 | 296 | self.call_load_panel.emit(False, "") |
@@ -470,6 +457,44 @@ def _handle_gcode_response(self, messages: list): |
470 | 457 | f"Retries: {retries_done}/{retries_total} | Range: {probed_range:.6f} | Tolerance: {tolerance:.6f}", |
471 | 458 | ) |
472 | 459 |
|
| 460 | + @QtCore.pyqtSlot(dict, name="printer_config") |
| 461 | + def on_printer_config(self, config: dict) -> None: |
| 462 | + """Slot that receives the full printer configuration, |
| 463 | +
|
| 464 | + Additionally, this method configures the signal connections |
| 465 | + between controllable heaters and numpad calls |
| 466 | + """ |
| 467 | + try: |
| 468 | + self.panel.extruder_temp_display.clicked.disconnect() |
| 469 | + self.panel.bed_temp_display.clicked.disconnect() |
| 470 | + except Exception: |
| 471 | + _logger.debug("Signals were not connected") |
| 472 | + extruder = config.get("extruder", None) or {} |
| 473 | + bed = config.get("heater_bed", None) or {} |
| 474 | + e_min_temp = extruder.get("min_temp", 0) |
| 475 | + e_max_temp = extruder.get("max_temp", 300) |
| 476 | + b_max_temp = bed.get("max_temp", 100) |
| 477 | + b_min_temp = bed.get("min_temp", 0) |
| 478 | + # Configure numpads |
| 479 | + self.panel.extruder_temp_display.clicked.connect( |
| 480 | + lambda: self.request_numpad[str, int, "PyQt_PyObject", int, int].emit( |
| 481 | + "Extruder Temperature", |
| 482 | + int(round(float(self.panel.extruder_temp_display.secondary_text))), |
| 483 | + self.on_numpad_change, |
| 484 | + int(e_min_temp), |
| 485 | + int(e_max_temp), |
| 486 | + ) |
| 487 | + ) |
| 488 | + self.panel.bed_temp_display.clicked.connect( |
| 489 | + lambda: self.request_numpad[str, int, "PyQt_PyObject", int, int].emit( |
| 490 | + "Bed Temperature", |
| 491 | + int(round(float(self.panel.bed_temp_display.secondary_text))), |
| 492 | + self.on_numpad_change, |
| 493 | + int(b_min_temp), |
| 494 | + int(b_max_temp), |
| 495 | + ) |
| 496 | + ) |
| 497 | + |
473 | 498 | def handle_ztilt(self): |
474 | 499 | """Handle Z-Tilt Adjustment""" |
475 | 500 | self.call_load_panel.emit(True, "Please wait, performing Z-axis calibration.") |
|
0 commit comments