1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
4 from wx.lib.intctrl import IntCtrl
11 from Cura.util import resources
12 from Cura.util import profile
14 #TODO: This does not belong here!
15 if sys.platform.startswith('win'):
16 def preventComputerFromSleeping(frame, prevent):
18 Function used to prevent the computer from going into sleep mode.
19 :param prevent: True = Prevent the system from going to sleep from this point on.
20 :param prevent: False = No longer prevent the system from going to sleep.
22 ES_CONTINUOUS = 0x80000000
23 ES_SYSTEM_REQUIRED = 0x00000001
24 ES_AWAYMODE_REQUIRED = 0x00000040
25 #SetThreadExecutionState returns 0 when failed, which is ignored. The function should be supported from windows XP and up.
27 # For Vista and up we use ES_AWAYMODE_REQUIRED to prevent a print from failing if the PC does go to sleep
28 # As it's not supported on XP, we catch the error and fallback to using ES_SYSTEM_REQUIRED only
29 if ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED) == 0:
30 ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED)
32 ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS)
34 elif sys.platform.startswith('darwin'):
36 bundle = objc.initFrameworkWrapper("IOKit",
37 frameworkIdentifier="com.apple.iokit",
38 frameworkPath=objc.pathForFramework("/System/Library/Frameworks/IOKit.framework"),
40 foo = objc.loadBundleFunctions(bundle, globals(), [("IOPMAssertionCreateWithName", b"i@I@o^I")])
41 foo = objc.loadBundleFunctions(bundle, globals(), [("IOPMAssertionRelease", b"iI")])
42 def preventComputerFromSleeping(frame, prevent):
44 success, preventComputerFromSleeping.assertionID = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, "Cura is printing", None)
45 if success != kIOReturnSuccess:
46 preventComputerFromSleeping.assertionID = None
48 if hasattr(preventComputerFromSleeping, "assertionID"):
49 if preventComputerFromSleeping.assertionID is not None:
50 IOPMAssertionRelease(preventComputerFromSleeping.assertionID)
51 preventComputerFromSleeping.assertionID = None
53 def preventComputerFromSleeping(frame, prevent):
54 if os.path.isfile("/usr/bin/xdg-screensaver"):
56 cmd = ['xdg-screensaver', 'suspend' if prevent else 'resume', str(frame.GetHandle())]
61 class printWindowPlugin(wx.Frame):
62 def __init__(self, parent, printerConnection, filename):
63 super(printWindowPlugin, self).__init__(parent, -1, style=wx.CLOSE_BOX|wx.CLIP_CHILDREN|wx.CAPTION|wx.SYSTEM_MENU|wx.FRAME_FLOAT_ON_PARENT|wx.MINIMIZE_BOX, title=_("Printing on %s") % (printerConnection.getName()))
64 self._printerConnection = printerConnection
65 self._basePath = os.path.dirname(filename)
66 self._backgroundImage = None
67 self._colorCommandMap = {}
70 self._termInput = None
71 self._termHistory = []
72 self._termHistoryIdx = 0
73 self._progressBar = None
74 self._tempGraph = None
76 self._lastUpdateTime = time.time()
77 self._isPrinting = False
80 'setImage': self.script_setImage,
81 'addColorCommand': self.script_addColorCommand,
82 'addTerminal': self.script_addTerminal,
83 'addTemperatureGraph': self.script_addTemperatureGraph,
84 'addProgressbar': self.script_addProgressbar,
85 'addButton': self.script_addButton,
86 'addSpinner': self.script_addSpinner,
87 'addTextButton': self.script_addTextButton,
89 'sendGCode': self.script_sendGCode,
90 'sendMovementGCode': self.script_sendMovementGCode,
91 'connect': self.script_connect,
92 'startPrint': self.script_startPrint,
93 'pausePrint': self.script_pausePrint,
94 'cancelPrint': self.script_cancelPrint,
95 'showErrorLog': self.script_showErrorLog,
97 execfile(filename, variables, variables)
99 self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
100 self.Bind(wx.EVT_PAINT, self.OnDraw)
101 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
102 self.Bind(wx.EVT_CLOSE, self.OnClose)
104 self._updateButtonStates()
106 self._printerConnection.addCallback(self._doPrinterConnectionUpdate)
108 if self._printerConnection.hasActiveConnection() and not self._printerConnection.isActiveConnectionOpen():
109 self._printerConnection.openActiveConnection()
111 def script_setImage(self, guiImage, mapImage):
112 self._backgroundImage = wx.BitmapFromImage(wx.Image(os.path.join(self._basePath, guiImage)))
113 self._mapImage = wx.Image(os.path.join(self._basePath, mapImage))
114 self.SetClientSize(self._mapImage.GetSize())
116 def script_addColorCommand(self, r, g, b, command, data = None):
117 self._colorCommandMap[(r, g, b)] = (command, data)
119 def script_addTerminal(self, r, g, b):
120 x, y, w, h = self._getColoredRect(r, g, b)
121 if x < 0 or self._termLog is not None:
123 f = wx.Font(8, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False)
124 self._termLog = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_DONTWRAP)
125 self._termLog.SetFont(f)
126 self._termLog.SetEditable(0)
127 self._termInput = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
128 self._termInput.SetFont(f)
130 self._termLog.SetPosition((x, y))
131 self._termLog.SetSize((w, h - self._termInput.GetSize().GetHeight()))
132 self._termInput.SetPosition((x, y + h - self._termInput.GetSize().GetHeight()))
133 self._termInput.SetSize((w, self._termInput.GetSize().GetHeight()))
134 self.Bind(wx.EVT_TEXT_ENTER, self.OnTermEnterLine, self._termInput)
135 self._termInput.Bind(wx.EVT_CHAR, self.OnTermKey)
137 def script_addTemperatureGraph(self, r, g, b):
138 x, y, w, h = self._getColoredRect(r, g, b)
139 if x < 0 or self._tempGraph is not None:
141 self._tempGraph = TemperatureGraph(self)
143 self._tempGraph.SetPosition((x, y))
144 self._tempGraph.SetSize((w, h))
146 def script_addProgressbar(self, r, g, b):
147 x, y, w, h = self._getColoredRect(r, g, b)
150 self._progressBar = wx.Gauge(self, -1, range=1000)
152 self._progressBar.SetPosition((x, y))
153 self._progressBar.SetSize((w, h))
155 def script_addButton(self, r, g, b, text, command, data = None):
156 x, y, w, h = self._getColoredRect(r, g, b)
159 button = wx.Button(self, -1, _(text))
160 button.SetPosition((x, y))
161 button.SetSize((w, h))
162 button.command = command
164 self._buttonList.append(button)
165 self.Bind(wx.EVT_BUTTON, lambda e: command(data), button)
167 def script_addSpinner(self, r, g, b, command, data):
168 x, y, w, h = self._getColoredRect(r, g, b)
172 def run_command(spinner):
173 value = spinner.GetValue()
174 print "Value (%s) and (%s)" % (spinner.last_value, value)
175 if spinner.last_value != '' and value != 0:
176 spinner.command(spinner.data % value)
177 spinner.last_value = value
179 spinner = wx.SpinCtrl(self, -1, style=wx.TE_PROCESS_ENTER)
180 spinner.SetRange(0, 300)
181 spinner.SetPosition((x, y))
182 spinner.SetSize((w, h))
184 spinner.command = command
186 spinner.last_value = ''
187 self._buttonList.append(spinner)
188 self.Bind(wx.EVT_SPINCTRL, lambda e: run_command(spinner), spinner)
190 def script_addTextButton(self, r_text, g_text, b_text, r_button, g_button, b_button, button_text, command, data):
191 x_text, y_text, w_text, h_text = self._getColoredRect(r_text, g_text, b_text)
194 x_button, y_button, w_button, h_button = self._getColoredRect(r_button, g_button, b_button)
197 from wx.lib.intctrl import IntCtrl
198 text = IntCtrl(self, -1)
199 text.SetBounds(0, 300)
200 text.SetPosition((x_text, y_text))
201 text.SetSize((w_text, h_text))
203 button = wx.Button(self, -1, _(button_text))
204 button.SetPosition((x_button, y_button))
205 button.SetSize((w_button, h_button))
206 button.command = command
208 self._buttonList.append(button)
209 self.Bind(wx.EVT_BUTTON, lambda e: command(data % text.GetValue()), button)
211 def _getColoredRect(self, r, g, b):
212 for x in xrange(0, self._mapImage.GetWidth()):
213 for y in xrange(0, self._mapImage.GetHeight()):
214 if self._mapImage.GetRed(x, y) == r and self._mapImage.GetGreen(x, y) == g and self._mapImage.GetBlue(x, y) == b:
216 while x+w < self._mapImage.GetWidth() and self._mapImage.GetRed(x + w, y) == r and self._mapImage.GetGreen(x + w, y) == g and self._mapImage.GetBlue(x + w, y) == b:
219 while y+h < self._mapImage.GetHeight() and self._mapImage.GetRed(x, y + h) == r and self._mapImage.GetGreen(x, y + h) == g and self._mapImage.GetBlue(x, y + h) == b:
222 print "Failed to find color: ", r, g, b
225 def script_sendGCode(self, data = None):
226 for line in data.split(';'):
229 self._printerConnection.sendCommand(line)
231 def script_sendMovementGCode(self, data = None):
232 if not self._printerConnection.isPaused() and not self._printerConnection.isPrinting():
233 self.script_sendGCode(data)
235 def script_connect(self, data = None):
236 self._printerConnection.openActiveConnection()
238 def script_startPrint(self, data = None):
239 if self._printerConnection.isPrinting() or self._printerConnection.isPaused():
240 self._printerConnection.pause(not self._printerConnection.isPaused())
242 self._printerConnection.startPrint()
244 def script_cancelPrint(self, e):
245 self._printerConnection.cancelPrint()
247 def script_pausePrint(self, e):
248 self._printerConnection.pause(not self._printerConnection.isPaused())
250 def script_showErrorLog(self, e):
251 LogWindow(self._printerConnection.getErrorLog())
253 def OnEraseBackground(self, e):
257 dc = wx.BufferedPaintDC(self, self._backgroundImage)
259 def OnLeftClick(self, e):
260 r = self._mapImage.GetRed(e.GetX(), e.GetY())
261 g = self._mapImage.GetGreen(e.GetX(), e.GetY())
262 b = self._mapImage.GetBlue(e.GetX(), e.GetY())
263 if (r, g, b) in self._colorCommandMap:
264 command = self._colorCommandMap[(r, g, b)]
265 command[0](command[1])
267 def OnClose(self, e):
268 if self._printerConnection.hasActiveConnection():
269 if self._printerConnection.isPrinting() or self._printerConnection.isPaused():
270 pass #TODO: Give warning that the close will kill the print.
271 self._printerConnection.closeActiveConnection()
272 self._printerConnection.removeCallback(self._doPrinterConnectionUpdate)
273 #TODO: When multiple printer windows are open, closing one will enable sleeping again.
274 preventComputerFromSleeping(self, False)
275 self._printerConnection.cancelPrint()
278 def OnTermEnterLine(self, e):
279 if not self._printerConnection.isAbleToSendDirectCommand():
281 line = self._termInput.GetValue()
284 self._addTermLog('> %s\n' % (line))
285 self._printerConnection.sendCommand(line)
286 self._termHistory.append(line)
287 self._termHistoryIdx = len(self._termHistory)
288 self._termInput.SetValue('')
290 def OnTermKey(self, e):
291 if len(self._termHistory) > 0:
292 if e.GetKeyCode() == wx.WXK_UP:
293 self._termHistoryIdx -= 1
294 if self._termHistoryIdx < 0:
295 self._termHistoryIdx = len(self._termHistory) - 1
296 self._termInput.SetValue(self._termHistory[self._termHistoryIdx])
297 if e.GetKeyCode() == wx.WXK_DOWN:
298 self._termHistoryIdx -= 1
299 if self._termHistoryIdx >= len(self._termHistory):
300 self._termHistoryIdx = 0
301 self._termInput.SetValue(self._termHistory[self._termHistoryIdx])
304 def _addTermLog(self, line):
305 if self._termLog is not None:
306 if len(self._termLog.GetValue()) > 10000:
307 self._termLog.SetValue(self._termLog.GetValue()[-10000:])
308 self._termLog.SetInsertionPointEnd()
309 if type(line) != unicode:
310 line = unicode(line, 'utf-8', 'replace')
311 self._termLog.AppendText(line.encode('utf-8', 'replace'))
313 def _updateButtonStates(self):
314 hasPauseButton = False
315 for button in self._buttonList:
316 if button.command == self.script_pausePrint:
317 hasPauseButton = True
320 for button in self._buttonList:
321 if button.command == self.script_connect:
322 button.Show(self._printerConnection.hasActiveConnection())
323 button.Enable(not self._printerConnection.isActiveConnectionOpen() and \
324 not self._printerConnection.isActiveConnectionOpening())
325 elif button.command == self.script_pausePrint:
326 button.Show(self._printerConnection.hasPause())
327 if not self._printerConnection.hasActiveConnection() or \
328 self._printerConnection.isActiveConnectionOpen():
329 button.Enable(self._printerConnection.isPrinting() or \
330 self._printerConnection.isPaused())
331 if self._printerConnection.isPaused():
332 button.SetLabel(_("Resume"))
334 button.SetLabel(_("Pause"))
337 elif button.command == self.script_startPrint:
338 if hasPauseButton or not self._printerConnection.hasPause():
339 if not self._printerConnection.hasActiveConnection() or \
340 self._printerConnection.isActiveConnectionOpen():
341 button.Enable(not self._printerConnection.isPrinting() and \
342 not self._printerConnection.isPaused())
346 if not self._printerConnection.hasActiveConnection() or \
347 self._printerConnection.isActiveConnectionOpen():
348 if self._printerConnection.isPrinting():
349 if self.pauseTimer.IsRunning():
350 self.printButton.Enable(False)
351 self.printButton.SetLabel(_("Please wait..."))
353 self.printButton.Enable(True)
354 button.SetLabel(_("Pause"))
356 if self._printerConnection.isPaused():
357 if self.pauseTimer.IsRunning():
358 self.printButton.Enable(False)
359 self.printButton.SetLabel(_("Please wait..."))
361 self.printButton.Enable(True)
362 button.SetLabel(_("Resume"))
364 button.SetLabel(_("Print"))
366 self.pauseTimer.Stop()
369 elif button.command == self.script_cancelPrint:
370 if not self._printerConnection.hasActiveConnection() or \
371 self._printerConnection.isActiveConnectionOpen():
372 button.Enable(self._printerConnection.isPrinting() or \
373 self._printerConnection.isPaused())
376 elif button.command == self.script_showErrorLog:
377 button.Show(self._printerConnection.isInErrorState())
378 if self._termInput is not None:
379 self._termInput.Enable(self._printerConnection.isAbleToSendDirectCommand())
381 def _doPrinterConnectionUpdate(self, connection, extraInfo = None):
382 wx.CallAfter(self.__doPrinterConnectionUpdate, connection, extraInfo)
383 if self._tempGraph is not None:
385 for n in xrange(0, 4):
386 t = connection.getTemperature(0)
391 self._tempGraph.addPoint(temp, [0] * len(temp), connection.getBedTemperature(), 0)
393 def __doPrinterConnectionUpdate(self, connection, extraInfo):
395 if self._lastUpdateTime + 0.5 > t and extraInfo is None:
397 self._lastUpdateTime = t
399 if extraInfo is not None and len(extraInfo) > 0:
400 self._addTermLog('< %s\n' % (extraInfo))
402 self._updateButtonStates()
403 isPrinting = connection.isPrinting() or connection.isPaused()
404 if self._progressBar is not None:
406 (current, total, z) = connection.getPrintProgress()
409 progress = float(current) / float(total)
410 self._progressBar.SetValue(progress * 1000)
412 self._progressBar.SetValue(0)
413 info = connection.getStatusString()
415 if self._printerConnection.getTemperature(0) is not None:
416 info += 'Temperature: %d' % (self._printerConnection.getTemperature(0))
417 if self._printerConnection.getBedTemperature() > 0:
418 info += ' Bed: %d' % (self._printerConnection.getBedTemperature())
419 if self._infoText is not None:
420 self._infoText.SetLabel(info)
422 self.SetTitle(info.replace('\n', ', ').strip(', '))
423 if isPrinting != self._isPrinting:
424 self._isPrinting = isPrinting
425 preventComputerFromSleeping(self, self._isPrinting)
427 class printWindowBasic(wx.Frame):
429 Printing window for USB printing, network printing, and any other type of printer connection we can think off.
430 This is only a basic window with minimal information.
432 def __init__(self, parent, printerConnection):
433 super(printWindowBasic, self).__init__(parent, -1, style=wx.CLOSE_BOX|wx.CLIP_CHILDREN|wx.CAPTION|wx.SYSTEM_MENU|wx.FRAME_TOOL_WINDOW|wx.FRAME_FLOAT_ON_PARENT, title=_("Printing on %s") % (printerConnection.getName()))
434 self._printerConnection = printerConnection
435 self._lastUpdateTime = 0
436 self._isPrinting = False
438 self.SetSizer(wx.BoxSizer())
439 self.panel = wx.Panel(self)
440 self.GetSizer().Add(self.panel, 1, flag=wx.EXPAND)
441 self.sizer = wx.GridBagSizer(2, 2)
442 self.panel.SetSizer(self.sizer)
444 self.powerWarningText = wx.StaticText(parent=self.panel,
446 label=_("Your computer is running on battery power.\nConnect your computer to AC power or your print might not finish."),
447 style=wx.ALIGN_CENTER)
448 self.powerWarningText.SetBackgroundColour('red')
449 self.powerWarningText.SetForegroundColour('white')
450 self.powerManagement = power.PowerManagement()
451 self.powerWarningTimer = wx.Timer(self)
452 self.Bind(wx.EVT_TIMER, self.OnPowerWarningChange, self.powerWarningTimer)
453 self.OnPowerWarningChange(None)
454 self.powerWarningTimer.Start(10000)
456 self.statsText = wx.StaticText(self.panel, -1, _("InfoLine from printer connection\nInfoLine from dialog\nExtra line\nMore lines for layout\nMore lines for layout\nMore lines for layout"))
458 self.connectButton = wx.Button(self.panel, -1, _("Connect"))
459 #self.loadButton = wx.Button(self.panel, -1, 'Load')
460 self.printButton = wx.Button(self.panel, -1, _("Print"))
461 self.pauseButton = wx.Button(self.panel, -1, _("Pause"))
462 self.cancelButton = wx.Button(self.panel, -1, _("Cancel print"))
463 self.errorLogButton = wx.Button(self.panel, -1, _("Error log"))
464 self.progress = wx.Gauge(self.panel, -1, range=1000)
466 self.pauseTimer = wx.Timer(self)
467 self.Bind(wx.EVT_TIMER, self.OnPauseTimer, self.pauseTimer)
469 self.sizer.Add(self.powerWarningText, pos=(0, 0), span=(1, 5), flag=wx.EXPAND|wx.BOTTOM, border=5)
470 self.sizer.Add(self.statsText, pos=(1, 0), span=(1, 5), flag=wx.LEFT, border=5)
471 self.sizer.Add(self.connectButton, pos=(2, 0))
472 #self.sizer.Add(self.loadButton, pos=(2,1))
473 self.sizer.Add(self.printButton, pos=(2, 1))
474 self.sizer.Add(self.pauseButton, pos=(2, 2))
475 self.sizer.Add(self.cancelButton, pos=(2, 3))
476 self.sizer.Add(self.errorLogButton, pos=(2, 4))
477 self.sizer.Add(self.progress, pos=(3, 0), span=(1, 5), flag=wx.EXPAND)
479 self.Bind(wx.EVT_CLOSE, self.OnClose)
480 self.connectButton.Bind(wx.EVT_BUTTON, self.OnConnect)
481 #self.loadButton.Bind(wx.EVT_BUTTON, self.OnLoad)
482 self.printButton.Bind(wx.EVT_BUTTON, self.OnPrint)
483 self.pauseButton.Bind(wx.EVT_BUTTON, self.OnPause)
484 self.cancelButton.Bind(wx.EVT_BUTTON, self.OnCancel)
485 self.errorLogButton.Bind(wx.EVT_BUTTON, self.OnErrorLog)
491 self.progress.SetMinSize(self.progress.GetSize())
492 self.statsText.SetLabel('\n\n\n\n\n\n')
493 self._updateButtonStates()
495 self._printerConnection.addCallback(self._doPrinterConnectionUpdate)
497 if self._printerConnection.hasActiveConnection() and not self._printerConnection.isActiveConnectionOpen():
498 self._printerConnection.openActiveConnection()
500 def OnPowerWarningChange(self, e):
501 type = self.powerManagement.get_providing_power_source_type()
502 if type == power.POWER_TYPE_AC and self.powerWarningText.IsShown():
503 self.powerWarningText.Hide()
508 elif type != power.POWER_TYPE_AC and not self.powerWarningText.IsShown():
509 self.powerWarningText.Show()
515 def OnClose(self, e):
516 if self._printerConnection.hasActiveConnection():
517 if self._printerConnection.isPrinting() or self._printerConnection.isPaused():
518 pass #TODO: Give warning that the close will kill the print.
519 self._printerConnection.closeActiveConnection()
520 self._printerConnection.removeCallback(self._doPrinterConnectionUpdate)
521 #TODO: When multiple printer windows are open, closing one will enable sleeping again.
522 preventComputerFromSleeping(self, False)
523 self.powerWarningTimer.Stop()
524 self.pauseTimer.Stop()
527 def OnConnect(self, e):
528 self._printerConnection.openActiveConnection()
533 def OnPrint(self, e):
534 self._printerConnection.startPrint()
536 def OnCancel(self, e):
537 self._printerConnection.cancelPrint()
539 def OnPause(self, e):
540 self._printerConnection.pause(not self._printerConnection.isPaused())
541 self.pauseButton.Enable(False)
542 self.pauseTimer.Stop()
543 self.pauseTimer.Start(10000)
545 def OnPauseTimer(self, e):
546 self.pauseButton.Enable(True)
547 self.pauseTimer.Stop()
548 self._updateButtonStates()
550 def OnErrorLog(self, e):
551 LogWindow(self._printerConnection.getErrorLog())
553 def _doPrinterConnectionUpdate(self, connection, extraInfo = None):
554 wx.CallAfter(self.__doPrinterConnectionUpdate, connection, extraInfo)
555 #temp = [connection.getTemperature(0)]
556 #self.temperatureGraph.addPoint(temp, [0], connection.getBedTemperature(), 0)
558 def __doPrinterConnectionUpdate(self, connection, extraInfo):
560 if self._lastUpdateTime + 0.5 > now and extraInfo is None:
562 self._lastUpdateTime = now
564 if extraInfo is not None and len(extraInfo) > 0:
565 self._addTermLog('< %s\n' % (extraInfo))
567 self._updateButtonStates()
568 onGoingPrint = connection.isPrinting() or connection.isPaused()
570 (current, total, z) = connection.getPrintProgress()
573 progress = float(current) / float(total)
574 self.progress.SetValue(progress * 1000)
576 self.progress.SetValue(0)
577 info = connection.getStatusString()
579 if self._printerConnection.getTemperature(0) is not None:
580 info += 'Temperature: %d' % (self._printerConnection.getTemperature(0))
581 if self._printerConnection.getBedTemperature() > 0:
582 info += ' Bed: %d' % (self._printerConnection.getBedTemperature())
584 self.statsText.SetLabel(info)
585 if onGoingPrint != self._isPrinting:
586 self._isPrinting = onGoingPrint
587 preventComputerFromSleeping(self, self._isPrinting)
589 def _addTermLog(self, msg):
592 def _updateButtonStates(self):
593 self.connectButton.Show(self._printerConnection.hasActiveConnection())
594 self.connectButton.Enable(not self._printerConnection.isActiveConnectionOpen() and not self._printerConnection.isActiveConnectionOpening())
595 self.pauseButton.Show(self._printerConnection.hasPause())
596 if not self._printerConnection.hasActiveConnection() or self._printerConnection.isActiveConnectionOpen():
597 self.printButton.Enable(not self._printerConnection.isPrinting() and \
598 not self._printerConnection.isPaused())
599 self.pauseButton.Enable(self._printerConnection.isPrinting())
600 self.cancelButton.Enable(self._printerConnection.isPrinting())
602 self.printButton.Enable(False)
603 self.pauseButton.Enable(False)
604 self.cancelButton.Enable(False)
605 self.errorLogButton.Show(self._printerConnection.isInErrorState())
607 class printWindowAdvanced(wx.Frame):
608 def __init__(self, parent, printerConnection):
609 super(printWindowAdvanced, self).__init__(parent, -1, style=wx.CLOSE_BOX|wx.CLIP_CHILDREN|wx.CAPTION|wx.SYSTEM_MENU|wx.FRAME_FLOAT_ON_PARENT|wx.MINIMIZE_BOX, title=_("Printing on %s") % (printerConnection.getName()))
610 self._printerConnection = printerConnection
611 self._lastUpdateTime = time.time()
612 self._isPrinting = False
614 self.SetSizer(wx.BoxSizer(wx.VERTICAL))
615 self.toppanel = wx.Panel(self)
616 self.topsizer = wx.GridBagSizer(2, 2)
617 self.toppanel.SetSizer(self.topsizer)
618 self.toppanel.SetBackgroundColour(wx.WHITE)
619 self.topsizer.SetEmptyCellSize((125, 1))
620 self.panel = wx.Panel(self)
621 self.sizer = wx.GridBagSizer(2, 2)
622 self.sizer.SetEmptyCellSize((125, 1))
623 self.panel.SetSizer(self.sizer)
624 self.panel.SetBackgroundColour(wx.WHITE)
625 self.GetSizer().Add(self.toppanel, 0, flag=wx.EXPAND)
626 self.GetSizer().Add(self.panel, 1, flag=wx.EXPAND)
628 self._fullscreenTemperature = None
629 self._termHistory = []
630 self._termHistoryIdx = 0
632 self._mapImage = wx.Image(resources.getPathForImage('print-window-map.png'))
633 self._colorCommandMap = {}
636 self._addMovementCommand(0, 0, 255, self._moveX, 100)
637 self._addMovementCommand(0, 0, 240, self._moveX, 10)
638 self._addMovementCommand(0, 0, 220, self._moveX, 1)
639 self._addMovementCommand(0, 0, 200, self._moveX, 0.1)
640 self._addMovementCommand(0, 0, 180, self._moveX, -0.1)
641 self._addMovementCommand(0, 0, 160, self._moveX, -1)
642 self._addMovementCommand(0, 0, 140, self._moveX, -10)
643 self._addMovementCommand(0, 0, 120, self._moveX, -100)
646 self._addMovementCommand(0, 255, 0, self._moveY, -100)
647 self._addMovementCommand(0, 240, 0, self._moveY, -10)
648 self._addMovementCommand(0, 220, 0, self._moveY, -1)
649 self._addMovementCommand(0, 200, 0, self._moveY, -0.1)
650 self._addMovementCommand(0, 180, 0, self._moveY, 0.1)
651 self._addMovementCommand(0, 160, 0, self._moveY, 1)
652 self._addMovementCommand(0, 140, 0, self._moveY, 10)
653 self._addMovementCommand(0, 120, 0, self._moveY, 100)
656 self._addMovementCommand(255, 0, 0, self._moveZ, 10)
657 self._addMovementCommand(220, 0, 0, self._moveZ, 1)
658 self._addMovementCommand(200, 0, 0, self._moveZ, 0.1)
659 self._addMovementCommand(180, 0, 0, self._moveZ, -0.1)
660 self._addMovementCommand(160, 0, 0, self._moveZ, -1)
661 self._addMovementCommand(140, 0, 0, self._moveZ, -10)
664 self._addMovementCommand(255, 80, 0, self._moveE, 10)
665 self._addMovementCommand(255, 180, 0, self._moveE, -10)
668 self._addMovementCommand(255, 255, 0, self._homeXYZ, None)
669 self._addMovementCommand(240, 255, 0, self._homeXYZ, "X")
670 self._addMovementCommand(220, 255, 0, self._homeXYZ, "Y")
671 self._addMovementCommand(200, 255, 0, self._homeXYZ, "Z")
673 self.powerWarningText = wx.StaticText(parent=self.toppanel,
675 label=_("Your computer is running on battery power.\nConnect your computer to AC power or your print might not finish."),
676 style=wx.ALIGN_CENTER)
677 self.powerWarningText.SetBackgroundColour('red')
678 self.powerWarningText.SetForegroundColour('white')
679 self.powerManagement = power.PowerManagement()
680 self.powerWarningTimer = wx.Timer(self)
681 self.Bind(wx.EVT_TIMER, self.OnPowerWarningChange, self.powerWarningTimer)
682 self.OnPowerWarningChange(None)
683 self.powerWarningTimer.Start(10000)
685 self.pauseTimer = wx.Timer(self)
686 self.Bind(wx.EVT_TIMER, self.OnPauseTimer, self.pauseTimer)
688 self.connectButton = wx.Button(self.toppanel, -1, _("Connect"), size=(125, 30))
689 self.printButton = wx.Button(self.toppanel, -1, _("Print"), size=(125, 30))
690 self.cancelButton = wx.Button(self.toppanel, -1, _("Cancel"), size=(125, 30))
691 self.errorLogButton = wx.Button(self.toppanel, -1, _("Error log"), size=(125, 30))
692 self.motorsOffButton = wx.Button(self.toppanel, -1, _("Motors off"), size=(125, 30))
693 self.movementBitmap = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(wx.Image(
694 resources.getPathForImage('print-window.png'))), (0, 0))
695 self.temperatureBitmap = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(wx.Image(
696 resources.getPathForImage('print-window-temperature.png'))), (0, 0))
697 self.temperatureField = TemperatureField(self.panel, self._setHotendTemperature)
698 self.temperatureBedBitmap = wx.StaticBitmap(self.panel, -1, wx.BitmapFromImage(wx.Image(
699 resources.getPathForImage('print-window-temperature-bed.png'))), (0, 0))
700 self.temperatureBedField = TemperatureField(self.panel, self._setBedTemperature)
701 self.temperatureGraph = TemperatureGraph(self.panel)
702 self.temperatureGraph.SetMinSize((250, 100))
703 self.progress = wx.Gauge(self.panel, -1, range=1000)
705 f = wx.Font(8, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False)
706 self._termLog = wx.TextCtrl(self.panel, style=wx.TE_MULTILINE)
707 self._termLog.SetFont(f)
708 self._termLog.SetEditable(0)
709 self._termLog.SetMinSize((385, -1))
710 self._termInput = wx.TextCtrl(self.panel, style=wx.TE_PROCESS_ENTER)
711 self._termInput.SetFont(f)
713 self.Bind(wx.EVT_TEXT_ENTER, self.OnTermEnterLine, self._termInput)
714 self._termInput.Bind(wx.EVT_CHAR, self.OnTermKey)
716 self.topsizer.Add(self.powerWarningText, pos=(0, 0), span=(1, 6), flag=wx.EXPAND|wx.BOTTOM, border=5)
717 self.topsizer.Add(self.connectButton, pos=(1, 0), flag=wx.LEFT, border=2)
718 self.topsizer.Add(self.printButton, pos=(1, 1), flag=wx.LEFT, border=2)
719 self.topsizer.Add(self.cancelButton, pos=(1, 2), flag=wx.LEFT, border=2)
720 self.topsizer.Add(self.errorLogButton, pos=(1, 4), flag=wx.LEFT, border=2)
721 self.topsizer.Add(self.motorsOffButton, pos=(1, 5), flag=wx.LEFT|wx.RIGHT, border=2)
722 self.sizer.Add(self.movementBitmap, pos=(0, 0), span=(2, 3))
723 self.sizer.Add(self.temperatureGraph, pos=(2, 0), span=(4, 2), flag=wx.EXPAND)
724 self.sizer.Add(self.temperatureBitmap, pos=(2, 2))
725 self.sizer.Add(self.temperatureField, pos=(3, 2))
726 self.sizer.Add(self.temperatureBedBitmap, pos=(4, 2))
727 self.sizer.Add(self.temperatureBedField, pos=(5, 2))
728 self.sizer.Add(self._termLog, pos=(0, 3), span=(5, 3), flag=wx.EXPAND|wx.RIGHT, border=5)
729 self.sizer.Add(self._termInput, pos=(5, 3), span=(1, 3), flag=wx.EXPAND|wx.RIGHT, border=5)
730 self.sizer.Add(self.progress, pos=(7, 0), span=(1, 6), flag=wx.EXPAND|wx.BOTTOM)
732 self.Bind(wx.EVT_SIZE, self.OnSize)
733 self.Bind(wx.EVT_CLOSE, self.OnClose)
734 self.movementBitmap.Bind(wx.EVT_LEFT_DOWN, self.OnMovementClick)
735 self.temperatureGraph.Bind(wx.EVT_LEFT_UP, self.OnTemperatureClick)
736 self.connectButton.Bind(wx.EVT_BUTTON, self.OnConnect)
737 self.printButton.Bind(wx.EVT_BUTTON, self.OnPrint)
738 self.cancelButton.Bind(wx.EVT_BUTTON, self.OnCancel)
739 self.errorLogButton.Bind(wx.EVT_BUTTON, self.OnErrorLog)
740 self.motorsOffButton.Bind(wx.EVT_BUTTON, self.OnMotorsOff)
745 self.progress.SetMinSize(self.progress.GetSize())
746 self._updateButtonStates()
748 self._printerConnection.addCallback(self._doPrinterConnectionUpdate)
750 if self._printerConnection.hasActiveConnection() and \
751 not self._printerConnection.isActiveConnectionOpen():
752 self._printerConnection.openActiveConnection()
755 # HACK ALERT: This is needed for some reason otherwise the window
756 # will be bigger than it should be until a power warning change
761 def OnClose(self, e):
762 if self._printerConnection.hasActiveConnection():
763 if self._printerConnection.isPrinting() or self._printerConnection.isPaused():
764 pass #TODO: Give warning that the close will kill the print.
765 self._printerConnection.closeActiveConnection()
766 self._printerConnection.removeCallback(self._doPrinterConnectionUpdate)
767 #TODO: When multiple printer windows are open, closing one will enable sleeping again.
768 preventComputerFromSleeping(self, False)
769 self._printerConnection.cancelPrint()
770 self.powerWarningTimer.Stop()
771 self.pauseTimer.Stop()
774 def OnPowerWarningChange(self, e):
775 type = self.powerManagement.get_providing_power_source_type()
776 if type == power.POWER_TYPE_AC and self.powerWarningText.IsShown():
777 self.powerWarningText.Hide()
778 self.toppanel.Layout()
782 elif type != power.POWER_TYPE_AC and not self.powerWarningText.IsShown():
783 self.powerWarningText.Show()
784 self.toppanel.Layout()
789 def OnConnect(self, e):
790 self._printerConnection.openActiveConnection()
792 def OnPrint(self, e):
793 if self._printerConnection.isPrinting() or self._printerConnection.isPaused():
794 self._printerConnection.pause(not self._printerConnection.isPaused())
795 self.pauseTimer.Stop()
796 self.printButton.Enable(False)
797 self.pauseTimer.Start(10000)
799 self._printerConnection.startPrint()
801 def OnPauseTimer(self, e):
802 self.printButton.Enable(True)
803 self.pauseTimer.Stop()
804 self._updateButtonStates()
806 def OnCancel(self, e):
807 self._printerConnection.cancelPrint()
809 def OnErrorLog(self, e):
810 LogWindow(self._printerConnection.getErrorLog())
812 def OnMotorsOff(self, e):
813 self._printerConnection.sendCommand("M18")
815 def GetMapRGB(self, x, y):
816 r = self._mapImage.GetRed(x, y)
817 g = self._mapImage.GetGreen(x, y)
818 b = self._mapImage.GetBlue(x, y)
821 def OnMovementClick(self, e):
822 (r, g, b) = self.GetMapRGB(e.GetX(), e.GetY())
823 if (r, g, b) in self._colorCommandMap:
824 command = self._colorCommandMap[(r, g, b)]
825 command[0](command[1])
827 def _addMovementCommand(self, r, g, b, command, step):
828 self._colorCommandMap[(r, g, b)] = (command, step)
830 def _moveXYZE(self, motor, step, feedrate):
831 # Prevent Z movement when paused and all moves when printing
832 if (not self._printerConnection.hasActiveConnection() or \
833 self._printerConnection.isActiveConnectionOpen()) and \
834 (not (self._printerConnection.isPaused() and motor != 'E') and \
835 not self._printerConnection.isPrinting()):
836 self._printerConnection.sendCommand("G91")
837 self._printerConnection.sendCommand("G1 %s%.1f F%d" % (motor, step, feedrate))
838 self._printerConnection.sendCommand("G90")
840 def _moveX(self, step):
841 self._moveXYZE("X", step, 2000)
843 def _moveY(self, step):
844 self._moveXYZE("Y", step, 2000)
846 def _moveZ(self, step):
847 self._moveXYZE("Z", step, 200)
849 def _moveE(self, step):
851 if "lulzbot_" in profile.getMachineSetting("machine_type"):
852 toolhead_name = profile.getMachineSetting("toolhead")
853 toolhead_name = toolhead_name.lower()
854 if "flexy" in toolhead_name:
856 self._moveXYZE("E", step, feedrate)
858 def _homeXYZ(self, direction):
859 if not self._printerConnection.isPaused() and not self._printerConnection.isPrinting():
860 if direction is None:
861 self._printerConnection.sendCommand("G28")
863 self._printerConnection.sendCommand("G28 %s0" % direction)
865 def _setHotendTemperature(self, value):
866 self._printerConnection.sendCommand("M104 S%d" % value)
868 def _setBedTemperature(self, value):
869 self._printerConnection.sendCommand("M140 S%d" % value)
871 def OnTemperatureClick(self, e):
872 wx.CallAfter(self.ToggleFullScreenTemperature)
874 def ToggleFullScreenTemperature(self):
875 sizer = self.GetSizer()
876 if self._fullscreenTemperature:
877 self._fullscreenTemperature.Show(False)
878 sizer.Detach(self._fullscreenTemperature)
879 self._fullscreenTemperature.Destroy()
880 self._fullscreenTemperature = None
881 self.panel.Show(True)
883 self._fullscreenTemperature = self.temperatureGraph.Clone(self)
884 self._fullscreenTemperature.Bind(wx.EVT_LEFT_UP, self.OnTemperatureClick)
885 self._fullscreenTemperature.SetMinSize(self.panel.GetSize())
886 sizer.Add(self._fullscreenTemperature, 1, flag=wx.EXPAND)
887 self.panel.Show(False)
891 def OnTermEnterLine(self, e):
892 if not self._printerConnection.isAbleToSendDirectCommand():
894 line = self._termInput.GetValue()
897 self._addTermLog('> %s\n' % (line))
898 self._printerConnection.sendCommand(line)
899 self._termHistory.append(line)
900 self._termHistoryIdx = len(self._termHistory)
901 self._termInput.SetValue('')
903 def OnTermKey(self, e):
904 if len(self._termHistory) > 0:
905 if e.GetKeyCode() == wx.WXK_UP:
906 self._termHistoryIdx -= 1
907 if self._termHistoryIdx < 0:
908 self._termHistoryIdx = len(self._termHistory) - 1
909 self._termInput.SetValue(self._termHistory[self._termHistoryIdx])
910 if e.GetKeyCode() == wx.WXK_DOWN:
911 self._termHistoryIdx -= 1
912 if self._termHistoryIdx >= len(self._termHistory):
913 self._termHistoryIdx = 0
914 self._termInput.SetValue(self._termHistory[self._termHistoryIdx])
917 def _addTermLog(self, line):
918 if self._termLog is not None:
919 if len(self._termLog.GetValue()) > 10000:
920 self._termLog.SetValue(self._termLog.GetValue()[-10000:])
921 self._termLog.SetInsertionPointEnd()
922 if type(line) != unicode:
923 line = unicode(line, 'utf-8', 'replace')
924 self._termLog.AppendText(line.encode('utf-8', 'replace'))
926 def _updateButtonStates(self):
927 self.connectButton.Show(self._printerConnection.hasActiveConnection())
928 self.connectButton.Enable(not self._printerConnection.isActiveConnectionOpen() and \
929 not self._printerConnection.isActiveConnectionOpening())
930 if not self._printerConnection.hasPause():
931 if not self._printerConnection.hasActiveConnection() or \
932 self._printerConnection.isActiveConnectionOpen():
933 self.printButton.Enable(not self._printerConnection.isPrinting() and \
934 not self._printerConnection.isPaused())
936 self.printButton.Enable(False)
938 if not self._printerConnection.hasActiveConnection() or \
939 self._printerConnection.isActiveConnectionOpen():
940 if self._printerConnection.isPrinting():
941 if self.pauseTimer.IsRunning():
942 self.printButton.Enable(False)
943 self.printButton.SetLabel(_("Please wait..."))
945 self.printButton.Enable(True)
946 self.printButton.SetLabel(_("Pause"))
948 if self._printerConnection.isPaused():
949 if self.pauseTimer.IsRunning():
950 self.printButton.Enable(False)
951 self.printButton.SetLabel(_("Please wait..."))
953 self.printButton.SetLabel(_("Resume"))
954 self.printButton.Enable(True)
956 self.printButton.SetLabel(_("Print"))
957 self.printButton.Enable(True)
958 self.pauseTimer.Stop()
960 self.printButton.Enable(False)
961 if not self._printerConnection.hasActiveConnection() or \
962 self._printerConnection.isActiveConnectionOpen():
963 self.cancelButton.Enable(self._printerConnection.isPrinting() or \
964 self._printerConnection.isPaused())
966 self.cancelButton.Enable(False)
967 self.errorLogButton.Show(self._printerConnection.isInErrorState())
968 self._termInput.Enable(self._printerConnection.isAbleToSendDirectCommand())
971 def _doPrinterConnectionUpdate(self, connection, extraInfo = None):
972 wx.CallAfter(self.__doPrinterConnectionUpdate, connection, extraInfo)
974 for n in xrange(0, 4):
975 t = connection.getTemperature(0)
980 self.temperatureGraph.addPoint(temp, [0] * len(temp), connection.getBedTemperature(), 0)
981 if self._fullscreenTemperature is not None:
982 self._fullscreenTemperature.addPoint(temp, [0] * len(temp), connection.getBedTemperature(), 0)
984 def __doPrinterConnectionUpdate(self, connection, extraInfo):
986 if self._lastUpdateTime + 0.5 > t and extraInfo is None:
988 self._lastUpdateTime = t
990 if extraInfo is not None and len(extraInfo) > 0:
991 self._addTermLog('< %s\n' % (extraInfo))
993 self._updateButtonStates()
995 info = connection.getStatusString()
996 isPrinting = connection.isPrinting() or connection.isPaused()
998 (current, total, z) = connection.getPrintProgress()
1001 progress = float(current) / float(total)
1002 self.progress.SetValue(progress * 1000)
1003 info += (" {:3.1f}% | ".format(progress * 100))
1004 info += (("Z: %.3fmm") % (z))
1006 self.progress.SetValue(0)
1008 if self._printerConnection.getTemperature(0) is not None:
1009 info += ' | Temperature: %d ' % (self._printerConnection.getTemperature(0))
1010 if self._printerConnection.getBedTemperature() > 0:
1011 info += 'Bed: %d' % (self._printerConnection.getBedTemperature())
1012 self.SetTitle(info.replace('\n', ', ').strip(', '))
1013 if isPrinting != self._isPrinting:
1014 self._isPrinting = isPrinting
1015 preventComputerFromSleeping(self, self._isPrinting)
1017 class TemperatureField(wx.Panel):
1018 def __init__(self, parent, callback):
1019 super(TemperatureField, self).__init__(parent)
1020 self.callback = callback
1022 self.SetBackgroundColour(wx.WHITE)
1024 self.text = IntCtrl(self, -1)
1025 self.text.SetBounds(0, 300)
1026 self.text.SetSize((60, 28))
1028 self.unit = wx.StaticBitmap(self, -1, wx.BitmapFromImage(wx.Image(
1029 resources.getPathForImage('print-window-temperature-unit.png'))), (0, 0))
1031 self.button = wx.Button(self, -1, _("Set"))
1032 self.button.SetSize((35, 25))
1033 self.Bind(wx.EVT_BUTTON, lambda e: self.callback(self.text.GetValue()), self.button)
1035 self.text.SetPosition((0, 0))
1036 self.unit.SetPosition((60, 0))
1037 self.button.SetPosition((90, 0))
1040 class TemperatureGraph(wx.Panel):
1041 def __init__(self, parent):
1042 super(TemperatureGraph, self).__init__(parent)
1044 self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
1045 self.Bind(wx.EVT_SIZE, self.OnSize)
1046 self.Bind(wx.EVT_PAINT, self.OnDraw)
1048 self._lastDraw = time.time() - 1.0
1050 self._backBuffer = None
1051 self.addPoint([0]*16, [0]*16, 0, 0)
1053 def Clone(self, parent):
1054 clone = TemperatureGraph(parent)
1055 clone._points = list(self._points)
1058 def OnEraseBackground(self, e):
1061 def OnSize(self, e):
1062 if self._backBuffer is None or self.GetSize() != self._backBuffer.GetSize():
1063 self._backBuffer = wx.EmptyBitmap(*self.GetSizeTuple())
1064 self.UpdateDrawing(True)
1066 def OnDraw(self, e):
1067 dc = wx.BufferedPaintDC(self, self._backBuffer)
1069 def UpdateDrawing(self, force=False):
1071 if (not force and now - self._lastDraw < 1.0) or self._backBuffer is None:
1073 self._lastDraw = now
1075 dc.SelectObject(self._backBuffer)
1076 dc.SetBackground(wx.Brush(wx.WHITE))
1078 dc.SetFont(wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT))
1079 w, h = self.GetSizeTuple()
1080 bgLinePen = wx.Pen('#A0A0A0')
1081 tempPen = wx.Pen('#FF4040')
1082 tempSPPen = wx.Pen('#FFA0A0')
1083 tempPenBG = wx.Pen('#FFD0D0')
1084 bedTempPen = wx.Pen('#4040FF')
1085 bedTempSPPen = wx.Pen('#A0A0FF')
1086 bedTempPenBG = wx.Pen('#D0D0FF')
1088 #Draw the background up to the current temperatures.
1094 for temp, tempSP, bedTemp, bedTempSP, t in self._points:
1095 x1 = int(w - (now - t))
1096 for x in xrange(x0, x1 + 1):
1097 for n in xrange(0, min(len(t0), len(temp))):
1098 t = float(x - x0) / float(x1 - x0 + 1) * (temp[n] - t0[n]) + t0[n]
1099 dc.SetPen(tempPenBG)
1100 dc.DrawLine(x, h, x, h - (t * h / 350))
1101 bt = float(x - x0) / float(x1 - x0 + 1) * (bedTemp - bt0) + bt0
1102 dc.SetPen(bedTempPenBG)
1103 dc.DrawLine(x, h, x, h - (bt * h / 350))
1111 for x in xrange(w, 0, -30):
1112 dc.SetPen(bgLinePen)
1113 dc.DrawLine(x, 0, x, h)
1115 for y in xrange(h - 1, 0, -h * 50 / 350):
1116 dc.SetPen(bgLinePen)
1117 dc.DrawLine(0, y, w, y)
1118 dc.DrawText(str(tmpNr), 0, y - dc.GetFont().GetPixelSize().GetHeight())
1120 dc.DrawLine(0, 0, w, 0)
1121 dc.DrawLine(0, 0, 0, h)
1123 #Draw the main lines
1129 for temp, tempSP, bedTemp, bedTempSP, t in self._points:
1130 x1 = int(w - (now - t))
1131 for x in xrange(x0, x1 + 1):
1132 for n in xrange(0, min(len(t0), len(temp))):
1133 t = float(x - x0) / float(x1 - x0 + 1) * (temp[n] - t0[n]) + t0[n]
1134 tSP = float(x - x0) / float(x1 - x0 + 1) * (tempSP[n] - tSP0[n]) + tSP0[n]
1135 dc.SetPen(tempSPPen)
1136 dc.DrawPoint(x, h - (tSP * h / 350))
1138 dc.DrawPoint(x, h - (t * h / 350))
1139 bt = float(x - x0) / float(x1 - x0 + 1) * (bedTemp - bt0) + bt0
1140 btSP = float(x - x0) / float(x1 - x0 + 1) * (bedTempSP - btSP0) + btSP0
1141 dc.SetPen(bedTempSPPen)
1142 dc.DrawPoint(x, h - (btSP * h / 350))
1143 dc.SetPen(bedTempPen)
1144 dc.DrawPoint(x, h - (bt * h / 350))
1152 self.Refresh(eraseBackground=False)
1155 if len(self._points) > 0 and (time.time() - self._points[0][4]) > w + 20:
1158 def addPoint(self, temp, tempSP, bedTemp, bedTempSP):
1159 if len(self._points) > 0 and time.time() - self._points[-1][4] < 0.5:
1161 for n in xrange(0, len(temp)):
1164 for n in xrange(0, len(tempSP)):
1165 if tempSP[n] is None:
1169 if bedTempSP is None:
1171 self._points.append((temp[:], tempSP[:], bedTemp, bedTempSP, time.time()))
1172 wx.CallAfter(self.UpdateDrawing)
1174 class LogWindow(wx.Frame):
1175 def __init__(self, logText):
1176 super(LogWindow, self).__init__(None, title=_("Error log"))
1177 self.textBox = wx.TextCtrl(self, -1, logText, style=wx.TE_MULTILINE | wx.TE_DONTWRAP | wx.TE_READONLY)
1178 self.SetSize((500, 400))