Commit 4e8c0188 authored by Guillaume Seguin's avatar Guillaume Seguin

Move startcb and endcb to pronsole

parent 7facb94c
...@@ -28,7 +28,7 @@ import locale ...@@ -28,7 +28,7 @@ import locale
import logging import logging
from . import printcore from . import printcore
from printrun.printrun_utils import install_locale from printrun.printrun_utils import install_locale, format_time, format_duration
install_locale('pronterface') install_locale('pronterface')
from printrun import gcoder from printrun import gcoder
...@@ -361,6 +361,8 @@ class pronsole(cmd.Cmd): ...@@ -361,6 +361,8 @@ class pronsole(cmd.Cmd):
self.dynamic_temp = False self.dynamic_temp = False
self.p = printcore.printcore() self.p = printcore.printcore()
self.p.recvcb = self.recvcb self.p.recvcb = self.recvcb
self.p.startcb = self.startcb
self.p.endcb = self.endcb
self.recvlisteners = [] self.recvlisteners = []
self.in_macro = False self.in_macro = False
self.p.onlinecb = self.online self.p.onlinecb = self.online
...@@ -384,6 +386,8 @@ class pronsole(cmd.Cmd): ...@@ -384,6 +386,8 @@ class pronsole(cmd.Cmd):
self.settings._bedtemp_abs_cb = self.set_temp_preset self.settings._bedtemp_abs_cb = self.set_temp_preset
self.settings._bedtemp_pla_cb = self.set_temp_preset self.settings._bedtemp_pla_cb = self.set_temp_preset
self.monitoring = 0 self.monitoring = 0
self.starttime = 0
self.extra_print_time = 0
self.silent = False self.silent = False
self.commandprefixes = 'MGT$' self.commandprefixes = 'MGT$'
self.promptstrs = {"offline": "%(bold)suninitialized>%(normal)s ", self.promptstrs = {"offline": "%(bold)suninitialized>%(normal)s ",
...@@ -1049,6 +1053,27 @@ class pronsole(cmd.Cmd): ...@@ -1049,6 +1053,27 @@ class pronsole(cmd.Cmd):
for i in self.recvlisteners: for i in self.recvlisteners:
i(l) i(l)
def startcb(self, resuming = False):
self.starttime = time.time()
if resuming:
print _("Print resumed at: %s") % format_time(self.starttime)
else:
print _("Print started at: %s") % format_time(self.starttime)
def endcb(self):
if self.p.queueindex == 0:
print_duration = int(time.time() - self.starttime + self.extra_print_time)
print _("Print ended at: %(end_time)s and took %(duration)s") % {"end_time": format_time(time.time()),
"duration": format_duration(print_duration)}
self.p.runSmallScript(self.endScript)
param = self.settings.final_command
if not param:
return
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 help_shell(self): def help_shell(self):
self.log("Executes a python command. Example:") self.log("Executes a python command. Example:")
self.log("! os.listdir('.')") self.log("! os.listdir('.')")
......
...@@ -316,8 +316,6 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -316,8 +316,6 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.p.startcb = self.startcb self.p.startcb = self.startcb
self.p.endcb = self.endcb self.p.endcb = self.endcb
self.compute_eta = None self.compute_eta = None
self.starttime = 0
self.extra_print_time = 0
self.curlayer = 0 self.curlayer = 0
self.cur_button = None self.cur_button = None
self.predisconnect_mainqueue = None self.predisconnect_mainqueue = None
...@@ -341,31 +339,18 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -341,31 +339,18 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.autoconnect = args.autoconnect self.autoconnect = args.autoconnect
def startcb(self, resuming = False): def startcb(self, resuming = False):
self.starttime = time.time() pronsole.pronsole.startcb(self, resuming)
if resuming: if not resuming:
print _("Print resumed at: %s") % format_time(self.starttime)
else:
print _("Print started at: %s") % format_time(self.starttime)
self.compute_eta = RemainingTimeEstimator(self.fgcode) self.compute_eta = RemainingTimeEstimator(self.fgcode)
if self.settings.lockbox and self.settings.lockonstart: if self.settings.lockbox and self.settings.lockonstart:
wx.CallAfter(self.lock, force = True) wx.CallAfter(self.lock, force = True)
def endcb(self): def endcb(self):
pronsole.pronsole.endcb(self)
if self.p.queueindex == 0: if self.p.queueindex == 0:
print_duration = int(time.time() - self.starttime + self.extra_print_time)
print _("Print ended at: %(end_time)s and took %(duration)s") % {"end_time": format_time(time.time()),
"duration": format_duration(print_duration)}
wx.CallAfter(self.pausebtn.Disable) wx.CallAfter(self.pausebtn.Disable)
wx.CallAfter(self.printbtn.SetLabel, _("Print")) wx.CallAfter(self.printbtn.SetLabel, _("Print"))
self.p.runSmallScript(self.endScript)
param = self.settings.final_command
if not param:
return
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): def online(self):
print _("Printer is now online.") print _("Printer is now online.")
wx.CallAfter(self.online_gui) wx.CallAfter(self.online_gui)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment