2012-03-24 17:12:10 +00:00
from __future__ import absolute_import
import __init__
2012-10-11 15:00:29 +00:00
import wx , threading , re , subprocess , sys , os , time , platform
2012-04-19 15:35:08 +00:00
from wx . lib import buttons
2012-04-01 17:16:31 +00:00
2012-04-02 12:43:39 +00:00
from gui import icon
2012-06-01 10:14:20 +00:00
from gui import toolbarUtil
2012-09-02 12:27:24 +00:00
from gui import webcam
2012-10-10 10:23:53 +00:00
from gui import taskbar
2012-06-26 10:05:06 +00:00
from util import machineCom
2012-04-12 12:26:03 +00:00
from util import profile
2012-04-02 16:56:44 +00:00
from util import gcodeInterpreter
2012-11-20 08:32:34 +00:00
from util import power
2012-03-24 17:12:10 +00:00
2012-04-13 16:14:38 +00:00
printWindowMonitorHandle = None
2012-03-24 17:12:10 +00:00
def printFile ( filename ) :
2012-04-13 16:14:38 +00:00
global printWindowMonitorHandle
if printWindowMonitorHandle == None :
printWindowMonitorHandle = printProcessMonitor ( )
printWindowMonitorHandle . loadFile ( filename )
def startPrintInterface ( filename ) :
#startPrintInterface is called from the main script when we want the printer interface to run in a seperate process.
# It needs to run in a seperate process, as any running python code blocks the GCode sender pyton code (http://wiki.python.org/moin/GlobalInterpreterLock).
app = wx . App ( False )
printWindowHandle = printWindow ( )
2012-03-24 17:12:10 +00:00
printWindowHandle . Show ( True )
printWindowHandle . Raise ( )
2012-04-13 16:14:38 +00:00
printWindowHandle . OnConnect ( None )
2012-07-06 11:27:06 +00:00
t = threading . Thread ( target = printWindowHandle . LoadGCodeFile , args = ( filename , ) )
t . daemon = True
t . start ( )
2012-04-13 16:14:38 +00:00
app . MainLoop ( )
class printProcessMonitor ( ) :
def __init__ ( self ) :
self . handle = None
def loadFile ( self , filename ) :
2012-10-11 15:00:29 +00:00
if self . handle == None :
cmdList = [ sys . executable , sys . argv [ 0 ] , ' -r ' , filename ]
if platform . system ( ) == " Darwin " :
if platform . machine ( ) == ' i386 ' :
cmdList . insert ( 0 , ' arch ' )
cmdList . insert ( 1 , ' -i386 ' )
self . handle = subprocess . Popen ( cmdList , stdin = subprocess . PIPE , stdout = subprocess . PIPE , stderr = subprocess . PIPE )
2012-04-13 16:14:38 +00:00
self . thread = threading . Thread ( target = self . Monitor )
self . thread . start ( )
else :
self . handle . stdin . write ( filename + ' \n ' )
def Monitor ( self ) :
p = self . handle
line = p . stdout . readline ( )
while ( len ( line ) > 0 ) :
2012-10-01 15:51:15 +00:00
#print line.rstrip()
2012-04-13 16:14:38 +00:00
line = p . stdout . readline ( )
2012-10-11 15:00:29 +00:00
p . communicate ( )
2012-04-13 16:14:38 +00:00
self . handle = None
self . thread = None
2012-03-24 17:12:10 +00:00
2012-04-19 15:35:08 +00:00
class PrintCommandButton ( buttons . GenBitmapButton ) :
2012-10-03 13:11:35 +00:00
def __init__ ( self , parent , commandList , bitmapFilename , size = ( 20 , 20 ) ) :
2012-06-01 10:14:20 +00:00
self . bitmap = toolbarUtil . getBitmapImage ( bitmapFilename )
2012-04-19 15:35:08 +00:00
super ( PrintCommandButton , self ) . __init__ ( parent . directControlPanel , - 1 , self . bitmap , size = size )
2012-10-03 13:11:35 +00:00
self . commandList = commandList
2012-04-19 15:35:08 +00:00
self . parent = parent
self . SetBezelWidth ( 1 )
self . SetUseFocusIndicator ( False )
self . Bind ( wx . EVT_BUTTON , self . OnClick )
def OnClick ( self , e ) :
2012-09-06 14:52:05 +00:00
if self . parent . machineCom == None or self . parent . machineCom . isPrinting ( ) :
2012-07-19 12:38:31 +00:00
return ;
2012-10-03 13:11:35 +00:00
for cmd in self . commandList :
self . parent . machineCom . sendCommand ( cmd )
2012-04-19 15:35:08 +00:00
e . Skip ( )
2012-03-24 17:12:10 +00:00
class printWindow ( wx . Frame ) :
" Main user interface window "
def __init__ ( self ) :
super ( printWindow , self ) . __init__ ( None , - 1 , title = ' Printing ' )
2012-04-01 17:16:31 +00:00
self . machineCom = None
2012-04-03 10:06:02 +00:00
self . gcode = None
2012-04-01 17:16:31 +00:00
self . gcodeList = None
2012-04-04 15:02:22 +00:00
self . sendList = [ ]
self . temp = None
2012-06-26 10:05:06 +00:00
self . bedTemp = None
2012-04-01 17:16:31 +00:00
self . bufferLineCount = 4
self . sendCnt = 0
2012-06-26 13:42:56 +00:00
self . feedrateRatioOuterWall = 1.0
self . feedrateRatioInnerWall = 1.0
self . feedrateRatioFill = 1.0
self . feedrateRatioSupport = 1.0
2012-06-27 18:23:01 +00:00
self . pause = False
2012-07-06 11:27:06 +00:00
self . termHistory = [ ]
self . termHistoryIdx = 0
2012-09-02 12:27:24 +00:00
self . cam = None
2012-09-27 15:20:31 +00:00
if webcam . hasWebcamSupport ( ) :
2012-09-02 12:27:24 +00:00
self . cam = webcam . webcam ( )
2012-11-12 08:58:40 +00:00
if not self . cam . hasCamera ( ) :
self . cam = None
2012-04-02 12:43:39 +00:00
2012-04-03 08:44:53 +00:00
#self.SetIcon(icon.getMainIcon())
2012-04-01 17:16:31 +00:00
2012-03-28 18:36:46 +00:00
self . SetSizer ( wx . BoxSizer ( ) )
self . panel = wx . Panel ( self )
self . GetSizer ( ) . Add ( self . panel , 1 , flag = wx . EXPAND )
self . sizer = wx . GridBagSizer ( 2 , 2 )
self . panel . SetSizer ( self . sizer )
2012-03-24 17:12:10 +00:00
2012-03-28 18:36:46 +00:00
sb = wx . StaticBox ( self . panel , label = " Statistics " )
boxsizer = wx . StaticBoxSizer ( sb , wx . VERTICAL )
2012-11-20 08:32:34 +00:00
2012-11-20 09:23:47 +00:00
self . powerWarningText = wx . StaticText ( parent = self . panel ,
id = - 1 ,
2012-11-29 11:11:34 +00:00
label = " Your computer is running on battery power. \n Connect your computer to AC power or your print might not finish. " ,
2012-11-20 09:23:47 +00:00
style = wx . ALIGN_CENTER )
self . powerWarningText . SetBackgroundColour ( ' red ' )
self . powerWarningText . SetForegroundColour ( ' white ' )
boxsizer . AddF ( self . powerWarningText , flags = wx . SizerFlags ( ) . Expand ( ) . Border ( wx . BOTTOM , 10 ) )
self . powerManagement = power . PowerManagement ( )
self . powerWarningTimer = wx . Timer ( self )
self . Bind ( wx . EVT_TIMER , self . OnPowerWarningChange , self . powerWarningTimer )
self . OnPowerWarningChange ( None )
self . powerWarningTimer . Start ( 10000 )
2012-11-20 08:32:34 +00:00
2012-10-01 12:36:47 +00:00
self . statsText = wx . StaticText ( self . panel , - 1 , " Filament: ####.##m #.##g \n Estimated print time: #####:## \n Machine state: \n Detecting baudrateXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX " )
2012-04-02 16:56:44 +00:00
boxsizer . Add ( self . statsText , flag = wx . LEFT , border = 5 )
2012-03-24 17:12:10 +00:00
2012-10-15 10:35:14 +00:00
self . sizer . Add ( boxsizer , pos = ( 0 , 0 ) , span = ( 7 , 1 ) , flag = wx . EXPAND )
2012-03-28 18:36:46 +00:00
2012-04-03 18:27:46 +00:00
self . connectButton = wx . Button ( self . panel , - 1 , ' Connect ' )
2012-10-09 07:00:19 +00:00
#self.loadButton = wx.Button(self.panel, -1, 'Load')
self . printButton = wx . Button ( self . panel , - 1 , ' Print ' )
2012-06-27 18:23:01 +00:00
self . pauseButton = wx . Button ( self . panel , - 1 , ' Pause ' )
2012-04-01 17:16:31 +00:00
self . cancelButton = wx . Button ( self . panel , - 1 , ' Cancel print ' )
2012-10-01 11:47:16 +00:00
self . machineLogButton = wx . Button ( self . panel , - 1 , ' Error log ' )
2012-04-02 16:56:44 +00:00
self . progress = wx . Gauge ( self . panel , - 1 )
2012-04-04 15:02:22 +00:00
2012-10-15 10:35:14 +00:00
self . sizer . Add ( self . connectButton , pos = ( 1 , 1 ) , flag = wx . EXPAND )
#self.sizer.Add(self.loadButton, pos=(1,1), flag=wx.EXPAND)
self . sizer . Add ( self . printButton , pos = ( 2 , 1 ) , flag = wx . EXPAND )
self . sizer . Add ( self . pauseButton , pos = ( 3 , 1 ) , flag = wx . EXPAND )
self . sizer . Add ( self . cancelButton , pos = ( 4 , 1 ) , flag = wx . EXPAND )
self . sizer . Add ( self . machineLogButton , pos = ( 5 , 1 ) , flag = wx . EXPAND )
self . sizer . Add ( self . progress , pos = ( 7 , 0 ) , span = ( 1 , 7 ) , flag = wx . EXPAND )
2012-06-26 13:42:56 +00:00
nb = wx . Notebook ( self . panel )
2012-10-15 10:35:14 +00:00
self . sizer . Add ( nb , pos = ( 0 , 2 ) , span = ( 7 , 4 ) , flag = wx . EXPAND )
2012-04-19 15:35:08 +00:00
2012-06-26 13:42:56 +00:00
self . temperaturePanel = wx . Panel ( nb )
sizer = wx . GridBagSizer ( 2 , 2 )
self . temperaturePanel . SetSizer ( sizer )
self . temperatureSelect = wx . SpinCtrl ( self . temperaturePanel , - 1 , ' 0 ' , size = ( 21 * 3 , 21 ) , style = wx . SP_ARROW_KEYS )
self . temperatureSelect . SetRange ( 0 , 400 )
self . bedTemperatureLabel = wx . StaticText ( self . temperaturePanel , - 1 , " BedTemp: " )
self . bedTemperatureSelect = wx . SpinCtrl ( self . temperaturePanel , - 1 , ' 0 ' , size = ( 21 * 3 , 21 ) , style = wx . SP_ARROW_KEYS )
self . bedTemperatureSelect . SetRange ( 0 , 400 )
self . bedTemperatureLabel . Show ( False )
self . bedTemperatureSelect . Show ( False )
2012-04-19 15:35:08 +00:00
2012-07-10 15:04:37 +00:00
self . temperatureGraph = temperatureGraph ( self . temperaturePanel )
2012-06-26 13:42:56 +00:00
sizer . Add ( wx . StaticText ( self . temperaturePanel , - 1 , " Temp: " ) , pos = ( 0 , 0 ) )
sizer . Add ( self . temperatureSelect , pos = ( 0 , 1 ) )
sizer . Add ( self . bedTemperatureLabel , pos = ( 1 , 0 ) )
sizer . Add ( self . bedTemperatureSelect , pos = ( 1 , 1 ) )
2012-07-10 15:04:37 +00:00
sizer . Add ( self . temperatureGraph , pos = ( 2 , 0 ) , span = ( 1 , 2 ) , flag = wx . EXPAND )
sizer . AddGrowableRow ( 2 )
2012-10-01 11:47:16 +00:00
sizer . AddGrowableCol ( 1 )
2012-06-26 13:42:56 +00:00
nb . AddPage ( self . temperaturePanel , ' Temp ' )
self . directControlPanel = wx . Panel ( nb )
2012-04-19 15:35:08 +00:00
sizer = wx . GridBagSizer ( 2 , 2 )
self . directControlPanel . SetSizer ( sizer )
2012-10-03 13:11:35 +00:00
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 Y100 F6000 ' , ' G90 ' ] , ' print-move-y100.png ' ) , pos = ( 0 , 3 ) )
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 Y10 F6000 ' , ' G90 ' ] , ' print-move-y10.png ' ) , pos = ( 1 , 3 ) )
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 Y1 F6000 ' , ' G90 ' ] , ' print-move-y1.png ' ) , pos = ( 2 , 3 ) )
2012-04-19 15:35:08 +00:00
2012-10-03 13:11:35 +00:00
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 Y-1 F6000 ' , ' G90 ' ] , ' print-move-y-1.png ' ) , pos = ( 4 , 3 ) )
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 Y-10 F6000 ' , ' G90 ' ] , ' print-move-y-10.png ' ) , pos = ( 5 , 3 ) )
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 Y-100 F6000 ' , ' G90 ' ] , ' print-move-y-100.png ' ) , pos = ( 6 , 3 ) )
2012-04-19 15:35:08 +00:00
2012-10-03 13:11:35 +00:00
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 X-100 F6000 ' , ' G90 ' ] , ' print-move-x-100.png ' ) , pos = ( 3 , 0 ) )
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 X-10 F6000 ' , ' G90 ' ] , ' print-move-x-10.png ' ) , pos = ( 3 , 1 ) )
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 X-1 F6000 ' , ' G90 ' ] , ' print-move-x-1.png ' ) , pos = ( 3 , 2 ) )
2012-04-19 15:35:08 +00:00
2012-10-03 13:11:35 +00:00
sizer . Add ( PrintCommandButton ( self , [ ' G28 X0 Y0 ' ] , ' print-move-home.png ' ) , pos = ( 3 , 3 ) )
2012-05-10 19:29:42 +00:00
2012-10-03 13:11:35 +00:00
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 X1 F6000 ' , ' G90 ' ] , ' print-move-x1.png ' ) , pos = ( 3 , 4 ) )
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 X10 F6000 ' , ' G90 ' ] , ' print-move-x10.png ' ) , pos = ( 3 , 5 ) )
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 X100 F6000 ' , ' G90 ' ] , ' print-move-x100.png ' ) , pos = ( 3 , 6 ) )
2012-04-19 15:35:08 +00:00
2012-10-03 13:11:35 +00:00
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 Z10 F200 ' , ' G90 ' ] , ' print-move-z10.png ' ) , pos = ( 0 , 8 ) )
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 Z1 F200 ' , ' G90 ' ] , ' print-move-z1.png ' ) , pos = ( 1 , 8 ) )
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 Z0.1 F200 ' , ' G90 ' ] , ' print-move-z0.1.png ' ) , pos = ( 2 , 8 ) )
2012-04-19 15:35:08 +00:00
2012-10-03 13:11:35 +00:00
sizer . Add ( PrintCommandButton ( self , [ ' G28 Z0 ' ] , ' print-move-home.png ' ) , pos = ( 3 , 8 ) )
2012-05-11 08:14:25 +00:00
2012-10-03 13:11:35 +00:00
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 Z-0.1 F200 ' , ' G90 ' ] , ' print-move-z-0.1.png ' ) , pos = ( 4 , 8 ) )
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 Z-1 F200 ' , ' G90 ' ] , ' print-move-z-1.png ' ) , pos = ( 5 , 8 ) )
sizer . Add ( PrintCommandButton ( self , [ ' G91 ' , ' G1 Z-10 F200 ' , ' G90 ' ] , ' print-move-z-10.png ' ) , pos = ( 6 , 8 ) )
2012-10-04 12:05:09 +00:00
sizer . Add ( PrintCommandButton ( self , [ ' G92 E0 ' , ' G1 E2 F120 ' ] , ' extrude.png ' , size = ( 60 , 20 ) ) , pos = ( 1 , 10 ) , span = ( 1 , 3 ) , flag = wx . EXPAND )
sizer . Add ( PrintCommandButton ( self , [ ' G92 E0 ' , ' G1 E-2 F120 ' ] , ' retract.png ' , size = ( 60 , 20 ) ) , pos = ( 2 , 10 ) , span = ( 1 , 3 ) , flag = wx . EXPAND )
2012-04-04 15:02:22 +00:00
2012-06-26 13:42:56 +00:00
nb . AddPage ( self . directControlPanel , ' Jog ' )
self . speedPanel = wx . Panel ( nb )
sizer = wx . GridBagSizer ( 2 , 2 )
self . speedPanel . SetSizer ( sizer )
self . outerWallSpeedSelect = wx . SpinCtrl ( self . speedPanel , - 1 , ' 100 ' , size = ( 21 * 3 , 21 ) , style = wx . SP_ARROW_KEYS )
self . outerWallSpeedSelect . SetRange ( 5 , 1000 )
self . innerWallSpeedSelect = wx . SpinCtrl ( self . speedPanel , - 1 , ' 100 ' , size = ( 21 * 3 , 21 ) , style = wx . SP_ARROW_KEYS )
self . innerWallSpeedSelect . SetRange ( 5 , 1000 )
self . fillSpeedSelect = wx . SpinCtrl ( self . speedPanel , - 1 , ' 100 ' , size = ( 21 * 3 , 21 ) , style = wx . SP_ARROW_KEYS )
self . fillSpeedSelect . SetRange ( 5 , 1000 )
self . supportSpeedSelect = wx . SpinCtrl ( self . speedPanel , - 1 , ' 100 ' , size = ( 21 * 3 , 21 ) , style = wx . SP_ARROW_KEYS )
self . supportSpeedSelect . SetRange ( 5 , 1000 )
sizer . Add ( wx . StaticText ( self . speedPanel , - 1 , " Outer wall: " ) , pos = ( 0 , 0 ) )
sizer . Add ( self . outerWallSpeedSelect , pos = ( 0 , 1 ) )
sizer . Add ( wx . StaticText ( self . speedPanel , - 1 , " % " ) , pos = ( 0 , 2 ) )
sizer . Add ( wx . StaticText ( self . speedPanel , - 1 , " Inner wall: " ) , pos = ( 1 , 0 ) )
sizer . Add ( self . innerWallSpeedSelect , pos = ( 1 , 1 ) )
sizer . Add ( wx . StaticText ( self . speedPanel , - 1 , " % " ) , pos = ( 1 , 2 ) )
sizer . Add ( wx . StaticText ( self . speedPanel , - 1 , " Fill: " ) , pos = ( 2 , 0 ) )
sizer . Add ( self . fillSpeedSelect , pos = ( 2 , 1 ) )
sizer . Add ( wx . StaticText ( self . speedPanel , - 1 , " % " ) , pos = ( 2 , 2 ) )
sizer . Add ( wx . StaticText ( self . speedPanel , - 1 , " Support: " ) , pos = ( 3 , 0 ) )
sizer . Add ( self . supportSpeedSelect , pos = ( 3 , 1 ) )
sizer . Add ( wx . StaticText ( self . speedPanel , - 1 , " % " ) , pos = ( 3 , 2 ) )
nb . AddPage ( self . speedPanel , ' Speed ' )
2012-07-06 11:27:06 +00:00
self . termPanel = wx . Panel ( nb )
sizer = wx . GridBagSizer ( 2 , 2 )
self . termPanel . SetSizer ( sizer )
f = wx . Font ( 8 , wx . FONTFAMILY_MODERN , wx . FONTSTYLE_NORMAL , wx . FONTWEIGHT_NORMAL , False )
self . termLog = wx . TextCtrl ( self . termPanel , style = wx . TE_MULTILINE | wx . TE_DONTWRAP )
self . termLog . SetFont ( f )
self . termLog . SetEditable ( 0 )
self . termInput = wx . TextCtrl ( self . termPanel , style = wx . TE_PROCESS_ENTER )
self . termInput . SetFont ( f )
sizer . Add ( self . termLog , pos = ( 0 , 0 ) , flag = wx . EXPAND )
sizer . Add ( self . termInput , pos = ( 1 , 0 ) , flag = wx . EXPAND )
sizer . AddGrowableCol ( 0 )
sizer . AddGrowableRow ( 0 )
nb . AddPage ( self . termPanel , ' Term ' )
2012-09-02 12:27:24 +00:00
2012-11-12 08:58:40 +00:00
if self . cam != None :
2012-09-02 12:27:24 +00:00
self . camPage = wx . Panel ( nb )
sizer = wx . GridBagSizer ( 2 , 2 )
self . camPage . SetSizer ( sizer )
2012-10-01 12:36:47 +00:00
self . timelapsEnable = wx . CheckBox ( self . camPage , - 1 , ' Enable timelaps movie recording ' )
2012-10-01 09:45:18 +00:00
sizer . Add ( self . timelapsEnable , pos = ( 0 , 0 ) , span = ( 1 , 2 ) , flag = wx . EXPAND )
pages = self . cam . propertyPages ( )
2012-10-03 13:11:35 +00:00
self . cam . buttons = [ self . timelapsEnable ]
2012-10-01 09:45:18 +00:00
for page in pages :
button = wx . Button ( self . camPage , - 1 , page )
button . index = pages . index ( page )
sizer . Add ( button , pos = ( 1 , pages . index ( page ) ) )
button . Bind ( wx . EVT_BUTTON , self . OnPropertyPageButton )
2012-10-03 13:11:35 +00:00
self . cam . buttons . append ( button )
2012-10-05 14:25:15 +00:00
self . campreviewEnable = wx . CheckBox ( self . camPage , - 1 , ' Show preview ' )
sizer . Add ( self . campreviewEnable , pos = ( 2 , 0 ) , span = ( 1 , 2 ) , flag = wx . EXPAND )
2012-10-01 09:45:18 +00:00
2012-09-27 15:20:31 +00:00
self . camPreview = wx . Panel ( self . camPage )
2012-10-05 14:25:15 +00:00
sizer . Add ( self . camPreview , pos = ( 3 , 0 ) , span = ( 1 , 2 ) , flag = wx . EXPAND )
2012-09-27 15:20:31 +00:00
2012-09-02 12:27:24 +00:00
nb . AddPage ( self . camPage , ' Camera ' )
2012-09-27 15:20:31 +00:00
self . camPreview . timer = wx . Timer ( self )
self . Bind ( wx . EVT_TIMER , self . OnCameraTimer , self . camPreview . timer )
self . camPreview . timer . Start ( 500 )
self . camPreview . Bind ( wx . EVT_ERASE_BACKGROUND , self . OnCameraEraseBackground )
2012-06-26 13:42:56 +00:00
2012-11-27 13:08:00 +00:00
self . sizer . AddGrowableRow ( 6 )
2012-09-02 12:27:24 +00:00
self . sizer . AddGrowableCol ( 3 )
2012-03-24 17:12:10 +00:00
self . Bind ( wx . EVT_CLOSE , self . OnClose )
2012-04-03 18:27:46 +00:00
self . connectButton . Bind ( wx . EVT_BUTTON , self . OnConnect )
2012-04-03 15:01:51 +00:00
#self.loadButton.Bind(wx.EVT_BUTTON, self.OnLoad)
2012-04-01 17:16:31 +00:00
self . printButton . Bind ( wx . EVT_BUTTON , self . OnPrint )
2012-06-27 18:23:01 +00:00
self . pauseButton . Bind ( wx . EVT_BUTTON , self . OnPause )
2012-04-01 17:16:31 +00:00
self . cancelButton . Bind ( wx . EVT_BUTTON , self . OnCancel )
2012-10-01 11:47:16 +00:00
self . machineLogButton . Bind ( wx . EVT_BUTTON , self . OnMachineLog )
2012-03-24 17:12:10 +00:00
2012-04-04 15:02:22 +00:00
self . Bind ( wx . EVT_SPINCTRL , self . OnTempChange , self . temperatureSelect )
2012-06-26 10:05:06 +00:00
self . Bind ( wx . EVT_SPINCTRL , self . OnBedTempChange , self . bedTemperatureSelect )
2012-06-26 13:42:56 +00:00
self . Bind ( wx . EVT_SPINCTRL , self . OnSpeedChange , self . outerWallSpeedSelect )
self . Bind ( wx . EVT_SPINCTRL , self . OnSpeedChange , self . innerWallSpeedSelect )
self . Bind ( wx . EVT_SPINCTRL , self . OnSpeedChange , self . fillSpeedSelect )
self . Bind ( wx . EVT_SPINCTRL , self . OnSpeedChange , self . supportSpeedSelect )
2012-07-06 11:27:06 +00:00
self . Bind ( wx . EVT_TEXT_ENTER , self . OnTermEnterLine , self . termInput )
self . termInput . Bind ( wx . EVT_CHAR , self . OnTermKey )
2012-04-04 15:02:22 +00:00
2012-03-24 17:12:10 +00:00
self . Layout ( )
self . Fit ( )
self . Centre ( )
2012-10-01 11:47:16 +00:00
self . statsText . SetMinSize ( self . statsText . GetSize ( ) )
2012-10-15 09:58:00 +00:00
2012-04-02 16:56:44 +00:00
self . UpdateButtonStates ( )
2012-09-06 14:52:05 +00:00
#self.UpdateProgress()
2012-04-02 16:56:44 +00:00
2012-09-02 12:27:24 +00:00
def OnCameraTimer ( self , e ) :
2012-10-05 14:25:15 +00:00
if not self . campreviewEnable . GetValue ( ) :
return
2012-10-01 09:45:18 +00:00
if self . machineCom != None and self . machineCom . isPrinting ( ) :
2012-09-02 12:27:24 +00:00
return
self . cam . takeNewImage ( )
2012-09-27 15:20:31 +00:00
self . camPreview . Refresh ( )
2012-09-02 12:27:24 +00:00
def OnCameraEraseBackground ( self , e ) :
dc = e . GetDC ( )
if not dc :
dc = wx . ClientDC ( self )
rect = self . GetUpdateRegion ( ) . GetBox ( )
dc . SetClippingRect ( rect )
2012-09-27 15:20:31 +00:00
dc . SetBackground ( wx . Brush ( self . camPreview . GetBackgroundColour ( ) , wx . SOLID ) )
2012-09-02 12:27:24 +00:00
if self . cam . getLastImage ( ) != None :
2012-10-01 09:45:18 +00:00
self . camPreview . SetMinSize ( ( self . cam . getLastImage ( ) . GetWidth ( ) , self . cam . getLastImage ( ) . GetHeight ( ) ) )
self . camPage . Fit ( )
2012-09-02 12:27:24 +00:00
dc . DrawBitmap ( self . cam . getLastImage ( ) , 0 , 0 )
2012-10-01 09:45:18 +00:00
else :
dc . Clear ( )
def OnPropertyPageButton ( self , e ) :
self . cam . openPropertyPage ( e . GetEventObject ( ) . index )
2012-09-02 12:27:24 +00:00
2012-04-02 16:56:44 +00:00
def UpdateButtonStates ( self ) :
2012-09-06 14:52:05 +00:00
self . connectButton . Enable ( self . machineCom == None or self . machineCom . isClosedOrError ( ) )
2012-09-07 10:04:55 +00:00
#self.loadButton.Enable(self.machineCom == None or not (self.machineCom.isPrinting() or self.machineCom.isPaused()))
self . printButton . Enable ( self . machineCom != None and self . machineCom . isOperational ( ) and not ( self . machineCom . isPrinting ( ) or self . machineCom . isPaused ( ) ) )
self . pauseButton . Enable ( self . machineCom != None and ( self . machineCom . isPrinting ( ) or self . machineCom . isPaused ( ) ) )
if self . machineCom != None and self . machineCom . isPaused ( ) :
self . pauseButton . SetLabel ( ' Resume ' )
else :
self . pauseButton . SetLabel ( ' Pause ' )
self . cancelButton . Enable ( self . machineCom != None and ( self . machineCom . isPrinting ( ) or self . machineCom . isPaused ( ) ) )
2012-09-06 14:52:05 +00:00
self . temperatureSelect . Enable ( self . machineCom != None and self . machineCom . isOperational ( ) )
self . bedTemperatureSelect . Enable ( self . machineCom != None and self . machineCom . isOperational ( ) )
2012-10-02 08:58:57 +00:00
self . directControlPanel . Enable ( self . machineCom != None and self . machineCom . isOperational ( ) and not self . machineCom . isPrinting ( ) )
2012-10-28 10:23:21 +00:00
self . machineLogButton . Show ( self . machineCom != None and self . machineCom . isClosedOrError ( ) )
2012-11-12 08:58:40 +00:00
if self . cam != None :
2012-10-03 13:11:35 +00:00
for button in self . cam . buttons :
button . Enable ( self . machineCom == None or not self . machineCom . isPrinting ( ) )
2012-04-02 16:56:44 +00:00
def UpdateProgress ( self ) :
status = " "
2012-07-06 11:27:06 +00:00
if self . gcode == None :
status + = " Loading gcode... \n "
else :
2012-04-03 10:06:02 +00:00
status + = " Filament: %.2f m %.2f g \n " % ( self . gcode . extrusionAmount / 1000 , self . gcode . calculateWeight ( ) * 1000 )
2012-04-29 10:00:13 +00:00
cost = self . gcode . calculateCost ( )
if cost != False :
status + = " Filament cost: %s \n " % ( cost )
2012-10-01 12:36:47 +00:00
status + = " Estimated print time: %02d : %02d \n " % ( int ( self . gcode . totalMoveTimeMinute / 60 ) , int ( self . gcode . totalMoveTimeMinute % 60 ) )
2012-09-06 14:52:05 +00:00
if self . machineCom == None or not self . machineCom . isPrinting ( ) :
2012-04-02 16:56:44 +00:00
self . progress . SetValue ( 0 )
2012-04-03 10:06:02 +00:00
if self . gcodeList != None :
status + = ' Line: -/ %d \n ' % ( len ( self . gcodeList ) )
2012-04-02 16:56:44 +00:00
else :
2012-10-01 12:51:59 +00:00
printTime = self . machineCom . getPrintTime ( ) / 60
2012-10-04 13:01:54 +00:00
printTimeLeft = self . machineCom . getPrintTimeRemainingEstimate ( )
2012-10-02 08:58:57 +00:00
status + = ' Line: %d / %d %d %% \n ' % ( self . machineCom . getPrintPos ( ) , len ( self . gcodeList ) , self . machineCom . getPrintPos ( ) * 100 / len ( self . gcodeList ) )
if self . currentZ > 0 :
status + = ' Height: %0.1f \n ' % ( self . currentZ )
2012-10-01 12:51:59 +00:00
status + = ' Print time: %02d : %02d \n ' % ( int ( printTime / 60 ) , int ( printTime % 60 ) )
2012-10-04 13:01:54 +00:00
if printTimeLeft == None :
2012-10-02 14:06:47 +00:00
status + = ' Print time left: Unknown \n '
else :
status + = ' Print time left: %02d : %02d \n ' % ( int ( printTimeLeft / 60 ) , int ( printTimeLeft % 60 ) )
2012-09-06 14:52:05 +00:00
self . progress . SetValue ( self . machineCom . getPrintPos ( ) )
2012-10-10 10:23:53 +00:00
taskbar . setProgress ( self , self . machineCom . getPrintPos ( ) , len ( self . gcodeList ) )
2012-09-06 14:52:05 +00:00
if self . machineCom != None :
if self . machineCom . getTemp ( ) > 0 :
status + = ' Temp: %d \n ' % ( self . machineCom . getTemp ( ) )
if self . machineCom . getBedTemp ( ) > 0 :
status + = ' Bed Temp: %d \n ' % ( self . machineCom . getBedTemp ( ) )
self . bedTemperatureLabel . Show ( True )
self . bedTemperatureSelect . Show ( True )
self . temperaturePanel . Layout ( )
2012-10-01 09:45:18 +00:00
status + = ' Machine state: %s \n ' % ( self . machineCom . getStateString ( ) )
2012-09-06 14:52:05 +00:00
2012-04-11 21:49:09 +00:00
self . statsText . SetLabel ( status . strip ( ) )
2012-03-24 17:12:10 +00:00
2012-04-01 17:16:31 +00:00
def OnConnect ( self , e ) :
if self . machineCom != None :
self . machineCom . close ( )
2012-09-06 14:52:05 +00:00
self . machineCom = machineCom . MachineCom ( callbackObject = self )
2012-04-02 16:56:44 +00:00
self . UpdateButtonStates ( )
2012-10-10 10:23:53 +00:00
taskbar . setBusy ( self , True )
2012-04-01 17:16:31 +00:00
def OnLoad ( self , e ) :
pass
def OnPrint ( self , e ) :
2012-09-06 14:52:05 +00:00
if self . machineCom == None or not self . machineCom . isOperational ( ) :
2012-04-01 17:16:31 +00:00
return
if self . gcodeList == None :
return
2012-09-06 14:52:05 +00:00
if self . machineCom . isPrinting ( ) :
2012-04-01 17:16:31 +00:00
return
2012-09-02 12:27:24 +00:00
self . currentZ = - 1
2012-10-01 09:45:18 +00:00
if self . cam != None and self . timelapsEnable . GetValue ( ) :
2012-09-02 12:27:24 +00:00
self . cam . startTimelaps ( self . filename [ : self . filename . rfind ( ' . ' ) ] + " .mpg " )
2012-09-06 14:52:05 +00:00
self . machineCom . printGCode ( self . gcodeList )
2012-04-02 16:56:44 +00:00
self . UpdateButtonStates ( )
2012-04-01 17:16:31 +00:00
def OnCancel ( self , e ) :
2012-06-27 18:23:01 +00:00
self . pauseButton . SetLabel ( ' Pause ' )
2012-09-06 14:52:05 +00:00
self . machineCom . cancelPrint ( )
self . machineCom . sendCommand ( " M84 " )
2012-04-02 16:56:44 +00:00
self . UpdateButtonStates ( )
2012-04-01 17:16:31 +00:00
2012-06-27 18:23:01 +00:00
def OnPause ( self , e ) :
2012-09-06 14:52:05 +00:00
if self . machineCom . isPaused ( ) :
self . machineCom . setPause ( False )
2012-06-27 18:23:01 +00:00
else :
2012-09-06 14:52:05 +00:00
self . machineCom . setPause ( True )
2012-06-27 18:23:01 +00:00
2012-10-01 11:47:16 +00:00
def OnMachineLog ( self , e ) :
LogWindow ( ' \n ' . join ( self . machineCom . getLog ( ) ) )
2012-03-24 17:12:10 +00:00
def OnClose ( self , e ) :
global printWindowHandle
printWindowHandle = None
2012-04-01 17:16:31 +00:00
if self . machineCom != None :
self . machineCom . close ( )
2012-03-24 17:12:10 +00:00
self . Destroy ( )
2012-04-01 17:16:31 +00:00
2012-04-04 15:02:22 +00:00
def OnTempChange ( self , e ) :
2012-09-06 14:52:05 +00:00
self . machineCom . sendCommand ( " M104 S %d " % ( self . temperatureSelect . GetValue ( ) ) )
2012-04-04 15:02:22 +00:00
2012-06-26 10:05:06 +00:00
def OnBedTempChange ( self , e ) :
2012-09-06 14:52:05 +00:00
self . machineCom . sendCommand ( " M140 S %d " % ( self . bedTemperatureSelect . GetValue ( ) ) )
2012-06-26 13:42:56 +00:00
def OnSpeedChange ( self , e ) :
2012-09-07 10:04:55 +00:00
if self . machineCom == None :
return
self . machineCom . setFeedrateModifier ( ' WALL-OUTER ' , self . outerWallSpeedSelect . GetValue ( ) / 100.0 )
self . machineCom . setFeedrateModifier ( ' WALL-INNER ' , self . innerWallSpeedSelect . GetValue ( ) / 100.0 )
self . machineCom . setFeedrateModifier ( ' FILL ' , self . fillSpeedSelect . GetValue ( ) / 100.0 )
self . machineCom . setFeedrateModifier ( ' SUPPORT ' , self . supportSpeedSelect . GetValue ( ) / 100.0 )
2012-07-06 11:27:06 +00:00
def AddTermLog ( self , line ) :
2012-07-19 12:27:59 +00:00
self . termLog . AppendText ( unicode ( line , ' utf-8 ' , ' replace ' ) )
2012-10-01 09:45:18 +00:00
l = len ( self . termLog . GetValue ( ) )
self . termLog . SetCaret ( wx . Caret ( self . termLog , ( l , l ) ) )
2012-07-06 11:27:06 +00:00
def OnTermEnterLine ( self , e ) :
line = self . termInput . GetValue ( )
if line == ' ' :
return
self . termLog . AppendText ( ' > %s \n ' % ( line ) )
2012-09-06 14:52:05 +00:00
self . machineCom . sendCommand ( line )
2012-07-06 11:27:06 +00:00
self . termHistory . append ( line )
self . termHistoryIdx = len ( self . termHistory )
self . termInput . SetValue ( ' ' )
def OnTermKey ( self , e ) :
if len ( self . termHistory ) > 0 :
if e . GetKeyCode ( ) == wx . WXK_UP :
self . termHistoryIdx = self . termHistoryIdx - 1
if self . termHistoryIdx < 0 :
self . termHistoryIdx = len ( self . termHistory ) - 1
self . termInput . SetValue ( self . termHistory [ self . termHistoryIdx ] )
if e . GetKeyCode ( ) == wx . WXK_DOWN :
self . termHistoryIdx = self . termHistoryIdx - 1
if self . termHistoryIdx > = len ( self . termHistory ) :
self . termHistoryIdx = 0
self . termInput . SetValue ( self . termHistory [ self . termHistoryIdx ] )
e . Skip ( )
2012-06-26 10:05:06 +00:00
2012-11-20 09:25:13 +00:00
def OnPowerWarningChange ( self , e ) :
type = self . powerManagement . get_providing_power_source_type ( )
if type == power . POWER_TYPE_AC and self . powerWarningText . IsShown ( ) :
self . powerWarningText . Hide ( )
2012-11-27 12:15:32 +00:00
self . panel . Layout ( )
2012-11-20 09:25:13 +00:00
self . Layout ( )
elif type != power . POWER_TYPE_AC and not self . powerWarningText . IsShown ( ) :
self . powerWarningText . Show ( )
2012-11-27 12:15:32 +00:00
self . panel . Layout ( )
2012-11-20 09:25:13 +00:00
self . Layout ( )
2012-04-01 17:16:31 +00:00
def LoadGCodeFile ( self , filename ) :
2012-09-06 14:52:05 +00:00
if self . machineCom != None and self . machineCom . isPrinting ( ) :
2012-04-03 15:01:51 +00:00
return
2012-04-04 15:02:22 +00:00
#Send an initial M110 to reset the line counter to zero.
2012-09-07 10:04:55 +00:00
prevLineType = lineType = ' CUSTOM '
2012-04-01 17:16:31 +00:00
gcodeList = [ " M110 " ]
for line in open ( filename , ' r ' ) :
2012-06-26 13:42:56 +00:00
if line . startswith ( ' ;TYPE: ' ) :
lineType = line [ 6 : ] . strip ( )
2012-04-01 17:16:31 +00:00
if ' ; ' in line :
line = line [ 0 : line . find ( ' ; ' ) ]
line = line . strip ( )
if len ( line ) > 0 :
2012-09-07 10:04:55 +00:00
if prevLineType != lineType :
gcodeList . append ( ( line , lineType , ) )
else :
gcodeList . append ( line )
prevLineType = lineType
2012-04-02 16:56:44 +00:00
gcode = gcodeInterpreter . gcode ( )
gcode . loadList ( gcodeList )
2012-10-01 15:51:15 +00:00
#print "Loaded: %s (%d)" % (filename, len(gcodeList))
2012-09-02 12:27:24 +00:00
self . filename = filename
2012-04-03 10:06:02 +00:00
self . gcode = gcode
2012-04-01 17:16:31 +00:00
self . gcodeList = gcodeList
2012-07-06 11:27:06 +00:00
wx . CallAfter ( self . progress . SetRange , len ( gcodeList ) )
wx . CallAfter ( self . UpdateButtonStates )
wx . CallAfter ( self . UpdateProgress )
2012-10-03 13:11:35 +00:00
wx . CallAfter ( self . SetTitle , ' Printing: %s ' % ( filename ) )
2012-04-04 15:02:22 +00:00
2012-04-01 17:16:31 +00:00
def sendLine ( self , lineNr ) :
if lineNr > = len ( self . gcodeList ) :
2012-04-03 10:06:02 +00:00
return False
2012-06-26 13:42:56 +00:00
line = self . gcodeList [ lineNr ]
2012-07-10 15:04:37 +00:00
try :
if ( ' M104 ' in line or ' M109 ' in line ) and ' S ' in line :
n = int ( re . search ( ' S([0-9]*) ' , line ) . group ( 1 ) )
wx . CallAfter ( self . temperatureSelect . SetValue , n )
if ( ' M140 ' in line or ' M190 ' in line ) and ' S ' in line :
n = int ( re . search ( ' S([0-9]*) ' , line ) . group ( 1 ) )
wx . CallAfter ( self . bedTemperatureSelect . SetValue , n )
except :
print " Unexpected error: " , sys . exc_info ( )
2012-06-26 13:42:56 +00:00
checksum = reduce ( lambda x , y : x ^ y , map ( ord , " N %d %s " % ( lineNr , line ) ) )
self . machineCom . sendCommand ( " N %d %s * %d " % ( lineNr , line , checksum ) )
2012-04-03 10:06:02 +00:00
return True
2012-04-01 17:16:31 +00:00
2012-09-06 14:52:05 +00:00
def mcLog ( self , message ) :
2012-10-01 15:51:15 +00:00
#print message
pass
2012-09-06 14:52:05 +00:00
2012-10-03 13:11:35 +00:00
def mcTempUpdate ( self , temp , bedTemp , targetTemp , bedTargetTemp ) :
self . temperatureGraph . addPoint ( temp , targetTemp , bedTemp , bedTargetTemp )
if self . temperatureSelect . GetValue ( ) != targetTemp :
wx . CallAfter ( self . temperatureSelect . SetValue , targetTemp )
if self . bedTemperatureSelect . GetValue ( ) != bedTargetTemp :
wx . CallAfter ( self . bedTemperatureSelect . SetValue , bedTargetTemp )
2012-09-06 14:52:05 +00:00
def mcStateChange ( self , state ) :
2012-10-10 10:23:53 +00:00
if self . machineCom != None :
if state == self . machineCom . STATE_OPERATIONAL and self . cam != None :
self . cam . endTimelaps ( )
if state == self . machineCom . STATE_OPERATIONAL :
taskbar . setBusy ( self , False )
if self . machineCom . isClosedOrError ( ) :
taskbar . setBusy ( self , False )
if self . machineCom . isPaused ( ) :
taskbar . setPause ( self , True )
2012-09-06 14:52:05 +00:00
wx . CallAfter ( self . UpdateButtonStates )
wx . CallAfter ( self . UpdateProgress )
def mcMessage ( self , message ) :
wx . CallAfter ( self . AddTermLog , message )
def mcProgress ( self , lineNr ) :
wx . CallAfter ( self . UpdateProgress )
2012-09-07 12:10:57 +00:00
def mcZChange ( self , newZ ) :
2012-10-01 12:36:47 +00:00
self . currentZ = newZ
2012-09-07 12:10:57 +00:00
if self . cam != None :
wx . CallAfter ( self . cam . takeNewImage )
2012-09-27 15:20:31 +00:00
wx . CallAfter ( self . camPreview . Refresh )
2012-04-03 10:06:02 +00:00
2012-07-10 15:04:37 +00:00
class temperatureGraph ( wx . Panel ) :
def __init__ ( self , parent ) :
super ( temperatureGraph , self ) . __init__ ( parent )
self . Bind ( wx . EVT_ERASE_BACKGROUND , self . OnEraseBackground )
self . Bind ( wx . EVT_SIZE , self . OnSize )
self . Bind ( wx . EVT_PAINT , self . OnDraw )
self . lastDraw = time . time ( ) - 1.0
self . points = [ ]
self . backBuffer = None
self . addPoint ( 0 , 0 , 0 , 0 )
2012-10-01 11:47:16 +00:00
self . SetMinSize ( ( 320 , 200 ) )
2012-07-10 15:04:37 +00:00
def OnEraseBackground ( self , e ) :
pass
def OnSize ( self , e ) :
if self . backBuffer == None or self . GetSize ( ) != self . backBuffer . GetSize ( ) :
self . backBuffer = wx . EmptyBitmap ( * self . GetSizeTuple ( ) )
self . UpdateDrawing ( True )
def OnDraw ( self , e ) :
dc = wx . BufferedPaintDC ( self , self . backBuffer )
def UpdateDrawing ( self , force = False ) :
now = time . time ( )
if not force and now - self . lastDraw < 1.0 :
return
self . lastDraw = now
dc = wx . MemoryDC ( )
dc . SelectObject ( self . backBuffer )
dc . Clear ( )
2012-11-27 13:08:00 +00:00
dc . SetFont ( wx . SystemSettings . GetFont ( wx . SYS_SYSTEM_FONT ) )
2012-07-10 15:04:37 +00:00
w , h = self . GetSizeTuple ( )
2012-10-01 11:47:16 +00:00
bgLinePen = wx . Pen ( ' #A0A0A0 ' )
2012-07-10 15:04:37 +00:00
tempPen = wx . Pen ( ' #FF4040 ' )
tempSPPen = wx . Pen ( ' #FFA0A0 ' )
tempPenBG = wx . Pen ( ' #FFD0D0 ' )
bedTempPen = wx . Pen ( ' #4040FF ' )
bedTempSPPen = wx . Pen ( ' #A0A0FF ' )
bedTempPenBG = wx . Pen ( ' #D0D0FF ' )
2012-10-02 08:58:57 +00:00
2012-10-02 09:03:00 +00:00
#Draw the background up to the current temperatures.
2012-10-02 08:58:57 +00:00
x0 = 0
t0 = 0
bt0 = 0
tSP0 = 0
btSP0 = 0
for temp , tempSP , bedTemp , bedTempSP , t in self . points :
x1 = int ( w - ( now - t ) )
for x in xrange ( x0 , x1 + 1 ) :
t = float ( x - x0 ) / float ( x1 - x0 + 1 ) * ( temp - t0 ) + t0
bt = float ( x - x0 ) / float ( x1 - x0 + 1 ) * ( bedTemp - bt0 ) + bt0
dc . SetPen ( tempPenBG )
dc . DrawLine ( x , h , x , h - ( t * h / 300 ) )
dc . SetPen ( bedTempPenBG )
dc . DrawLine ( x , h , x , h - ( bt * h / 300 ) )
t0 = temp
bt0 = bedTemp
tSP0 = tempSP
btSP0 = bedTempSP
x0 = x1 + 1
#Draw the grid
2012-10-01 11:47:16 +00:00
for x in xrange ( w , 0 , - 30 ) :
dc . SetPen ( bgLinePen )
dc . DrawLine ( x , 0 , x , h )
2012-11-27 13:08:00 +00:00
tmpNr = 0
2012-10-01 11:47:16 +00:00
for y in xrange ( h - 1 , 0 , - h * 50 / 300 ) :
dc . SetPen ( bgLinePen )
dc . DrawLine ( 0 , y , w , y )
2012-11-27 13:08:00 +00:00
dc . DrawText ( str ( tmpNr ) , 0 , y - dc . GetFont ( ) . GetPixelSize ( ) . GetHeight ( ) )
tmpNr + = 50
2012-10-01 11:47:16 +00:00
dc . DrawLine ( 0 , 0 , w , 0 )
dc . DrawLine ( 0 , 0 , 0 , h )
2012-10-02 09:03:00 +00:00
#Draw the main lines
2012-10-02 08:58:57 +00:00
x0 = 0
t0 = 0
bt0 = 0
tSP0 = 0
btSP0 = 0
2012-07-10 15:04:37 +00:00
for temp , tempSP , bedTemp , bedTempSP , t in self . points :
x1 = int ( w - ( now - t ) )
for x in xrange ( x0 , x1 + 1 ) :
t = float ( x - x0 ) / float ( x1 - x0 + 1 ) * ( temp - t0 ) + t0
bt = float ( x - x0 ) / float ( x1 - x0 + 1 ) * ( bedTemp - bt0 ) + bt0
tSP = float ( x - x0 ) / float ( x1 - x0 + 1 ) * ( tempSP - tSP0 ) + tSP0
btSP = float ( x - x0 ) / float ( x1 - x0 + 1 ) * ( bedTempSP - btSP0 ) + btSP0
dc . SetPen ( tempSPPen )
dc . DrawPoint ( x , h - ( tSP * h / 300 ) )
dc . SetPen ( bedTempSPPen )
dc . DrawPoint ( x , h - ( btSP * h / 300 ) )
dc . SetPen ( tempPen )
dc . DrawPoint ( x , h - ( t * h / 300 ) )
dc . SetPen ( bedTempPen )
dc . DrawPoint ( x , h - ( bt * h / 300 ) )
t0 = temp
bt0 = bedTemp
tSP0 = tempSP
btSP0 = bedTempSP
x0 = x1 + 1
del dc
self . Refresh ( eraseBackground = False )
self . Update ( )
if len ( self . points ) > 0 and ( time . time ( ) - self . points [ 0 ] [ 4 ] ) > w + 20 :
self . points . pop ( 0 )
def addPoint ( self , temp , tempSP , bedTemp , bedTempSP ) :
2012-09-02 12:27:24 +00:00
if bedTemp == None :
bedTemp = 0
if bedTempSP == None :
bedTempSP = 0
2012-07-10 15:04:37 +00:00
self . points . append ( ( temp , tempSP , bedTemp , bedTempSP , time . time ( ) ) )
wx . CallAfter ( self . UpdateDrawing )
2012-10-01 11:47:16 +00:00
class LogWindow ( wx . Frame ) :
def __init__ ( self , logText ) :
super ( LogWindow , self ) . __init__ ( None , title = " Machine log " )
self . textBox = wx . TextCtrl ( self , - 1 , logText , style = wx . TE_MULTILINE | wx . TE_DONTWRAP | wx . TE_READONLY )
2012-10-01 13:14:47 +00:00
self . SetSize ( ( 500 , 400 ) )
2012-10-01 11:47:16 +00:00
self . Centre ( )
self . Show ( True )