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