Commit 6cce62b2 authored by Guillaume Seguin's avatar Guillaume Seguin

Merge branch 'master' of github.com:kliment/Printrun

parents 16934b24 598d39e2
This diff is collapsed.
...@@ -33,7 +33,7 @@ except ImportError: import json ...@@ -33,7 +33,7 @@ except ImportError: import json
from . import pronsole from . import pronsole
from . import printcore from . import printcore
from .utils import install_locale, setup_logging, \ from .utils import install_locale, setup_logging, dosify, \
iconfile, configfile, format_time, format_duration, \ iconfile, configfile, format_time, format_duration, \
hexcolor_to_float, parse_temperature_report, \ hexcolor_to_float, parse_temperature_report, \
prepare_command, check_rgb_color, check_rgba_color prepare_command, check_rgb_color, check_rgba_color
...@@ -45,8 +45,7 @@ except: ...@@ -45,8 +45,7 @@ except:
logging.error(_("WX is not installed. This program requires WX to run.")) logging.error(_("WX is not installed. This program requires WX to run."))
raise raise
from printrun.gui.widgets import SpecialButton, MacroEditor, \ from .gui.widgets import SpecialButton, MacroEditor, PronterOptions, ButtonEdit
PronterOptions, ButtonEdit
winsize = (800, 500) winsize = (800, 500)
layerindex = 0 layerindex = 0
...@@ -58,12 +57,12 @@ pronterface_quitting = False ...@@ -58,12 +57,12 @@ pronterface_quitting = False
class PronterfaceQuitException(Exception): class PronterfaceQuitException(Exception):
pass pass
from printrun.gui import MainWindow from .gui import MainWindow
from printrun.excluder import Excluder from .excluder import Excluder
from pronsole import dosify, wxSetting, HiddenSetting, StringSetting, SpinSetting, FloatSpinSetting, BooleanSetting, StaticTextSetting from .settings import wxSetting, HiddenSetting, StringSetting, SpinSetting, \
FloatSpinSetting, BooleanSetting, StaticTextSetting
from printrun import gcoder from printrun import gcoder
from .pronsole import REPORT_NONE, REPORT_POS, REPORT_TEMP
tempreading_exp = re.compile("(^T:| T:)")
class Tee(object): class Tee(object):
def __init__(self, target): def __init__(self, target):
...@@ -141,14 +140,8 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -141,14 +140,8 @@ class PronterWindow(MainWindow, pronsole.pronsole):
self.filename = filename self.filename = filename
self.statuscheck = False
self.status_thread = None
self.capture_skip = {} self.capture_skip = {}
self.capture_skip_newline = False self.capture_skip_newline = False
self.tempreadings = ""
self.userm114 = 0
self.userm105 = 0
self.m105_waitcycles = 0
self.fgcode = None self.fgcode = None
self.excluder = None self.excluder = None
self.slicep = None self.slicep = None
...@@ -327,10 +320,6 @@ class PronterWindow(MainWindow, pronsole.pronsole): ...@@ -327,10 +320,6 @@ class PronterWindow(MainWindow, pronsole.pronsole):
pronsole.pronsole.kill(self) pronsole.pronsole.kill(self)
global pronterface_quitting global pronterface_quitting
pronterface_quitting = True pronterface_quitting = True
self.statuscheck = False
if self.status_thread:
self.status_thread.join()
self.status_thread = None
self.p.recvcb = None self.p.recvcb = None
self.p.disconnect() self.p.disconnect()
if hasattr(self, "feedrates_changed"): if hasattr(self, "feedrates_changed"):
...@@ -969,61 +958,40 @@ Printrun. If not, see <http://www.gnu.org/licenses/>.""" ...@@ -969,61 +958,40 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
# Statusbar handling # Statusbar handling
# -------------------------------------------------------------- # --------------------------------------------------------------
def statuschecker_inner(self):
status_string = ""
if self.sdprinting or self.uploading or self.p.printing:
secondsremain, secondsestimate, progress = self.get_eta()
if self.sdprinting or self.uploading:
if self.uploading:
status_string += _("SD upload: %04.2f%% |") % (100 * progress,)
status_string += _(" Line# %d of %d lines |") % (self.p.queueindex, len(self.p.mainqueue))
else:
status_string += _("SD printing: %04.2f%% |") % (self.percentdone,)
elif self.p.printing:
status_string += _("Printing: %04.2f%% |") % (100 * float(self.p.queueindex) / len(self.p.mainqueue),)
status_string += _(" Line# %d of %d lines |") % (self.p.queueindex, len(self.p.mainqueue))
if progress > 0:
status_string += _(" Est: %s of %s remaining | ") % (format_duration(secondsremain),
format_duration(secondsestimate))
status_string += _(" Z: %.3f mm") % self.curlayer
elif self.loading_gcode:
status_string = self.loading_gcode_message
wx.CallAfter(self.statusbar.SetStatusText, status_string)
wx.CallAfter(self.gviz.Refresh)
# Call pronsole's statuschecker inner loop function to handle
# temperature monitoring and status loop sleep
pronsole.pronsole.statuschecker_inner(self, self.settings.monitor)
try:
while not self.sentlines.empty():
gc = self.sentlines.get_nowait()
wx.CallAfter(self.gviz.addgcodehighlight, gc)
self.sentlines.task_done()
except Queue.Empty:
pass
def statuschecker(self): def statuschecker(self):
while self.statuscheck: pronsole.pronsole.statuschecker(self)
string = ""
if self.sdprinting or self.uploading or self.p.printing:
secondsremain, secondsestimate, progress = self.get_eta()
if self.sdprinting or self.uploading:
if self.uploading:
string += _("SD upload: %04.2f%% |") % (100 * progress,)
string += _(" Line# %d of %d lines |") % (self.p.queueindex, len(self.p.mainqueue))
else:
string += _("SD printing: %04.2f%% |") % (self.percentdone,)
elif self.p.printing:
string += _("Printing: %04.2f%% |") % (100 * float(self.p.queueindex) / len(self.p.mainqueue),)
string += _(" Line# %d of %d lines |") % (self.p.queueindex, len(self.p.mainqueue))
if progress > 0:
string += _(" Est: %s of %s remaining | ") % (format_duration(secondsremain),
format_duration(secondsestimate))
string += _(" Z: %.3f mm") % self.curlayer
elif self.loading_gcode:
string = self.loading_gcode_message
wx.CallAfter(self.statusbar.SetStatusText, string)
wx.CallAfter(self.gviz.Refresh)
if self.p.online:
if self.p.writefailures >= 4:
self.logError(_("Disconnecting after 4 failed writes."))
self.status_thread = None
self.disconnect()
return
if self.settings.monitor and self.p.online:
if self.sdprinting:
self.p.send_now("M27")
if self.m105_waitcycles % 10 == 0:
self.p.send_now("M105")
self.m105_waitcycles += 1
cur_time = time.time()
wait_time = 0
while time.time() < cur_time + self.monitor_interval - 0.25:
if not self.statuscheck:
break
time.sleep(0.25)
# Safeguard: if system time changes and goes back in the past,
# we could get stuck almost forever
wait_time += 0.25
if wait_time > self.monitor_interval - 0.25:
break
# Always sleep at least a bit, if something goes wrong with the
# system time we'll avoid freezing the whole app this way
time.sleep(0.25)
try:
while not self.sentlines.empty():
gc = self.sentlines.get_nowait()
wx.CallAfter(self.gviz.addgcodehighlight, gc)
self.sentlines.task_done()
except Queue.Empty:
pass
wx.CallAfter(self.statusbar.SetStatusText, _("Not connected to printer.")) wx.CallAfter(self.statusbar.SetStatusText, _("Not connected to printer."))
# -------------------------------------------------------------- # --------------------------------------------------------------
...@@ -1072,13 +1040,10 @@ Printrun. If not, see <http://www.gnu.org/licenses/>.""" ...@@ -1072,13 +1040,10 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
self.p.send_now("M26 S0") self.p.send_now("M26 S0")
if not self.connect_to_printer(port, baud): if not self.connect_to_printer(port, baud):
return return
self.statuscheck = True
if port != self.settings.port: if port != self.settings.port:
self.set("port", port) self.set("port", port)
if baud != self.settings.baudrate: if baud != self.settings.baudrate:
self.set("baudrate", str(baud)) self.set("baudrate", str(baud))
self.status_thread = threading.Thread(target = self.statuschecker)
self.status_thread.start()
if self.predisconnect_mainqueue: if self.predisconnect_mainqueue:
self.recoverbtn.Enable() self.recoverbtn.Enable()
...@@ -1675,8 +1640,8 @@ Printrun. If not, see <http://www.gnu.org/licenses/>.""" ...@@ -1675,8 +1640,8 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
except: except:
traceback.print_exc() traceback.print_exc()
def update_pos(self, l): def update_pos(self):
bits = gcoder.m114_exp.findall(l) bits = gcoder.m114_exp.findall(self.posreport)
x = None x = None
y = None y = None
z = None z = None
...@@ -1693,24 +1658,13 @@ Printrun. If not, see <http://www.gnu.org/licenses/>.""" ...@@ -1693,24 +1658,13 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
if z is not None: self.current_pos[2] = z if z is not None: self.current_pos[2] = z
def recvcb(self, l): def recvcb(self, l):
isreport = False report_type = self.recvcb_report(l)
if "ok C:" in l or "Count" in l \ isreport = report_type != REPORT_NONE
or ("X:" in l and len(gcoder.m114_exp.findall(l)) == 6): if report_type == REPORT_POS:
self.posreport = l self.update_pos()
self.update_pos(l) elif report_type == REPORT_TEMP:
if self.userm114 > 0:
self.userm114 -= 1
else:
isreport = True
if "ok T:" in l or tempreading_exp.findall(l):
self.tempreadings = l
wx.CallAfter(self.tempdisp.SetLabel, self.tempreadings.strip().replace("ok ", "")) wx.CallAfter(self.tempdisp.SetLabel, self.tempreadings.strip().replace("ok ", ""))
self.update_tempdisplay() self.update_tempdisplay()
if self.userm105 > 0:
self.userm105 -= 1
else:
self.m105_waitcycles = 0
isreport = True
tstring = l.rstrip() tstring = l.rstrip()
if not self.p.loud and (tstring not in ["ok", "wait"] and not isreport): if not self.p.loud and (tstring not in ["ok", "wait"] and not isreport):
wx.CallAfter(self.addtexttolog, tstring + "\n") wx.CallAfter(self.addtexttolog, tstring + "\n")
......
This diff is collapsed.
...@@ -117,6 +117,9 @@ def get_command_output(command, replaces): ...@@ -117,6 +117,9 @@ def get_command_output(command, replaces):
blocking = False) blocking = False)
return p.stdout.read() return p.stdout.read()
def dosify(name):
return os.path.split(name)[1].split(".")[0][:8] + ".g"
class RemainingTimeEstimator(object): class RemainingTimeEstimator(object):
drift = None drift = None
......
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