Commit 211ce92b authored by D1plo1d's avatar D1plo1d

Merge branch 'experimental' of github.com:kliment/Printrun into experimental

parents 97355a82 07935b24
......@@ -152,7 +152,8 @@ class printcore():
print _("Could not connect to %s:%s:") % (hostname, port)
self.printer = None
self.printer_tcp = None
print _("Socket error %s: %s") % (e.errno, e.strerror)
print _("Socket error %s:") % e.errno,
print e.strerror
return
else:
disable_hup(self.port)
......@@ -225,18 +226,22 @@ class printcore():
# workaround cases where M105 was sent before printer Serial
# was online an empty line means read timeout was reached,
# meaning no data was received thus we count those empty lines,
# and once we have seen 5 in a row, we just break and send a
# and once we have seen 15 in a row, we just break and send a
# new M105
if not line: empty_lines += 1
# 15 was chosen based on the fact that it gives enough time for
# Gen7 bootloader to time out, and that the non received M105
# issues should be quite rare so we can wait for a long time
# before resending
if not line:
empty_lines += 1
if empty_lines == 15: break
else: empty_lines = 0
if empty_lines == 5: break
if line.startswith(tuple(self.greetings)) or line.startswith('ok'):
if line.startswith(tuple(self.greetings)) or line.startswith('ok') or "T:" in line:
if self.onlinecb:
try: self.onlinecb()
except: pass
self.online = True
return
time.sleep(0.25)
def _listen(self):
"""This function acts on messages from the firmware
......@@ -523,7 +528,7 @@ class printcore():
except: pass
try:
self.printer.write(str(command + "\n"))
self.printer.flush()
if self.printer_tcp: self.printer.flush()
self.writefailures = 0
except socket.error as e:
print "Can't write to printer (disconnected?) (Socket error {0}): {1}".format(e.errno, e.strerror)
......
......@@ -31,8 +31,7 @@ move_gcodes = ["G0", "G1", "G2", "G3"]
class PyLine(object):
__slots__ = ('x','y','z','e','f','i','j',
'raw','split_raw',
'command','is_move',
'raw', 'command', 'is_move',
'relative','relative_e',
'current_x', 'current_y', 'current_z', 'extruding', 'current_tool',
'gcview_end_vertex')
......
......@@ -20,6 +20,15 @@ from math import log10, floor, ceil
from bufferedcanvas import *
class GraphWindow(wx.Frame):
def __init__(self, root, size = (600, 600)):
wx.Frame.__init__(self, None, title = _("Temperature graph"), size = size)
panel = wx.Panel(self, -1)
vbox = wx.BoxSizer(wx.VERTICAL)
self.graph = Graph(panel, wx.ID_ANY, root)
vbox.Add(self.graph, 1, wx.EXPAND)
panel.SetSizer(vbox)
class Graph(BufferedCanvas):
'''A class to show a Graph with Pronterface.'''
......@@ -52,6 +61,20 @@ class Graph(BufferedCanvas):
self.xbars = 6 # One bar per 10 second
self.xsteps = 60 # Covering 1 minute in the graph
self.window = None
def showwin(self, event = None):
if not self.window:
self.window = GraphWindow(self.root)
self.window.Show()
if self.timer.IsRunning():
self.window.graph.StartPlotting(self.timer.Interval)
else:
self.window.Raise()
def __del__(self):
if self.window: self.window.Close()
def OnPaint(self, evt):
dc = wx.PaintDC(self)
gc = wx.GraphicsContext.Create(dc)
......@@ -197,6 +220,7 @@ class Graph(BufferedCanvas):
def SetBedTemperature(self, value):
self.bedtemps.pop()
self.bedtemps.append(value)
if self.window: self.window.graph.SetBedTemperature(value)
def AddBedTemperature(self, value):
self.bedtemps.append(value)
......@@ -206,6 +230,7 @@ class Graph(BufferedCanvas):
def SetBedTargetTemperature(self, value):
self.bedtargettemps.pop()
self.bedtargettemps.append(value)
if self.window: self.window.graph.SetBedTargetTemperature(value)
def AddBedTargetTemperature(self, value):
self.bedtargettemps.append(value)
......@@ -215,6 +240,7 @@ class Graph(BufferedCanvas):
def SetExtruder0Temperature(self, value):
self.extruder0temps.pop()
self.extruder0temps.append(value)
if self.window: self.window.graph.SetExtruder0Temperature(value)
def AddExtruder0Temperature(self, value):
self.extruder0temps.append(value)
......@@ -224,6 +250,7 @@ class Graph(BufferedCanvas):
def SetExtruder0TargetTemperature(self, value):
self.extruder0targettemps.pop()
self.extruder0targettemps.append(value)
if self.window: self.window.graph.SetExtruder0TargetTemperature(value)
def AddExtruder0TargetTemperature(self, value):
self.extruder0targettemps.append(value)
......@@ -233,6 +260,7 @@ class Graph(BufferedCanvas):
def SetExtruder1Temperature(self, value):
self.extruder1temps.pop()
self.extruder1temps.append(value)
if self.window: self.window.graph.SetExtruder1Temperature(value)
def AddExtruder1Temperature(self, value):
self.extruder1temps.append(value)
......@@ -242,6 +270,7 @@ class Graph(BufferedCanvas):
def SetExtruder1TargetTemperature(self, value):
self.extruder1targettemps.pop()
self.extruder1targettemps.append(value)
if self.window: self.window.graph.SetExtruder1TargetTemperature(value)
def AddExtruder1TargetTemperature(self, value):
self.extruder1targettemps.append(value)
......@@ -251,10 +280,12 @@ class Graph(BufferedCanvas):
def StartPlotting(self, time):
self.Refresh()
self.timer.Start(time)
if self.window: self.window.graph.StartPlotting(time)
def StopPlotting(self):
self.timer.Stop()
self.Refresh()
if self.window: self.window.graph.StopPlotting()
def draw(self, dc, w, h):
dc.SetBackground(wx.Brush(self.root.settings.bgcolor))
......
......@@ -171,6 +171,7 @@ def add_extra_controls(self, root, parentpanel, extra_buttons = None):
self.Add(root.graph, pos = (base_line + 5, 0), span = (3, 6))
else:
self.Add(root.graph, pos = (base_line + 2, 5), span = (3, 1))
root.graph.Bind(wx.EVT_LEFT_DOWN, root.graph.showwin)
if extra_buttons:
pos_mapping = {
......
......@@ -295,7 +295,7 @@ class GcodeModel(Model):
def copy(self):
copy = GcodeModel()
for var in ["vertices", "colors", "max_layers", "num_layers_to_draw", "printed_until", "layer_stops"]:
for var in ["vertices", "colors", "max_layers", "num_layers_to_draw", "printed_until", "layer_stops", "dims"]:
setattr(copy, var, getattr(self, var))
copy.loaded = True
copy.initialized = False
......
......@@ -539,6 +539,7 @@ class pronsole(cmd.Cmd):
if ls.startswith('!'):
return ws + ls[1:] + "\n" # python mode
else:
ls = ls.replace('"','\\"') # need to escape double quotes
ret = ws + 'self.parseusercmd("'+ls+'".format(*arg))\n' # parametric command mode
return ret + ws + 'self.onecmd("'+ls+'".format(*arg))\n'
......@@ -576,7 +577,7 @@ class pronsole(cmd.Cmd):
self.logError("Macro '"+macro_name+"' is not defined")
def do_macro(self, args):
if args.strip()=="":
self.print_topics("User-defined macros", self.macros.keys(), 15, 80)
self.print_topics("User-defined macros", map(str,self.macros.keys()), 15, 80)
return
arglist = args.split(None, 1)
macro_name = arglist[0]
......@@ -1430,6 +1431,9 @@ class pronsole(cmd.Cmd):
self.processing_args = False
if args.filename:
filename = args.filename.decode(locale.getpreferredencoding())
self.cmdline_filename_callback(filename)
def cmdline_filename_callback(self, filename):
self.do_load(filename)
def parse_cmdline(self, args):
......
......@@ -50,7 +50,7 @@ import pronsole
from pronsole import dosify, wxSetting, HiddenSetting, StringSetting, SpinSetting, FloatSpinSetting, BooleanSetting, StaticTextSetting
from printrun import gcoder
tempreport_exp = re.compile("([TB]\d*):([-+]?\d*\.?\d*)(?: \/)?([-+]?\d*\.?\d*)")
tempreport_exp = re.compile("([TB]\d*):([-+]?\d*\.?\d*)(?: ?\/)?([-+]?\d*\.?\d*)")
def parse_temperature_report(report):
matches = tempreport_exp.findall(report)
......@@ -1226,15 +1226,32 @@ class PronterWindow(MainWindow, pronsole.pronsole):
if "T0" in temps:
hotend_temp = float(temps["T0"][0])
else:
hotend_temp = float(temps["T"][0]) if "T" in temps else -1.0
hotend_temp = float(temps["T"][0]) if "T" in temps else None
if hotend_temp is not None:
if self.display_graph: wx.CallAfter(self.graph.SetExtruder0Temperature, hotend_temp)
if self.display_gauges: wx.CallAfter(self.hottgauge.SetValue, hotend_temp)
setpoint = None
if "T0" in temps and temps["T0"][1]: setpoint = float(temps["T0"][1])
elif temps["T"][1]: setpoint = float(temps["T"][1])
if setpoint is not None:
if self.display_graph: wx.CallAfter(self.graph.SetExtruder0TargetTemperature, setpoint)
if self.display_gauges: wx.CallAfter(self.hottgauge.SetTarget, setpoint)
if "T1" in temps:
hotend_temp = float(temps["T1"][0])
if self.display_graph: wx.CallAfter(self.graph.SetExtruder1Temperature, hotend_temp)
bed_temp = float(temps["B"][0]) if "B" in temps else -1.0
setpoint = temps["T1"][1]
if setpoint and self.display_graph:
wx.CallAfter(self.graph.SetExtruder1TargetTemperature, float(setpoint))
bed_temp = float(temps["B"][0]) if "B" in temps else None
if bed_temp is not None:
if self.display_graph: wx.CallAfter(self.graph.SetBedTemperature, bed_temp)
if self.display_gauges: wx.CallAfter(self.bedtgauge.SetValue, bed_temp)
setpoint = temps["B"][1]
if setpoint:
setpoint = float(setpoint)
if self.display_graph: wx.CallAfter(self.graph.SetBedTargetTemperature, setpoint)
if self.display_gauges: wx.CallAfter(self.bedtgauge.SetTarget, setpoint)
except:
traceback.print_exc()
......@@ -1469,6 +1486,11 @@ class PronterWindow(MainWindow, pronsole.pronsole):
threading.Thread(target = self.skein_func).start()
threading.Thread(target = self.skein_monitor).start()
def cmdline_filename_callback(self, filename):
# Do nothing when processing a filename from command line, as we'll
# handle it when everything has been prepared
self.filename = filename
def do_load(self,l):
if hasattr(self, 'skeining'):
self.loadfile(None, l)
......
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