From 370aee9dcebb72e075c29ab2b0b93d573d21ce2a Mon Sep 17 00:00:00 2001 From: Roberto Date: Tue, 23 Dec 2025 14:36:48 +0000 Subject: [PATCH 1/4] Bugfix: fixed total layer/current layer fallback --- BlocksScreen/helper_methods.py | 2 +- .../lib/panels/widgets/jobStatusPage.py | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/BlocksScreen/helper_methods.py b/BlocksScreen/helper_methods.py index 0dd2b2db..1f7b5a91 100644 --- a/BlocksScreen/helper_methods.py +++ b/BlocksScreen/helper_methods.py @@ -254,7 +254,7 @@ def calculate_current_layer( """ if z_position == 0: return -1 - _current_layer = 1 + (z_position - first_layer_height) / layer_height + _current_layer =(z_position) / layer_height return int(_current_layer) diff --git a/BlocksScreen/lib/panels/widgets/jobStatusPage.py b/BlocksScreen/lib/panels/widgets/jobStatusPage.py index 0d7c4e29..5e384ed3 100644 --- a/BlocksScreen/lib/panels/widgets/jobStatusPage.py +++ b/BlocksScreen/lib/panels/widgets/jobStatusPage.py @@ -293,14 +293,22 @@ def on_gcode_move_update(self, field: str, value: list) -> None: """Handle gcode move""" if "gcode_position" in field: # Without offsets if self._internal_print_status == "printing": + object_height = float(self.file_metadata.get("object_height", -1.0)) + layer_height = float(self.file_metadata.get("layer_height", -1.0)) + first_layer_height = float( + self.file_metadata.get("first_layer_height", -1.0) + ) _current_layer = calculate_current_layer( z_position=value[2], - object_height=float(self.file_metadata.get("object_height", -1.0)), - layer_height=float(self.file_metadata.get("layer_height", -1.0)), - first_layer_height=float( - self.file_metadata.get("first_layer_height", -1.0) - ), + object_height=object_height, + layer_height=layer_height, + first_layer_height=first_layer_height, ) + + total_layer = (object_height ) / layer_height if layer_height > 0 else -1 + self.layer_display_button.secondary_text = ( + f"{int(total_layer)}" if total_layer != -1 else "?" + ) self.layer_display_button.setText( f"{int(_current_layer)}" if _current_layer != -1 else "?" ) From 73719b1ef395fc19f0d68beaf9c09606b9fe941f Mon Sep 17 00:00:00 2001 From: Roberto Date: Tue, 23 Dec 2025 14:38:05 +0000 Subject: [PATCH 2/4] Add: added font size and family --- BlocksScreen/lib/utils/display_button.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BlocksScreen/lib/utils/display_button.py b/BlocksScreen/lib/utils/display_button.py index 1f798dfe..5bda40aa 100644 --- a/BlocksScreen/lib/utils/display_button.py +++ b/BlocksScreen/lib/utils/display_button.py @@ -174,6 +174,10 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None: int(_mtl.width() / 2.0), _rect.height(), ) + font = QtGui.QFont() + font.setPointSize(12) + font.setFamily("Momcake-bold") + painter.setFont(font) painter.drawText( _ptl_rect, QtCore.Qt.TextFlag.TextShowMnemonic @@ -240,6 +244,10 @@ def paintEvent(self, a0: QtGui.QPaintEvent) -> None: ) else: + font = QtGui.QFont() + font.setPointSize(12) + font.setFamily("Momcake-bold") + painter.setFont(font) painter.drawText( _mtl, QtCore.Qt.TextFlag.TextShowMnemonic From 4892986528dece23e8cc308328c2f0134ae12c10 Mon Sep 17 00:00:00 2001 From: Roberto Date: Tue, 23 Dec 2025 17:29:59 +0000 Subject: [PATCH 3/4] bugfix: where the fallback was allways active --- BlocksScreen/helper_methods.py | 5 +- .../lib/panels/widgets/jobStatusPage.py | 64 +++++++++++-------- 2 files changed, 40 insertions(+), 29 deletions(-) diff --git a/BlocksScreen/helper_methods.py b/BlocksScreen/helper_methods.py index 1f7b5a91..fa940b92 100644 --- a/BlocksScreen/helper_methods.py +++ b/BlocksScreen/helper_methods.py @@ -254,7 +254,10 @@ def calculate_current_layer( """ if z_position == 0: return -1 - _current_layer =(z_position) / layer_height + if z_position <= first_layer_height: + return 1 + + _current_layer = (z_position) / layer_height return int(_current_layer) diff --git a/BlocksScreen/lib/panels/widgets/jobStatusPage.py b/BlocksScreen/lib/panels/widgets/jobStatusPage.py index 5e384ed3..134fd8ba 100644 --- a/BlocksScreen/lib/panels/widgets/jobStatusPage.py +++ b/BlocksScreen/lib/panels/widgets/jobStatusPage.py @@ -58,6 +58,7 @@ class JobStatusWidget(QtWidgets.QWidget): def __init__(self, parent) -> None: super().__init__(parent) self.thumbnail_graphics = [] + self.layer_fallback = False self._setupUI() self.cancel_print_dialog = dialogPage.DialogPage(self) self.tune_menu_btn.clicked.connect(self.tune_clicked.emit) @@ -177,8 +178,8 @@ def on_print_start(self, file: str) -> None: @QtCore.pyqtSlot(dict, name="on_fileinfo") def on_fileinfo(self, fileinfo: dict) -> None: """Handle received file information/metadata""" - self.total_layers = str(fileinfo.get("layer_count", "?")) - self.layer_display_button.setText("?") + self.total_layers = str(fileinfo.get("layer_count", "---")) + self.layer_display_button.setText("---") self.layer_display_button.secondary_text = str(self.total_layers) self.file_metadata = fileinfo self._load_thumbnails(*fileinfo.get("thumbnail_images", [])) @@ -240,7 +241,7 @@ def on_print_stats_update(self, field: str, value: dict | float | str) -> None: elif value in ("cancelled", "complete", "error", "standby"): self._current_file_name = "" self._internal_print_status = "" - self.total_layers = "?" + self.total_layers = "---" self.file_metadata.clear() self.hide_request.emit() self.thumbnail_view.deleteLater() @@ -261,18 +262,24 @@ def on_print_stats_update(self, field: str, value: dict | float | str) -> None: logger.info( f"Unexpected error while posting print job start event: {e}" ) - - if not self.file_metadata: - return if isinstance(value, dict): + self.layer_fallback = False if "total_layer" in value.keys(): self.total_layers = value["total_layer"] - self.layer_display_button.secondary_text = str(self.total_layers) + if value["total_layer"] is not None: + self.layer_display_button.secondary_text = str(self.total_layers) + + else: + self.total_layers = "---" + self.layer_fallback = True + if "current_layer" in value.keys(): if value["current_layer"] is not None: _current_layer = value["current_layer"] - if _current_layer is not None: - self.layer_display_button.setText(f"{int(_current_layer)}") + self.layer_display_button.setText(f"{int(_current_layer)}") + else: + self.layer_display_button.setText("---") + self.layer_fallback = True elif isinstance(value, float): if "total_duration" in field: self.print_total_duration = value @@ -293,25 +300,26 @@ def on_gcode_move_update(self, field: str, value: list) -> None: """Handle gcode move""" if "gcode_position" in field: # Without offsets if self._internal_print_status == "printing": - object_height = float(self.file_metadata.get("object_height", -1.0)) - layer_height = float(self.file_metadata.get("layer_height", -1.0)) - first_layer_height = float( - self.file_metadata.get("first_layer_height", -1.0) - ) - _current_layer = calculate_current_layer( - z_position=value[2], - object_height=object_height, - layer_height=layer_height, - first_layer_height=first_layer_height, - ) - - total_layer = (object_height ) / layer_height if layer_height > 0 else -1 - self.layer_display_button.secondary_text = ( - f"{int(total_layer)}" if total_layer != -1 else "?" - ) - self.layer_display_button.setText( - f"{int(_current_layer)}" if _current_layer != -1 else "?" - ) + if self.layer_fallback: + object_height = float(self.file_metadata.get("object_height", -1.0)) + layer_height = float(self.file_metadata.get("layer_height", -1.0)) + first_layer_height = float( + self.file_metadata.get("first_layer_height", -1.0) + ) + _current_layer = calculate_current_layer( + z_position=value[2], + object_height=object_height, + layer_height=layer_height, + first_layer_height=first_layer_height, + ) + + total_layer = (object_height ) / layer_height if layer_height > 0 else -1 + self.layer_display_button.secondary_text = ( + f"{int(total_layer)}" if total_layer != -1 else "---" + ) + self.layer_display_button.setText( + f"{int(_current_layer)}" if _current_layer != -1 else "---" + ) @QtCore.pyqtSlot(str, float, name="virtual_sdcard_update") @QtCore.pyqtSlot(str, bool, name="virtual_sdcard_update") From 8f27483b86022f03cb726145df844da0520266a3 Mon Sep 17 00:00:00 2001 From: Roberto Date: Tue, 23 Dec 2025 17:40:07 +0000 Subject: [PATCH 4/4] Refactor: ran ruff formatter --- BlocksScreen/lib/panels/widgets/jobStatusPage.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/BlocksScreen/lib/panels/widgets/jobStatusPage.py b/BlocksScreen/lib/panels/widgets/jobStatusPage.py index 134fd8ba..40613d54 100644 --- a/BlocksScreen/lib/panels/widgets/jobStatusPage.py +++ b/BlocksScreen/lib/panels/widgets/jobStatusPage.py @@ -268,7 +268,7 @@ def on_print_stats_update(self, field: str, value: dict | float | str) -> None: self.total_layers = value["total_layer"] if value["total_layer"] is not None: self.layer_display_button.secondary_text = str(self.total_layers) - + else: self.total_layers = "---" self.layer_fallback = True @@ -313,7 +313,9 @@ def on_gcode_move_update(self, field: str, value: list) -> None: first_layer_height=first_layer_height, ) - total_layer = (object_height ) / layer_height if layer_height > 0 else -1 + total_layer = ( + (object_height) / layer_height if layer_height > 0 else -1 + ) self.layer_display_button.secondary_text = ( f"{int(total_layer)}" if total_layer != -1 else "---" )