Skip to content

Commit

Permalink
Format used/remaining filament length in mm, cm, m
Browse files Browse the repository at this point in the history
depending on the amount so that less digits are used.
  • Loading branch information
volconst committed Sep 27, 2020
1 parent f81b95e commit 7c3cdd7
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions printrun/pronterface.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ class PronterfaceQuitException(Exception):
from printrun import gcoder
from .pronsole import REPORT_NONE, REPORT_POS, REPORT_TEMP, REPORT_MANUAL

def format_length(mm, fractional=2):
if mm <= 10:
units = mm
suffix = 'mm'
elif mm < 1000:
units = mm / 10
suffix = 'cm'
else:
units = mm / 1000
suffix = 'm'
return '%%.%df' % fractional % units + suffix

class ConsoleOutputHandler:
"""Handle console output. All messages go through the logging submodule. We setup a logging handler to get logged messages and write them to both stdout (unless a log file path is specified, in which case we add another logging handler to write to this file) and the log panel.
We also redirect stdout and stderr to ourself to catch print messages and al."""
Expand Down Expand Up @@ -1602,7 +1614,7 @@ def output_gcode_stats(self):
gcode = self.fgcode
self.spool_manager.refresh()

self.log(_("%.2fmm of filament used in this print") % gcode.filament_length)
self.log(_("%s of filament used in this print") % format_length(gcode.filament_length))

if len(gcode.filament_length_multi) > 1:
for i in enumerate(gcode.filament_length_multi):
Expand All @@ -1613,12 +1625,11 @@ def output_gcode_stats(self):
" from spool '%s' (%.2fmm will remain)" %
(self.spool_manager.getSpoolName(i[0]),
self.calculate_remaining_filament(i[1], i[0]))))
else:
if self.spool_manager.getSpoolName(0) != None:
self.log(_(
"Using spool '%s' (%.2fmm of filament will remain)" %
elif self.spool_manager.getSpoolName(0) != None:
self.log(
_("Using spool '%s' (%s of filament will remain)") %
(self.spool_manager.getSpoolName(0),
self.calculate_remaining_filament(
format_length(self.calculate_remaining_filament(
gcode.filament_length, 0))))

self.log(_("The print goes:"))
Expand Down

0 comments on commit 7c3cdd7

Please sign in to comment.