Improve (and fix) time displays

master
Guillaume Seguin 2012-08-07 13:54:07 +02:00
parent aba8848647
commit 08c42443f1
2 changed files with 12 additions and 8 deletions

View File

@ -16,7 +16,7 @@
# along with Printrun. If not, see <http://www.gnu.org/licenses/>.
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}

View File

@ -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)