Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion BlocksScreen/helper_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ def calculate_current_layer(
"""
if z_position == 0:
return -1
_current_layer = 1 + (z_position - first_layer_height) / layer_height
if z_position <= first_layer_height:
return 1

_current_layer = (z_position) / layer_height

return int(_current_layer)

Expand Down
56 changes: 37 additions & 19 deletions BlocksScreen/lib/panels/widgets/jobStatusPage.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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", []))
Expand Down Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -293,17 +300,28 @@ 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":
_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(
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)
),
)
self.layer_display_button.setText(
f"{int(_current_layer)}" if _current_layer != -1 else "?"
)
)
_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")
Expand Down
8 changes: 8 additions & 0 deletions BlocksScreen/lib/utils/display_button.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading