Commit a052f0fb authored by Guillaume Seguin's avatar Guillaume Seguin

Coding style cleanup, pronterface.py, first 25%

parent 97e2b704
...@@ -204,16 +204,15 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -204,16 +204,15 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
if self.filename: if self.filename:
wx.CallAfter(self.printbtn.Enable) wx.CallAfter(self.printbtn.Enable)
def sentcb(self, line):
def sentcb(self,line): if "G1" in line:
if("G1" in line): if "Z" in line:
if("Z" in line):
try: try:
layer=float(line.split("Z")[1].split()[0]) layer = float(line.split("Z")[1].split()[0])
if(layer!=self.curlayer): if layer != self.curlayer:
self.curlayer=layer self.curlayer = layer
self.gviz.hilight=[] self.gviz.hilight = []
threading.Thread(target=wx.CallAfter,args=(self.gviz.setlayer,layer)).start() threading.Thread(target = wx.CallAfter, args = (self.gviz.setlayer, layer)).start()
except: except:
pass pass
try: try:
...@@ -222,24 +221,24 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -222,24 +221,24 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
pass pass
#threading.Thread(target=self.gviz.addgcode,args=(line,1)).start() #threading.Thread(target=self.gviz.addgcode,args=(line,1)).start()
#self.gwindow.p.addgcode(line,hilight=1) #self.gwindow.p.addgcode(line,hilight=1)
if("M104" in line or "M109" in line): if "M104" in line or "M109" in line:
if("S" in line): if "S" in line:
try: try:
temp=float(line.split("S")[1].split("*")[0]) temp = float(line.split("S")[1].split("*")[0])
#self.hottgauge.SetTarget(temp) #self.hottgauge.SetTarget(temp)
wx.CallAfter(self.graph.SetExtruder0TargetTemperature,temp) wx.CallAfter(self.graph.SetExtruder0TargetTemperature, temp)
except: except:
pass pass
try: try:
self.sentlines.put_nowait(line) self.sentlines.put_nowait(line)
except: except:
pass pass
if("M140" in line): if "M140" in line:
if("S" in line): if "S" in line:
try: try:
temp=float(line.split("S")[1].split("*")[0]) temp = float(line.split("S")[1].split("*")[0])
#self.bedtgauge.SetTarget(temp) #self.bedtgauge.SetTarget(temp)
wx.CallAfter(self.graph.SetBedTargetTemperature,temp) wx.CallAfter(self.graph.SetBedTargetTemperature, temp)
except: except:
pass pass
try: try:
...@@ -247,71 +246,71 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -247,71 +246,71 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
except: except:
pass pass
def do_extrude(self,l=""): def do_extrude(self, l = ""):
try: try:
if not (l.__class__=="".__class__ or l.__class__==u"".__class__) or (not len(l)): if not l.__class__ in (str, unicode) or not len(l):
l=str(self.edist.GetValue()) l = str(self.edist.GetValue())
pronsole.pronsole.do_extrude(self,l) pronsole.pronsole.do_extrude(self, l)
except: except:
raise raise
def do_reverse(self,l=""): def do_reverse(self, l = ""):
try: try:
if not (l.__class__=="".__class__ or l.__class__==u"".__class__) or (not len(l)): if not l.__class__ in (str, unicode) or not len(l):
l=str(float(self.edist.GetValue())*-1.0) l = str(- float(self.edist.GetValue()))
pronsole.pronsole.do_extrude(self,l) pronsole.pronsole.do_extrude(self,l)
except: except:
pass pass
def setbedgui(self,f): def setbedgui(self, f):
self.bsetpoint=f self.bsetpoint = f
#self.bedtgauge.SetTarget(int(f)) #self.bedtgauge.SetTarget(int(f))
wx.CallAfter(self.graph.SetBedTargetTemperature,int(f)) wx.CallAfter(self.graph.SetBedTargetTemperature, int(f))
if f>0: if f>0:
wx.CallAfter(self.btemp.SetValue,str(f)) wx.CallAfter(self.btemp.SetValue, str(f))
self.set("last_bed_temperature",str(f)) self.set("last_bed_temperature", str(f))
wx.CallAfter(self.setboff.SetBackgroundColour,"") wx.CallAfter(self.setboff.SetBackgroundColour, "")
wx.CallAfter(self.setboff.SetForegroundColour,"") wx.CallAfter(self.setboff.SetForegroundColour, "")
wx.CallAfter(self.setbbtn.SetBackgroundColour,"#FFAA66") wx.CallAfter(self.setbbtn.SetBackgroundColour, "#FFAA66")
wx.CallAfter(self.setbbtn.SetForegroundColour,"#660000") wx.CallAfter(self.setbbtn.SetForegroundColour, "#660000")
wx.CallAfter(self.btemp.SetBackgroundColour,"#FFDABB") wx.CallAfter(self.btemp.SetBackgroundColour, "#FFDABB")
else: else:
wx.CallAfter(self.setboff.SetBackgroundColour,"#0044CC") wx.CallAfter(self.setboff.SetBackgroundColour, "#0044CC")
wx.CallAfter(self.setboff.SetForegroundColour,"white") wx.CallAfter(self.setboff.SetForegroundColour, "white")
wx.CallAfter(self.setbbtn.SetBackgroundColour,"") wx.CallAfter(self.setbbtn.SetBackgroundColour, "")
wx.CallAfter(self.setbbtn.SetForegroundColour,"") wx.CallAfter(self.setbbtn.SetForegroundColour, "")
wx.CallAfter(self.btemp.SetBackgroundColour,"white") wx.CallAfter(self.btemp.SetBackgroundColour, "white")
wx.CallAfter(self.btemp.Refresh) wx.CallAfter(self.btemp.Refresh)
def sethotendgui(self,f): def sethotendgui(self, f):
self.hsetpoint=f self.hsetpoint = f
#self.hottgauge.SetTarget(int(f)) #self.hottgauge.SetTarget(int(f))
wx.CallAfter(self.graph.SetExtruder0TargetTemperature,int(f)) wx.CallAfter(self.graph.SetExtruder0TargetTemperature, int(f))
if f>0: if f > 0:
wx.CallAfter(self.htemp.SetValue,str(f)) wx.CallAfter(self.htemp.SetValue, str(f))
self.set("last_temperature",str(f)) self.set("last_temperature", str(f))
wx.CallAfter(self.settoff.SetBackgroundColour,"") wx.CallAfter(self.settoff.SetBackgroundColour, "")
wx.CallAfter(self.settoff.SetForegroundColour,"") wx.CallAfter(self.settoff.SetForegroundColour, "")
wx.CallAfter(self.settbtn.SetBackgroundColour,"#FFAA66") wx.CallAfter(self.settbtn.SetBackgroundColour, "#FFAA66")
wx.CallAfter(self.settbtn.SetForegroundColour,"#660000") wx.CallAfter(self.settbtn.SetForegroundColour, "#660000")
wx.CallAfter(self.htemp.SetBackgroundColour,"#FFDABB") wx.CallAfter(self.htemp.SetBackgroundColour, "#FFDABB")
else: else:
wx.CallAfter(self.settoff.SetBackgroundColour,"#0044CC") wx.CallAfter(self.settoff.SetBackgroundColour, "#0044CC")
wx.CallAfter(self.settoff.SetForegroundColour,"white") wx.CallAfter(self.settoff.SetForegroundColour, "white")
wx.CallAfter(self.settbtn.SetBackgroundColour,"") wx.CallAfter(self.settbtn.SetBackgroundColour, "")
wx.CallAfter(self.settbtn.SetForegroundColour,"") wx.CallAfter(self.settbtn.SetForegroundColour, "")
wx.CallAfter(self.htemp.SetBackgroundColour,"white") wx.CallAfter(self.htemp.SetBackgroundColour, "white")
wx.CallAfter(self.htemp.Refresh) wx.CallAfter(self.htemp.Refresh)
def do_settemp(self,l=""): def do_settemp(self, l = ""):
try: try:
if not (l.__class__=="".__class__ or l.__class__==u"".__class__) or not l: if not l.__class__ in (str, unicode) or not len(l):
l=str(self.htemp.GetValue().split()[0]) l = str(self.htemp.GetValue().split()[0])
l=l.lower().replace(",",".") l = l.lower().replace(",", ".")
for i in self.temps.keys(): for i in self.temps.keys():
l=l.replace(i,self.temps[i]) l = l.replace(i, self.temps[i])
f=float(l) f = float(l)
if f>=0: if f >= 0:
if self.p.online: if self.p.online:
self.p.send_now("M104 S"+l) self.p.send_now("M104 S"+l)
print _("Setting hotend temperature to %f degrees Celsius.") % f print _("Setting hotend temperature to %f degrees Celsius.") % f
...@@ -320,20 +319,20 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -320,20 +319,20 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
print _("Printer is not online.") print _("Printer is not online.")
else: else:
print _("You cannot set negative temperatures. To turn the hotend off entirely, set its temperature to 0.") print _("You cannot set negative temperatures. To turn the hotend off entirely, set its temperature to 0.")
except Exception,x: except Exception, x:
print _("You must enter a temperature. (%s)" % (repr(x),)) print _("You must enter a temperature. (%s)" % (repr(x),))
if self.webInterface: if self.webInterface:
self.webInterface.AddLog("You must enter a temperature. (%s)" % (repr(x),)) self.webInterface.AddLog("You must enter a temperature. (%s)" % (repr(x),))
def do_bedtemp(self,l=""): def do_bedtemp(self, l = ""):
try: try:
if not (l.__class__=="".__class__ or l.__class__==u"".__class__) or (not len(l)): if not l.__class__ in (str, unicode) or not len(l):
l=str(self.btemp.GetValue().split()[0]) l = str(self.btemp.GetValue().split()[0])
l=l.lower().replace(",",".") l = l.lower().replace(",", ".")
for i in self.bedtemps.keys(): for i in self.bedtemps.keys():
l=l.replace(i,self.bedtemps[i]) l = l.replace(i, self.bedtemps[i])
f=float(l) f = float(l)
if f>=0: if f >= 0:
if self.p.online: if self.p.online:
self.p.send_now("M140 S"+l) self.p.send_now("M140 S"+l)
print _("Setting bed temperature to %f degrees Celsius.") % f print _("Setting bed temperature to %f degrees Celsius.") % f
...@@ -355,17 +354,17 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -355,17 +354,17 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
pronsole.pronsole.end_macro(self) pronsole.pronsole.end_macro(self)
self.update_macros_menu() self.update_macros_menu()
def delete_macro(self,macro_name): def delete_macro(self, macro_name):
pronsole.pronsole.delete_macro(self,macro_name) pronsole.pronsole.delete_macro(self, macro_name)
self.update_macros_menu() self.update_macros_menu()
def start_macro(self,macro_name,old_macro_definition=""): def start_macro(self, macro_name, old_macro_definition=""):
if not self.processing_rc: if not self.processing_rc:
def cb(definition): def cb(definition):
if len(definition.strip())==0: if len(definition.strip()) == 0:
if old_macro_definition!="": if old_macro_definition != "":
dialog = wx.MessageDialog(self,_("Do you want to erase the macro?"),style=wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION) dialog = wx.MessageDialog(self, _("Do you want to erase the macro?"), style = wx.YES_NO|wx.YES_DEFAULT|wx.ICON_QUESTION)
if dialog.ShowModal()==wx.ID_YES: if dialog.ShowModal() == wx.ID_YES:
self.delete_macro(macro_name) self.delete_macro(macro_name)
return return
print _("Cancelled.") print _("Cancelled.")
...@@ -375,11 +374,11 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -375,11 +374,11 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.cur_macro_name = macro_name self.cur_macro_name = macro_name
self.cur_macro_def = definition self.cur_macro_def = definition
self.end_macro() self.end_macro()
macroed(macro_name,old_macro_definition,cb) macroed(macro_name, old_macro_definition, cb)
else: else:
pronsole.pronsole.start_macro(self,macro_name,old_macro_definition) pronsole.pronsole.start_macro(self, macro_name, old_macro_definition)
def catchprint(self,l): def catchprint(self, l):
if self.capture_skip_newline and len(l) and not len(l.strip("\n\r")): if self.capture_skip_newline and len(l) and not len(l.strip("\n\r")):
self.capture_skip_newline = False self.capture_skip_newline = False
return return
...@@ -388,28 +387,28 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -388,28 +387,28 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.capture_skip[pat] -= 1 self.capture_skip[pat] -= 1
self.capture_skip_newline = True self.capture_skip_newline = True
return return
wx.CallAfter(self.logbox.AppendText,l) wx.CallAfter(self.logbox.AppendText, l)
if self.webInterface: if self.webInterface:
self.webInterface.AppendLog(l) self.webInterface.AppendLog(l)
def scanserial(self): def scanserial(self):
"""scan for available ports. return a list of device names.""" """scan for available ports. return a list of device names."""
baselist=[] baselist = []
if os.name=="nt": if os.name == "nt":
try: try:
key=_winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM") key = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,"HARDWARE\\DEVICEMAP\\SERIALCOMM")
i=0 i = 0
while(1): while True:
baselist+=[_winreg.EnumValue(key,i)[1]] baselist += [_winreg.EnumValue(key, i)[1]]
i+=1 i += 1
except: except:
pass pass
return baselist+glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') +glob.glob("/dev/tty.*")+glob.glob("/dev/cu.*")+glob.glob("/dev/rfcomm*") return baselist+glob.glob('/dev/ttyUSB*') + glob.glob('/dev/ttyACM*') + glob.glob("/dev/tty.*") + glob.glob("/dev/cu.*") + glob.glob("/dev/rfcomm*")
def project(self,event): def project(self, event):
import projectlayer import projectlayer
if(self.p.online): if self.p.online:
projectlayer.setframe(self,self.p).Show() projectlayer.setframe(self, self.p).Show()
else: else:
print _("Printer is not online.") print _("Printer is not online.")
if self.webInterface: if self.webInterface:
...@@ -419,61 +418,61 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -419,61 +418,61 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
self.menustrip = wx.MenuBar() self.menustrip = wx.MenuBar()
# File menu # File menu
m = wx.Menu() m = wx.Menu()
self.Bind(wx.EVT_MENU, self.loadfile, m.Append(-1,_("&Open..."),_(" Opens file"))) self.Bind(wx.EVT_MENU, self.loadfile, m.Append(-1, _("&Open..."), _(" Opens file")))
self.Bind(wx.EVT_MENU, self.do_editgcode, m.Append(-1,_("&Edit..."),_(" Edit open file"))) self.Bind(wx.EVT_MENU, self.do_editgcode, m.Append(-1, _("&Edit..."), _(" Edit open file")))
self.Bind(wx.EVT_MENU, self.clearOutput, m.Append(-1,_("Clear console"),_(" Clear output console"))) self.Bind(wx.EVT_MENU, self.clearOutput, m.Append(-1, _("Clear console"), _(" Clear output console")))
self.Bind(wx.EVT_MENU, self.project, m.Append(-1,_("Projector"),_(" Project slices"))) self.Bind(wx.EVT_MENU, self.project, m.Append(-1, _("Projector"), _(" Project slices")))
self.Bind(wx.EVT_MENU, self.OnExit, m.Append(wx.ID_EXIT,_("E&xit"),_(" Closes the Window"))) self.Bind(wx.EVT_MENU, self.OnExit, m.Append(wx.ID_EXIT, _("E&xit"), _(" Closes the Window")))
self.menustrip.Append(m,_("&File")) self.menustrip.Append(m, _("&File"))
# Settings menu # Settings menu
m = wx.Menu() m = wx.Menu()
self.macros_menu = wx.Menu() self.macros_menu = wx.Menu()
m.AppendSubMenu(self.macros_menu, _("&Macros")) m.AppendSubMenu(self.macros_menu, _("&Macros"))
self.Bind(wx.EVT_MENU, self.new_macro, self.macros_menu.Append(-1, _("<&New...>"))) self.Bind(wx.EVT_MENU, self.new_macro, self.macros_menu.Append(-1, _("<&New...>")))
self.Bind(wx.EVT_MENU, lambda *e:options(self), m.Append(-1,_("&Options"),_(" Options dialog"))) self.Bind(wx.EVT_MENU, lambda *e:options(self), m.Append(-1, _("&Options"),_(" Options dialog")))
self.Bind(wx.EVT_MENU, lambda x:threading.Thread(target=lambda :self.do_skein("set")).start(), m.Append(-1,_("Slicing Settings"),_(" Adjust slicing settings"))) self.Bind(wx.EVT_MENU, lambda x: threading.Thread(target = lambda:self.do_skein("set")).start(), m.Append(-1, _("Slicing Settings"), _(" Adjust slicing settings")))
self.menustrip.Append(m,_("&Settings")) self.menustrip.Append(m, _("&Settings"))
self.update_macros_menu() self.update_macros_menu()
self.SetMenuBar(self.menustrip) self.SetMenuBar(self.menustrip)
def doneediting(self,gcode): def doneediting(self, gcode):
f=open(self.filename,"w") f = open(self.filename, "w")
f.write("\n".join(gcode)) f.write("\n".join(gcode))
f.close() f.close()
wx.CallAfter(self.loadfile,None,self.filename) wx.CallAfter(self.loadfile, None, self.filename)
def do_editgcode(self,e=None): def do_editgcode(self, e = None):
if(self.filename is not None): if self.filename is not None:
macroed(self.filename,self.f,self.doneediting,1) macroed(self.filename, self.f, self.doneediting, 1)
def new_macro(self,e=None): def new_macro(self, e = None):
dialog = wx.Dialog(self,-1,_("Enter macro name"),size=(260,85)) dialog = wx.Dialog(self, -1, _("Enter macro name"), size = (260, 85))
panel = wx.Panel(dialog,-1) panel = wx.Panel(dialog, -1)
vbox = wx.BoxSizer(wx.VERTICAL) vbox = wx.BoxSizer(wx.VERTICAL)
wx.StaticText(panel,-1,_("Macro name:"),(8,14)) wx.StaticText(panel, -1, _("Macro name:"), (8, 14))
dialog.namectrl = wx.TextCtrl(panel,-1,'',(110,8),size=(130,24),style=wx.TE_PROCESS_ENTER) dialog.namectrl = wx.TextCtrl(panel, -1, '', (110, 8), size=(130, 24), style = wx.TE_PROCESS_ENTER)
hbox = wx.BoxSizer(wx.HORIZONTAL) hbox = wx.BoxSizer(wx.HORIZONTAL)
okb = wx.Button(dialog,wx.ID_OK,_("Ok"),size=(60,24)) okb = wx.Button(dialog, wx.ID_OK, _("Ok"), size = (60, 24))
dialog.Bind(wx.EVT_TEXT_ENTER,lambda e:dialog.EndModal(wx.ID_OK),dialog.namectrl) dialog.Bind(wx.EVT_TEXT_ENTER, lambda e:dialog.EndModal(wx.ID_OK), dialog.namectrl)
#dialog.Bind(wx.EVT_BUTTON,lambda e:self.new_macro_named(dialog,e),okb) #dialog.Bind(wx.EVT_BUTTON, lambda e:self.new_macro_named(dialog, e), okb)
hbox.Add(okb) hbox.Add(okb)
hbox.Add(wx.Button(dialog,wx.ID_CANCEL,_("Cancel"),size=(60,24))) hbox.Add(wx.Button(dialog, wx.ID_CANCEL, _("Cancel"), size = (60, 24)))
vbox.Add(panel) vbox.Add(panel)
vbox.Add(hbox,1,wx.ALIGN_CENTER|wx.TOP|wx.BOTTOM,10) vbox.Add(hbox, 1, wx.ALIGN_CENTER|wx.TOP|wx.BOTTOM, 10)
dialog.SetSizer(vbox) dialog.SetSizer(vbox)
dialog.Centre() dialog.Centre()
macro = "" macro = ""
if dialog.ShowModal()==wx.ID_OK: if dialog.ShowModal() == wx.ID_OK:
macro = dialog.namectrl.GetValue() macro = dialog.namectrl.GetValue()
if macro != "": if macro != "":
wx.CallAfter(self.edit_macro,macro) wx.CallAfter(self.edit_macro, macro)
dialog.Destroy() dialog.Destroy()
return macro return macro
def edit_macro(self,macro): def edit_macro(self, macro):
if macro == "": return self.new_macro() if macro == "": return self.new_macro()
if self.macros.has_key(macro): if self.macros.has_key(macro):
old_def = self.macros[macro] old_def = self.macros[macro]
...@@ -501,14 +500,14 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -501,14 +500,14 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
except: except:
pass pass
for macro in self.macros.keys(): for macro in self.macros.keys():
self.Bind(wx.EVT_MENU, lambda x,m=macro:self.start_macro(m,self.macros[m]), self.macros_menu.Append(-1, macro)) self.Bind(wx.EVT_MENU, lambda x, m = macro: self.start_macro(m, self.macros[m]), self.macros_menu.Append(-1, macro))
def OnExit(self, event): def OnExit(self, event):
self.Close() self.Close()
def rescanports(self,event=None): def rescanports(self, event = None):
scan=self.scanserial() scan = self.scanserial()
portslist=list(scan) portslist = list(scan)
if self.settings.port != "" and self.settings.port not in portslist: if self.settings.port != "" and self.settings.port not in portslist:
portslist += [self.settings.port] portslist += [self.settings.port]
self.serialport.Clear() self.serialport.Clear()
...@@ -516,7 +515,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): ...@@ -516,7 +515,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole):
try: try:
if os.path.exists(self.settings.port) or self.settings.port in scan: if os.path.exists(self.settings.port) or self.settings.port in scan:
self.serialport.SetValue(self.settings.port) self.serialport.SetValue(self.settings.port)
elif len(portslist)>0: elif len(portslist) > 0:
self.serialport.SetValue(portslist[0]) self.serialport.SetValue(portslist[0])
except: except:
pass pass
......
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