From e8daa864f7674c6e8ff3d5ed0e40bc933449a827 Mon Sep 17 00:00:00 2001 From: Keegi Date: Thu, 5 Jan 2012 19:56:00 +0200 Subject: [PATCH] Moved around and added back temperature gauges for hotend and bed. Hide auto-monitoring temp updates from text-box. --- pronterface.py | 102 +++++++++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 37 deletions(-) diff --git a/pronterface.py b/pronterface.py index 4415ae7..142708d 100755 --- a/pronterface.py +++ b/pronterface.py @@ -2,7 +2,7 @@ # Set up Internationalization using gettext # searching for installed locales on /usr/share; uses relative folder if not found (windows) -import os, gettext, Queue +import os, gettext, Queue, re if os.path.exists('/usr/share/pronterface/locale'): gettext.install('pronterface', '/usr/share/pronterface/locale', unicode=1) @@ -77,6 +77,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): self.panel=wx.Panel(self,-1,size=size) self.statuscheck=False + self.capture_skip=[] self.tempreport="" self.monitor=0 self.f=None @@ -209,7 +210,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): self.p.send_now("M104 S"+l) print _("Setting hotend temperature to "),f,_(" degrees Celsius.") self.hsetpoint=f - #self.tgauge.SetTarget(int(f)) + self.hottgauge.SetTarget(int(f)) if f>0: wx.CallAfter(self.htemp.SetValue,l) self.set("last_temperature",str(f)) @@ -245,6 +246,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): self.p.send_now("M140 S"+l) print _("Setting bed temperature to "),f,_(" degrees Celsius.") self.bsetpoint=f + self.bedtgauge.SetTarget(int(f)) if f>0: wx.CallAfter(self.btemp.SetValue,l) self.set("last_bed_temperature",str(f)) @@ -294,6 +296,10 @@ class PronterWindow(wx.Frame,pronsole.pronsole): pronsole.pronsole.start_macro(self,macro_name,old_macro_definition) def catchprint(self,l): + for pat in self.capture_skip: + if pat.match(l): + self.capture_skip.remove(pat) + return wx.CallAfter(self.logbox.AppendText,l) def scanserial(self): @@ -458,13 +464,6 @@ class PronterWindow(wx.Frame,pronsole.pronsole): uts.Add(self.resetbtn) self.minibtn=wx.Button(self.panel,-1,_("Mini mode")) self.minibtn.Bind(wx.EVT_BUTTON,self.toggleview) - #self.tgauge=TempGauge(self.panel,size=(300,24)) - #def scroll_setpoint(e): - # if e.GetWheelRotation()>0: - # self.do_settemp(str(self.hsetpoint+1)) - # elif e.GetWheelRotation()<0: - # self.do_settemp(str(max(0,self.hsetpoint-1))) - #self.tgauge.Bind(wx.EVT_MOUSEWHEEL,scroll_setpoint) uts.Add((25,-1)) self.monitorbox=wx.CheckBox(self.panel,-1,_("Monitor Printer")) @@ -473,7 +472,6 @@ class PronterWindow(wx.Frame,pronsole.pronsole): uts.Add((15,-1),flag=wx.EXPAND) uts.Add(self.minibtn,0,wx.ALIGN_CENTER) - #uts.Add(self.tgauge) #SECOND ROW ubs=self.upperbottomsizer=wx.BoxSizer(wx.HORIZONTAL) @@ -579,7 +577,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): self.setbbtn=wx.Button(self.panel,-1,_("Set"),size=(38,-1)) self.setbbtn.Bind(wx.EVT_BUTTON,self.do_bedtemp) self.printerControls.append(self.setbbtn) - lls.Add(self.setbbtn,pos=(4,4),span=(1,2)) + lls.Add(self.setbbtn,pos=(4,4),span=(1,1)) self.btemp.SetValue(str(self.settings.last_bed_temperature)) self.htemp.SetValue(str(self.settings.last_temperature)) @@ -603,7 +601,7 @@ class PronterWindow(wx.Frame,pronsole.pronsole): #lls.Add(self.btemp,pos=(4,1),span=(1,3)) #lls.Add(self.setbbtn,pos=(4,4),span=(1,2)) self.tempdisp=wx.StaticText(self.panel,-1,"") - lls.Add(self.tempdisp,pos=(4,6),span=(1,3)) + lls.Add(self.tempdisp,pos=(4,5),span=(1,3)) self.edist=wx.SpinCtrl(self.panel,-1,"5",min=0,max=1000,size=(60,-1)) self.edist.SetBackgroundColour((225,200,200)) @@ -622,17 +620,28 @@ class PronterWindow(wx.Frame,pronsole.pronsole): self.zfeedc.SetForegroundColour("black") # lls.Add((10,0),pos=(0,11),span=(1,1)) + self.hottgauge=TempGauge(self.panel,size=(300,24),title=_("Heater:"),maxval=230) + lls.Add(self.hottgauge,pos=(7,0),span=(1,8)) + self.bedtgauge=TempGauge(self.panel,size=(300,24),title=_("Bed:"),maxval=130) + lls.Add(self.bedtgauge,pos=(8,0),span=(1,8)) + #def scroll_setpoint(e): + # if e.GetWheelRotation()>0: + # self.do_settemp(str(self.hsetpoint+1)) + # elif e.GetWheelRotation()<0: + # self.do_settemp(str(max(0,self.hsetpoint-1))) + #self.tgauge.Bind(wx.EVT_MOUSEWHEEL,scroll_setpoint) + self.gviz=gviz.gviz(self.panel,(300,300), build_dimensions=self.build_dimensions_list, grid=(self.settings.preview_grid_step1,self.settings.preview_grid_step2), extrusion_width=self.settings.preview_extrusion_width) self.gviz.showall=1 - #try: - # - # import stlview - # self.gwindow=stlview.GCFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size=(600,600)) - #except: - self.gwindow=gviz.window([], + try: + raise "" + import stlview + self.gwindow=stlview.GCFrame(None, wx.ID_ANY, 'Gcode view, shift to move view, mousewheel to set layer', size=(600,600)) + except: + self.gwindow=gviz.window([], build_dimensions=self.build_dimensions_list, grid=(self.settings.preview_grid_step1,self.settings.preview_grid_step2), extrusion_width=self.settings.preview_extrusion_width) @@ -1125,10 +1134,11 @@ class PronterWindow(wx.Frame,pronsole.pronsole): pass string+=(self.tempreport.replace("\r","").replace("T",_("Hotend")).replace("B",_("Bed")).replace("\n","").replace("ok ",""))+" " wx.CallAfter(self.tempdisp.SetLabel,self.tempreport.strip().replace("ok ","")) - #try: - # self.tgauge.SetValue(int(filter(lambda x:x.startswith("T:"),self.tempreport.split())[0].split(":")[1])) - #except: - # pass + try: + self.hottgauge.SetValue(float(filter(lambda x:x.startswith("T:"),self.tempreport.split())[0].split(":")[1])) + self.bedtgauge.SetValue(float(filter(lambda x:x.startswith("B:"),self.tempreport.split())[0].split(":")[1])) + except: + pass fractioncomplete = 0.0 if self.sdprinting: fractioncomplete = float(self.percentdone/100.0) @@ -1150,6 +1160,8 @@ class PronterWindow(wx.Frame,pronsole.pronsole): if(self.monitor and self.p.online): if self.sdprinting: self.p.send_now("M27") + self.capture_skip.append(re.compile(r"ok T:[\d\.]+( B:[\d\.]+)?( @:[\d\.]+)?\s*")) + self.capture_skip.append(re.compile(r"\n")) self.p.send_now("M105") time.sleep(self.monitor_interval) while not self.sentlines.empty(): @@ -1184,10 +1196,11 @@ class PronterWindow(wx.Frame,pronsole.pronsole): if "T:" in l: self.tempreport=l wx.CallAfter(self.tempdisp.SetLabel,self.tempreport.strip().replace("ok ","")) - #try: - # self.tgauge.SetValue(int(filter(lambda x:x.startswith("T:"),self.tempreport.split())[0].split(":")[1])) - #except: - # pass + try: + self.hottgauge.SetValue(float(filter(lambda x:x.startswith("T:"),self.tempreport.split())[0].split(":")[1])) + self.bedtgauge.SetValue(float(filter(lambda x:x.startswith("B:"),self.tempreport.split())[0].split(":")[1])) + except: + pass tstring=l.rstrip() #print tstring if(tstring!="ok"): @@ -1587,7 +1600,6 @@ class macroed(wx.Dialog): def close(self,ev): self.Destroy() def unindent(self,text): - import re self.indent_chars = text[:len(text)-len(text.lstrip())] if len(self.indent_chars)==0: self.indent_chars=" " @@ -1603,7 +1615,6 @@ class macroed(wx.Dialog): unindented += line + "\n" return unindented def reindent(self,text): - import re lines = re.split(r"(?:\r\n?|\n)",text) if len(lines) <= 1: return text @@ -1690,18 +1701,21 @@ class ButtonEdit(wx.Dialog): self.name.SetValue(macro) class TempGauge(wx.Panel): - def __init__(self,parent,size=(200,22)): + def __init__(self,parent,size=(200,22),title="",maxval=240,gaugeColour=None): wx.Panel.__init__(self,parent,-1,size=size) self.Bind(wx.EVT_PAINT,self.paint) self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM) self.width,self.height=size + self.title=title + self.max=maxval + self.gaugeColour=gaugeColour self.value=0 self.setpoint=0 self.recalc() def recalc(self): - self.max=max(int(self.setpoint*1.05),240) - self.scale=float(self.width-2)/float(self.max) - self.ypt=int(self.scale*max(self.setpoint,40)) + mmax=max(int(self.setpoint*1.05),self.max) + self.scale=float(self.width-2)/float(mmax) + self.ypt=max(16,int(self.scale*max(self.setpoint,self.max/6))) def SetValue(self,value): self.value=value wx.CallAfter(self.Refresh) @@ -1709,13 +1723,24 @@ class TempGauge(wx.Panel): self.setpoint=value self.recalc() wx.CallAfter(self.Refresh) + def interpolatedColour(self,val,vmin,vmid,vmax,cmin,cmid,cmax): + if val < vmin: return cmin + if val > vmax: return cmax + if val <= vmid: + lo,hi,val,valhi = cmin,cmid,val-vmin,vmid-vmin + else: + lo,hi,val,valhi = cmid,cmax,val-vmid,vmax-vmid + vv = float(val)/valhi + rgb=lo.Red()+(hi.Red()-lo.Red())*vv,lo.Green()+(hi.Green()-lo.Green())*vv,lo.Blue()+(hi.Blue()-lo.Blue())*vv + rgb=map(lambda x:x*0.8,rgb) + return wx.Colour(*map(int,rgb)) def paint(self,ev): x0,y0,x1,y1,xE,yE = 1,1,self.ypt+1,1,self.width+1-2,20 dc=wx.PaintDC(self) dc.SetBackground(wx.Brush((255,255,255))) dc.Clear() cold,medium,hot = wx.Colour(0,167,223),wx.Colour(239,233,119),wx.Colour(210,50.100) - gauge1,gauge2 = wx.Colour(255,255,210),wx.Colour(234,82,0) + gauge1,gauge2 = wx.Colour(255,255,210),(self.gaugeColour or wx.Colour(234,82,0)) shadow1,shadow2 = wx.Colour(110,110,110),wx.Colour(255,255,255) gc = wx.GraphicsContext.Create(dc) # draw shadow first @@ -1737,12 +1762,13 @@ class TempGauge(wx.Panel): gc.SetBrush(gc.CreateLinearGradientBrush(x1-2,y1,xE,y1,medium,hot)) gc.DrawRoundedRectangle(x1-2,y1,xE-x1,yE,6) # draw gauge - gc.SetBrush(gc.CreateLinearGradientBrush(x0,y0+3,x0,y0+15,gauge1,gauge2)) - #gc.SetBrush(gc.CreateLinearGradientBrush(0,3,0,15,wx.Colour(255,255,255),wx.Colour(255,90,32))) width=12 w1=y0+9-width/2 w2=w1+width value=x0+max(10,min(self.width+1-2,int(self.value*self.scale))) + #gc.SetBrush(gc.CreateLinearGradientBrush(x0,y0+3,x0,y0+15,gauge1,gauge2)) + #gc.SetBrush(gc.CreateLinearGradientBrush(0,3,0,15,wx.Colour(255,255,255),wx.Colour(255,90,32))) + gc.SetBrush(gc.CreateLinearGradientBrush(x0,y0+3,x0,y0+15,gauge1,self.interpolatedColour(value,x0,x1,xE,cold,medium,hot))) val_path = gc.CreatePath() val_path.MoveToPoint(x0,w1) val_path.AddLineToPoint(value,w1) @@ -1768,9 +1794,11 @@ class TempGauge(wx.Panel): #gc.SetFont(gc.CreateFont(wx.Font(12,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_BOLD),wx.WHITE)) #gc.DrawText(text,29,-2) gc.SetFont(gc.CreateFont(wx.Font(10,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_BOLD),wx.WHITE)) - gc.DrawText(text,x0+31,y0+1) + gc.DrawText(self.title,x0+19,y0+1) + gc.DrawText(text, x0+153,y0+1) gc.SetFont(gc.CreateFont(wx.Font(10,wx.FONTFAMILY_DEFAULT,wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_BOLD))) - gc.DrawText(text,x0+30,y0+0) + gc.DrawText(self.title,x0+18,y0+0) + gc.DrawText(text, x0+152,y0+0) if __name__ == '__main__': app = wx.App(False)