11from __future__ import annotations
2-
32import re
43import typing
54from functools import partial
5+ import logging
66
77from helper_methods import normalize
88from lib .moonrakerComm import MoonWebSocket
1818from PyQt6 import QtCore , QtGui , QtWidgets
1919
2020
21+ _logger = logging .getLogger (__name__ )
22+
23+
2124class ControlTab (QtWidgets .QStackedWidget ):
2225 """Printer Control Stacked Widget"""
2326
@@ -37,6 +40,9 @@ class ControlTab(QtWidgets.QStackedWidget):
3740 disable_popups : typing .ClassVar [QtCore .pyqtSignal ] = QtCore .pyqtSignal (
3841 bool , name = "disable-popups"
3942 )
43+ lock_ui : typing .ClassVar [QtCore .pyqtSignal ] = QtCore .pyqtSignal (
44+ bool , name = "lock-ui"
45+ )
4046 request_numpad : typing .ClassVar [QtCore .pyqtSignal ] = QtCore .pyqtSignal (
4147 [str , int , "PyQt_PyObject" ],
4248 [str , int , "PyQt_PyObject" , int , int ],
@@ -79,6 +85,7 @@ def __init__(
7985 self .probe_helper_page = ProbeHelper (self )
8086 self .probe_helper_page .toggle_conn_page .connect (self .toggle_conn_page )
8187 self .probe_helper_page .disable_popups .connect (self .disable_popups )
88+ self .probe_helper_page .lock_ui .connect (self .lock_ui )
8289 self .addWidget (self .probe_helper_page )
8390 self .probe_helper_page .call_load_panel .connect (self .call_load_panel )
8491 self .printcores_page = SwapPrintcorePage (self )
@@ -252,24 +259,6 @@ def __init__(
252259 self .numpadPage .request_back .connect (self .request_back_button )
253260 self .addWidget (self .numpadPage )
254261
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- )
273262 self .request_numpad [str , int , "PyQt_PyObject" , int , int ].connect (
274263 self .on_numpad_request
275264 )
@@ -304,6 +293,8 @@ def __init__(
304293 self .printer .fan_update [str , str , float ].connect (self .on_fan_object_update )
305294 self .printer .fan_update [str , str , int ].connect (self .on_fan_object_update )
306295
296+ self .printer .printer_config .connect (self .on_printer_config )
297+
307298 def _handle_z_tilt_object_update (self , value , state ):
308299 if state :
309300 self .call_load_panel .emit (False , "" )
@@ -470,6 +461,44 @@ def _handle_gcode_response(self, messages: list):
470461 f"Retries: { retries_done } /{ retries_total } | Range: { probed_range :.6f} | Tolerance: { tolerance :.6f} " ,
471462 )
472463
464+ @QtCore .pyqtSlot (dict , name = "printer_config" )
465+ def on_printer_config (self , config : dict ) -> None :
466+ """Slot that receives the full printer configuration,
467+
468+ Additionally, this method configures the signal connections
469+ between controllable heaters and numpad calls
470+ """
471+ try :
472+ self .panel .extruder_temp_display .clicked .disconnect ()
473+ self .panel .bed_temp_display .clicked .disconnect ()
474+ except Exception :
475+ _logger .debug ("Signals were not connected" )
476+ extruder = config .get ("extruder" , None ) or {}
477+ bed = config .get ("heater_bed" , None ) or {}
478+ e_min_temp = extruder .get ("min_temp" , 0 )
479+ e_max_temp = extruder .get ("max_temp" , 300 )
480+ b_max_temp = bed .get ("max_temp" , 100 )
481+ b_min_temp = bed .get ("min_temp" , 0 )
482+ # Configure numpads
483+ self .panel .extruder_temp_display .clicked .connect (
484+ lambda : self .request_numpad [str , int , "PyQt_PyObject" , int , int ].emit (
485+ "Extruder Temperature" ,
486+ int (round (float (self .panel .extruder_temp_display .secondary_text ))),
487+ self .on_numpad_change ,
488+ int (e_min_temp ),
489+ int (e_max_temp ),
490+ )
491+ )
492+ self .panel .bed_temp_display .clicked .connect (
493+ lambda : self .request_numpad [str , int , "PyQt_PyObject" , int , int ].emit (
494+ "Bed Temperature" ,
495+ int (round (float (self .panel .bed_temp_display .secondary_text ))),
496+ self .on_numpad_change ,
497+ int (b_min_temp ),
498+ int (b_max_temp ),
499+ )
500+ )
501+
473502 def handle_ztilt (self ):
474503 """Handle Z-Tilt Adjustment"""
475504 self .call_load_panel .emit (True , "Please wait, performing Z-axis calibration." )
0 commit comments