From 08c42443f1485d405dbc61aa7e9d64459ba1417a Mon Sep 17 00:00:00 2001 From: Guillaume Seguin Date: Tue, 7 Aug 2012 13:54:07 +0200 Subject: [PATCH] Improve (and fix) time displays --- pronsole.py | 4 ++-- pronterface.py | 16 ++++++++++------ 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pronsole.py b/pronsole.py index d0905b2..2fda5f5 100755 --- a/pronsole.py +++ b/pronsole.py @@ -16,7 +16,7 @@ # along with Printrun. If not, see . import cmd, sys -import glob, os, time +import glob, os, time, datetime import sys, subprocess import math, codecs from math import sqrt @@ -178,7 +178,7 @@ def estimate_duration(g): lastf = f #print "Total Duration: " #, time.strftime('%H:%M:%S', time.gmtime(totalduration)) - return "{0:d} layers, ".format(int(layercount))+time.strftime('%H:%M:%S', time.gmtime(totalduration)) + return "{0:d} layers, ".format(int(layercount)) + str(datetime.timedelta(seconds = int(totalduration))) class Settings: #def _temperature_alias(self): return {"pla":210,"abs":230,"off":0} diff --git a/pronterface.py b/pronterface.py index 5f75f79..4101e31 100755 --- a/pronterface.py +++ b/pronterface.py @@ -25,7 +25,7 @@ try: except: print _("WX is not installed. This program requires WX to run.") raise -import sys, glob, time, threading, traceback, cStringIO, subprocess +import sys, glob, time, datetime, threading, traceback, cStringIO, subprocess from printrun.pronterface_widgets import * @@ -57,7 +57,10 @@ def parse_temperature_report(report, key): return float(filter(lambda x: x.startswith(key), report.split())[0].split(":")[1].split("/")[0]) def format_time(timestamp): - return time.strftime('%H:%M:%S', timestamp) + return datetime.datetime.fromtimestamp(timestamp).strftime("%H:%M:%S") + +def format_duration(delta): + return str(datetime.timedelta(seconds = int(delta))) class Tee(object): def __init__(self, target): @@ -188,7 +191,8 @@ class PronterWindow(wx.Frame,pronsole.pronsole): def endcb(self): if(self.p.queueindex==0): print "Print ended at: " + format_time(time.time()) - print "and took: " + format_time(int(time.time () - self.starttime + self.extra_print_time)) + print_duration = int(time.time () - self.starttime + self.extra_print_time) + print "and took: " + format_duration(print_duration) wx.CallAfter(self.pausebtn.Disable) wx.CallAfter(self.printbtn.SetLabel,_("Print")) @@ -196,7 +200,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): if not param: return import shlex - pararray=[i.replace("$s",str(self.filename)).replace("$t", format_time(int(time.time()-self.starttime+self.extra_print_time))).encode() for i in shlex.split(param.replace("\\","\\\\").encode())] + pararray=[i.replace("$s",str(self.filename)).replace("$t", format_duration(print_duration)).encode() for i in shlex.split(param.replace("\\","\\\\").encode())] self.finalp=subprocess.Popen(pararray,stderr=subprocess.STDOUT,stdout=subprocess.PIPE) def online(self): @@ -1357,8 +1361,8 @@ class PronterWindow(wx.Frame,pronsole.pronsole): secondselapsed = int(time.time() - self.starttime + self.extra_print_time) secondsestimate = secondselapsed / fractioncomplete secondsremain = secondsestimate - secondselapsed - string += _(" Est: %s of %s remaining | ") % (format_time(secondsremain), - format_time(secondsestimate)) + string += _(" Est: %s of %s remaining | ") % (format_duration(secondsremain), + format_duration(secondsestimate)) string += _(" Z: %0.2f mm") % self.curlayer wx.CallAfter(self.status.SetStatusText, string) wx.CallAfter(self.gviz.Refresh)