Commit 3232cad5 authored by Guillaume Seguin's avatar Guillaume Seguin

Truly fix #584, refactor a bit command parsing

Use precmd() method instead of adding our own layer of preprocessing
parent 40742d31
......@@ -62,6 +62,7 @@ tempreading_exp = re.compile("(^T:| T:)")
REPORT_NONE = 0
REPORT_POS = 1
REPORT_TEMP = 2
REPORT_MANUAL = 4
class Status(object):
......@@ -327,8 +328,12 @@ class pronsole(cmd.Cmd):
def help_gcodes(self):
self.log("Gcodes are passed through to the printer as they are")
def parseusercmd(self, line):
pass
def precmd(self, line):
if line.upper().startswith("M114"):
self.userm114 += 1
elif line.upper().startswith("M105"):
self.userm105 += 1
return line
def help_shell(self):
self.log("Executes a python command. Example:")
......@@ -439,7 +444,7 @@ class pronsole(cmd.Cmd):
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
ret = ws + 'self.precmd("' + ls + '".format(*arg))\n' # parametric command mode
return ret + ws + 'self.onecmd("' + ls + '".format(*arg))\n'
def compile_macro(self, macro_name, macro_def):
......@@ -1196,24 +1201,26 @@ class pronsole(cmd.Cmd):
isreport = REPORT_POS
if self.userm114 > 0:
self.userm114 -= 1
isreport |= REPORT_MANUAL
if "ok T:" in l or tempreading_exp.findall(l):
self.tempreadings = l
isreport = REPORT_TEMP
if self.userm105 > 0:
self.userm105 -= 1
isreport |= REPORT_MANUAL
else:
self.m105_waitcycles = 0
return isreport
def recvcb(self, l):
report_type = self.recvcb_report(l)
if report_type == REPORT_TEMP:
if report_type & REPORT_TEMP:
self.status.update_tempreading(l)
tstring = l.rstrip()
for listener in self.recvlisteners:
listener(l)
if tstring != "ok" and not self.sdlisting \
and not self.monitoring and report_type == REPORT_NONE:
and not self.monitoring and (report_type == REPORT_NONE or report_type & REPORT_MANUAL):
if tstring[:5] == "echo:":
tstring = tstring[5:].lstrip()
if self.silent is False: print "\r" + tstring.ljust(15)
......
......@@ -655,19 +655,13 @@ class PronterWindow(MainWindow, pronsole.pronsole):
def set_verbose_communications(self, e):
self.p.loud = e.IsChecked()
def parseusercmd(self, line):
if line.upper().startswith("M114"):
self.userm114 += 1
elif line.upper().startswith("M105"):
self.userm105 += 1
def sendline(self, e):
command = self.commandbox.GetValue()
if not len(command):
return
wx.CallAfter(self.addtexttolog, ">>> " + command + "\n")
self.parseusercmd(str(command))
self.onecmd(str(command))
line = self.precmd(str(command))
self.onecmd(line)
self.commandbox.SetSelection(0, len(command))
self.commandbox.history.append(command)
self.commandbox.histindex = len(self.commandbox.history)
......@@ -2005,7 +1999,7 @@ Printrun. If not, see <http://www.gnu.org/licenses/>."""
return self.editbutton(e)
self.cur_button = e.GetEventObject().custombutton
command = e.GetEventObject().properties.command
self.parseusercmd(command)
command = self.precmd(command)
self.onecmd(command)
self.cur_button = None
except:
......
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