1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
11 #TODO: This does not belong here!
12 if sys.platform.startswith('win'):
13 def preventComputerFromSleeping(frame, prevent):
15 Function used to prevent the computer from going into sleep mode.
16 :param prevent: True = Prevent the system from going to sleep from this point on.
17 :param prevent: False = No longer prevent the system from going to sleep.
19 ES_CONTINUOUS = 0x80000000
20 ES_SYSTEM_REQUIRED = 0x00000001
21 ES_AWAYMODE_REQUIRED = 0x00000040
22 #SetThreadExecutionState returns 0 when failed, which is ignored. The function should be supported from windows XP and up.
24 # For Vista and up we use ES_AWAYMODE_REQUIRED to prevent a print from failing if the PC does go to sleep
25 # As it's not supported on XP, we catch the error and fallback to using ES_SYSTEM_REQUIRED only
26 if ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED | ES_AWAYMODE_REQUIRED) == 0:
27 ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED)
29 ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS)
31 elif sys.platform.startswith('darwin'):
33 bundle = objc.initFrameworkWrapper("IOKit",
34 frameworkIdentifier="com.apple.iokit",
35 frameworkPath=objc.pathForFramework("/System/Library/Frameworks/IOKit.framework"),
37 objc.loadBundleFunctions(bundle, globals(), [("IOPMAssertionCreateWithName", b"i@I@o^I")])
38 def preventComputerFromSleeping(frame, prevent):
40 success, preventComputerFromSleeping.assertionID = IOPMAssertionCreateWithName(kIOPMAssertionTypeNoDisplaySleep, kIOPMAssertionLevelOn, "Cura is printing", None)
41 if success != kIOReturnSuccess:
42 preventComputerFromSleeping.assertionID = None
44 if preventComputerFromSleeping.assertionID is not None:
45 IOPMAssertionRelease(preventComputerFromSleeping.assertionID)
46 preventComputerFromSleeping.assertionID = None
48 def preventComputerFromSleeping(frame, prevent):
49 if os.path.isfile("/usr/bin/xdg-screensaver"):
51 cmd = ['xdg-screensaver', 'suspend' if prevent else 'resume', str(frame.GetHandle())]
56 class printWindowPlugin(wx.Frame):
57 def __init__(self, parent, printerConnection, filename):
58 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()))
59 self._printerConnection = printerConnection
60 self._basePath = os.path.dirname(filename)
61 self._backgroundImage = None
62 self._colorCommandMap = {}
65 self._termInput = None
66 self._termHistory = []
67 self._termHistoryIdx = 0
68 self._progressBar = None
69 self._tempGraph = None
71 self._lastUpdateTime = time.time()
72 self._isPrinting = False
75 'setImage': self.script_setImage,
76 'addColorCommand': self.script_addColorCommand,
77 'addTerminal': self.script_addTerminal,
78 'addTemperatureGraph': self.script_addTemperatureGraph,
79 'addProgressbar': self.script_addProgressbar,
80 'addButton': self.script_addButton,
81 'addSpinner': self.script_addSpinner,
82 'addTextButton': self.script_addTextButton,
84 'sendGCode': self.script_sendGCode,
85 'connect': self.script_connect,
86 'startPrint': self.script_startPrint,
87 'pausePrint': self.script_pausePrint,
88 'cancelPrint': self.script_cancelPrint,
89 'showErrorLog': self.script_showErrorLog,
91 execfile(filename, variables, variables)
93 self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
94 self.Bind(wx.EVT_PAINT, self.OnDraw)
95 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
96 self.Bind(wx.EVT_CLOSE, self.OnClose)
98 self._updateButtonStates()
100 self._printerConnection.addCallback(self._doPrinterConnectionUpdate)
102 if self._printerConnection.hasActiveConnection() and not self._printerConnection.isActiveConnectionOpen():
103 self._printerConnection.openActiveConnection()
105 def script_setImage(self, guiImage, mapImage):
106 self._backgroundImage = wx.BitmapFromImage(wx.Image(os.path.join(self._basePath, guiImage)))
107 self._mapImage = wx.Image(os.path.join(self._basePath, mapImage))
108 self.SetClientSize(self._mapImage.GetSize())
110 def script_addColorCommand(self, r, g, b, command, data = None):
111 self._colorCommandMap[(r, g, b)] = (command, data)
113 def script_addTerminal(self, r, g, b):
114 x, y, w, h = self._getColoredRect(r, g, b)
115 if x < 0 or self._termLog is not None:
117 f = wx.Font(8, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False)
118 self._termLog = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_DONTWRAP)
119 self._termLog.SetFont(f)
120 self._termLog.SetEditable(0)
121 self._termInput = wx.TextCtrl(self, style=wx.TE_PROCESS_ENTER)
122 self._termInput.SetFont(f)
124 self._termLog.SetPosition((x, y))
125 self._termLog.SetSize((w, h - self._termInput.GetSize().GetHeight()))
126 self._termInput.SetPosition((x, y + h - self._termInput.GetSize().GetHeight()))
127 self._termInput.SetSize((w, self._termInput.GetSize().GetHeight()))
128 self.Bind(wx.EVT_TEXT_ENTER, self.OnTermEnterLine, self._termInput)
129 self._termInput.Bind(wx.EVT_CHAR, self.OnTermKey)
131 def script_addTemperatureGraph(self, r, g, b):
132 x, y, w, h = self._getColoredRect(r, g, b)
133 if x < 0 or self._tempGraph is not None:
135 self._tempGraph = TemperatureGraph(self)
137 self._tempGraph.SetPosition((x, y))
138 self._tempGraph.SetSize((w, h))
140 def script_addProgressbar(self, r, g, b):
141 x, y, w, h = self._getColoredRect(r, g, b)
144 self._progressBar = wx.Gauge(self, -1, range=1000)
146 self._progressBar.SetPosition((x, y))
147 self._progressBar.SetSize((w, h))
149 def script_addButton(self, r, g, b, text, command, data = None):
150 x, y, w, h = self._getColoredRect(r, g, b)
153 button = wx.Button(self, -1, _(text))
154 button.SetPosition((x, y))
155 button.SetSize((w, h))
156 button.command = command
158 self._buttonList.append(button)
159 self.Bind(wx.EVT_BUTTON, lambda e: command(data), button)
161 def script_addSpinner(self, r, g, b, command, data):
162 x, y, w, h = self._getColoredRect(r, g, b)
166 def run_command(spinner):
167 value = spinner.GetValue()
168 print "Value (%s) and (%s)" % (spinner.last_value, value)
169 if spinner.last_value != '' and value != 0:
170 spinner.command(spinner.data % value)
171 spinner.last_value = value
173 spinner = wx.SpinCtrl(self, -1, style=wx.TE_PROCESS_ENTER)
174 spinner.SetRange(0, 300)
175 spinner.SetPosition((x, y))
176 spinner.SetSize((w, h))
178 spinner.command = command
180 spinner.last_value = ''
181 self._buttonList.append(spinner)
182 self.Bind(wx.EVT_SPINCTRL, lambda e: run_command(spinner), spinner)
184 def script_addTextButton(self, r_text, g_text, b_text, r_button, g_button, b_button, button_text, command, data):
185 x_text, y_text, w_text, h_text = self._getColoredRect(r_text, g_text, b_text)
188 x_button, y_button, w_button, h_button = self._getColoredRect(r_button, g_button, b_button)
191 from wx.lib.intctrl import IntCtrl
192 text = IntCtrl(self, -1)
193 text.SetBounds(0, 300)
194 text.SetPosition((x_text, y_text))
195 text.SetSize((w_text, h_text))
197 button = wx.Button(self, -1, _(button_text))
198 button.SetPosition((x_button, y_button))
199 button.SetSize((w_button, h_button))
200 button.command = command
202 self._buttonList.append(button)
203 self.Bind(wx.EVT_BUTTON, lambda e: command(data % text.GetValue()), button)
205 def _getColoredRect(self, r, g, b):
206 for x in xrange(0, self._mapImage.GetWidth()):
207 for y in xrange(0, self._mapImage.GetHeight()):
208 if self._mapImage.GetRed(x, y) == r and self._mapImage.GetGreen(x, y) == g and self._mapImage.GetBlue(x, y) == b:
210 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:
213 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:
216 print "Failed to find color: ", r, g, b
219 def script_sendGCode(self, data = None):
220 for line in data.split(';'):
223 self._printerConnection.sendCommand(line)
225 def script_connect(self, data = None):
226 self._printerConnection.openActiveConnection()
228 def script_startPrint(self, data = None):
229 self._printerConnection.startPrint()
231 def script_cancelPrint(self, e):
232 self._printerConnection.cancelPrint()
234 def script_pausePrint(self, e):
235 self._printerConnection.pause(not self._printerConnection.isPaused())
237 def script_showErrorLog(self, e):
238 LogWindow(self._printerConnection.getErrorLog())
240 def OnEraseBackground(self, e):
244 dc = wx.BufferedPaintDC(self, self._backgroundImage)
246 def OnLeftClick(self, e):
247 r = self._mapImage.GetRed(e.GetX(), e.GetY())
248 g = self._mapImage.GetGreen(e.GetX(), e.GetY())
249 b = self._mapImage.GetBlue(e.GetX(), e.GetY())
250 if (r, g, b) in self._colorCommandMap:
251 command = self._colorCommandMap[(r, g, b)]
252 command[0](command[1])
254 def OnClose(self, e):
255 if self._printerConnection.hasActiveConnection():
256 if self._printerConnection.isPrinting() or self._printerConnection.isPaused():
257 pass #TODO: Give warning that the close will kill the print.
258 self._printerConnection.closeActiveConnection()
259 self._printerConnection.removeCallback(self._doPrinterConnectionUpdate)
260 #TODO: When multiple printer windows are open, closing one will enable sleeping again.
261 preventComputerFromSleeping(self, False)
264 def OnTermEnterLine(self, e):
265 if not self._printerConnection.isAbleToSendDirectCommand():
267 line = self._termInput.GetValue()
270 self._addTermLog('> %s\n' % (line))
271 self._printerConnection.sendCommand(line)
272 self._termHistory.append(line)
273 self._termHistoryIdx = len(self._termHistory)
274 self._termInput.SetValue('')
276 def OnTermKey(self, e):
277 if len(self._termHistory) > 0:
278 if e.GetKeyCode() == wx.WXK_UP:
279 self._termHistoryIdx -= 1
280 if self._termHistoryIdx < 0:
281 self._termHistoryIdx = len(self._termHistory) - 1
282 self._termInput.SetValue(self._termHistory[self._termHistoryIdx])
283 if e.GetKeyCode() == wx.WXK_DOWN:
284 self._termHistoryIdx -= 1
285 if self._termHistoryIdx >= len(self._termHistory):
286 self._termHistoryIdx = 0
287 self._termInput.SetValue(self._termHistory[self._termHistoryIdx])
290 def _addTermLog(self, line):
291 if self._termLog is not None:
292 if len(self._termLog.GetValue()) > 10000:
293 self._termLog.SetValue(self._termLog.GetValue()[-10000:])
294 self._termLog.SetInsertionPointEnd()
295 if type(line) != unicode:
296 line = unicode(line, 'utf-8', 'replace')
297 self._termLog.AppendText(line.encode('utf-8', 'replace'))
299 def _updateButtonStates(self):
300 for button in self._buttonList:
301 if button.command == self.script_connect:
302 button.Show(self._printerConnection.hasActiveConnection())
303 button.Enable(not self._printerConnection.isActiveConnectionOpen() and \
304 not self._printerConnection.isActiveConnectionOpening())
305 elif button.command == self.script_pausePrint:
306 button.Show(self._printerConnection.hasPause())
307 if not self._printerConnection.hasActiveConnection() or \
308 self._printerConnection.isActiveConnectionOpen():
309 button.Enable(self._printerConnection.isPrinting() or \
310 self._printerConnection.isPaused())
311 if self._printerConnection.isPaused():
312 button.SetLabel(_("Resume"))
314 button.SetLabel(_("Pause"))
317 elif button.command == self.script_startPrint:
318 if not self._printerConnection.hasActiveConnection() or \
319 self._printerConnection.isActiveConnectionOpen():
320 button.Enable(not self._printerConnection.isPrinting() and \
321 not self._printerConnection.isPaused())
324 elif button.command == self.script_cancelPrint:
325 if not self._printerConnection.hasActiveConnection() or \
326 self._printerConnection.isActiveConnectionOpen():
327 button.Enable(self._printerConnection.isPrinting() or \
328 self._printerConnection.isPaused())
331 elif button.command == self.script_showErrorLog:
332 button.Show(self._printerConnection.isInErrorState())
333 if self._termInput is not None:
334 self._termInput.Enable(self._printerConnection.isAbleToSendDirectCommand())
336 def _doPrinterConnectionUpdate(self, connection, extraInfo = None):
337 wx.CallAfter(self.__doPrinterConnectionUpdate, connection, extraInfo)
338 if self._tempGraph is not None:
340 for n in xrange(0, 4):
341 t = connection.getTemperature(0)
346 self._tempGraph.addPoint(temp, [0] * len(temp), connection.getBedTemperature(), 0)
348 def __doPrinterConnectionUpdate(self, connection, extraInfo):
350 if self._lastUpdateTime + 0.5 > t and extraInfo is None:
352 self._lastUpdateTime = t
354 if extraInfo is not None:
355 self._addTermLog('< %s\n' % (extraInfo))
357 self._updateButtonStates()
358 isPrinting = connection.isPrinting() or connection.isPaused()
359 if self._progressBar is not None:
361 self._progressBar.SetValue(connection.getPrintProgress() * 1000)
363 self._progressBar.SetValue(0)
364 info = connection.getStatusString()
366 if self._printerConnection.getTemperature(0) is not None:
367 info += 'Temperature: %d' % (self._printerConnection.getTemperature(0))
368 if self._printerConnection.getBedTemperature() > 0:
369 info += ' Bed: %d' % (self._printerConnection.getBedTemperature())
370 if self._infoText is not None:
371 self._infoText.SetLabel(info)
373 self.SetTitle(info.replace('\n', ', '))
374 if isPrinting != self._isPrinting:
375 self._isPrinting = isPrinting
376 preventComputerFromSleeping(self, self._isPrinting)
378 class printWindowBasic(wx.Frame):
380 Printing window for USB printing, network printing, and any other type of printer connection we can think off.
381 This is only a basic window with minimal information.
383 def __init__(self, parent, printerConnection):
384 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()))
385 self._printerConnection = printerConnection
386 self._lastUpdateTime = 0
387 self._isPrinting = False
389 self.SetSizer(wx.BoxSizer())
390 self.panel = wx.Panel(self)
391 self.GetSizer().Add(self.panel, 1, flag=wx.EXPAND)
392 self.sizer = wx.GridBagSizer(2, 2)
393 self.panel.SetSizer(self.sizer)
395 self.powerWarningText = wx.StaticText(parent=self.panel,
397 label=_("Your computer is running on battery power.\nConnect your computer to AC power or your print might not finish."),
398 style=wx.ALIGN_CENTER)
399 self.powerWarningText.SetBackgroundColour('red')
400 self.powerWarningText.SetForegroundColour('white')
401 self.powerManagement = power.PowerManagement()
402 self.powerWarningTimer = wx.Timer(self)
403 self.Bind(wx.EVT_TIMER, self.OnPowerWarningChange, self.powerWarningTimer)
404 self.OnPowerWarningChange(None)
405 self.powerWarningTimer.Start(10000)
407 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"))
409 self.connectButton = wx.Button(self.panel, -1, _("Connect"))
410 #self.loadButton = wx.Button(self.panel, -1, 'Load')
411 self.printButton = wx.Button(self.panel, -1, _("Print"))
412 self.pauseButton = wx.Button(self.panel, -1, _("Pause"))
413 self.cancelButton = wx.Button(self.panel, -1, _("Cancel print"))
414 self.errorLogButton = wx.Button(self.panel, -1, _("Error log"))
415 self.progress = wx.Gauge(self.panel, -1, range=1000)
417 self.sizer.Add(self.powerWarningText, pos=(0, 0), span=(1, 5), flag=wx.EXPAND|wx.BOTTOM, border=5)
418 self.sizer.Add(self.statsText, pos=(1, 0), span=(1, 5), flag=wx.LEFT, border=5)
419 self.sizer.Add(self.connectButton, pos=(2, 0))
420 #self.sizer.Add(self.loadButton, pos=(2,1))
421 self.sizer.Add(self.printButton, pos=(2, 1))
422 self.sizer.Add(self.pauseButton, pos=(2, 2))
423 self.sizer.Add(self.cancelButton, pos=(2, 3))
424 self.sizer.Add(self.errorLogButton, pos=(2, 4))
425 self.sizer.Add(self.progress, pos=(3, 0), span=(1, 5), flag=wx.EXPAND)
427 self.Bind(wx.EVT_CLOSE, self.OnClose)
428 self.connectButton.Bind(wx.EVT_BUTTON, self.OnConnect)
429 #self.loadButton.Bind(wx.EVT_BUTTON, self.OnLoad)
430 self.printButton.Bind(wx.EVT_BUTTON, self.OnPrint)
431 self.pauseButton.Bind(wx.EVT_BUTTON, self.OnPause)
432 self.cancelButton.Bind(wx.EVT_BUTTON, self.OnCancel)
433 self.errorLogButton.Bind(wx.EVT_BUTTON, self.OnErrorLog)
439 self.progress.SetMinSize(self.progress.GetSize())
440 self.statsText.SetLabel('\n\n\n\n\n\n')
441 self._updateButtonStates()
443 self._printerConnection.addCallback(self._doPrinterConnectionUpdate)
445 if self._printerConnection.hasActiveConnection() and not self._printerConnection.isActiveConnectionOpen():
446 self._printerConnection.openActiveConnection()
448 def OnPowerWarningChange(self, e):
449 type = self.powerManagement.get_providing_power_source_type()
450 if type == power.POWER_TYPE_AC and self.powerWarningText.IsShown():
451 self.powerWarningText.Hide()
456 elif type != power.POWER_TYPE_AC and not self.powerWarningText.IsShown():
457 self.powerWarningText.Show()
463 def OnClose(self, e):
464 if self._printerConnection.hasActiveConnection():
465 if self._printerConnection.isPrinting() or self._printerConnection.isPaused():
466 pass #TODO: Give warning that the close will kill the print.
467 self._printerConnection.closeActiveConnection()
468 self._printerConnection.removeCallback(self._doPrinterConnectionUpdate)
469 #TODO: When multiple printer windows are open, closing one will enable sleeping again.
470 preventComputerFromSleeping(self, False)
473 def OnConnect(self, e):
474 self._printerConnection.openActiveConnection()
479 def OnPrint(self, e):
480 self._printerConnection.startPrint()
482 def OnCancel(self, e):
483 self._printerConnection.cancelPrint()
485 def OnPause(self, e):
486 self._printerConnection.pause(not self._printerConnection.isPaused())
488 def OnErrorLog(self, e):
489 LogWindow(self._printerConnection.getErrorLog())
491 def _doPrinterConnectionUpdate(self, connection, extraInfo = None):
492 wx.CallAfter(self.__doPrinterConnectionUpdate, connection, extraInfo)
493 #temp = [connection.getTemperature(0)]
494 #self.temperatureGraph.addPoint(temp, [0], connection.getBedTemperature(), 0)
496 def __doPrinterConnectionUpdate(self, connection, extraInfo):
498 if self._lastUpdateTime + 0.5 > t and extraInfo is None:
500 self._lastUpdateTime = t
502 if extraInfo is not None:
503 self._addTermLog('< %s\n' % (extraInfo))
505 self._updateButtonStates()
506 isPrinting = connection.isPrinting() or connection.isPaused()
508 self.progress.SetValue(connection.getPrintProgress() * 1000)
510 self.progress.SetValue(0)
511 info = connection.getStatusString()
513 if self._printerConnection.getTemperature(0) is not None:
514 info += 'Temperature: %d' % (self._printerConnection.getTemperature(0))
515 if self._printerConnection.getBedTemperature() > 0:
516 info += ' Bed: %d' % (self._printerConnection.getBedTemperature())
518 self.statsText.SetLabel(info)
519 if isPrinting != self._isPrinting:
520 self._isPrinting = isPrinting
521 preventComputerFromSleeping(self, self._isPrinting)
524 def _addTermLog(self, msg):
527 def _addTermLog(self, msg):
530 def _updateButtonStates(self):
531 self.connectButton.Show(self._printerConnection.hasActiveConnection())
532 self.connectButton.Enable(not self._printerConnection.isActiveConnectionOpen() and not self._printerConnection.isActiveConnectionOpening())
533 self.pauseButton.Show(self._printerConnection.hasPause())
534 if not self._printerConnection.hasActiveConnection() or self._printerConnection.isActiveConnectionOpen():
535 self.printButton.Enable(not self._printerConnection.isPrinting() and \
536 not self._printerConnection.isPaused())
537 self.pauseButton.Enable(self._printerConnection.isPrinting())
538 self.cancelButton.Enable(self._printerConnection.isPrinting())
540 self.printButton.Enable(False)
541 self.pauseButton.Enable(False)
542 self.cancelButton.Enable(False)
543 self.errorLogButton.Show(self._printerConnection.isInErrorState())
545 class TemperatureGraph(wx.Panel):
546 def __init__(self, parent):
547 super(TemperatureGraph, self).__init__(parent)
549 self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground)
550 self.Bind(wx.EVT_SIZE, self.OnSize)
551 self.Bind(wx.EVT_PAINT, self.OnDraw)
553 self._lastDraw = time.time() - 1.0
555 self._backBuffer = None
556 self.addPoint([0]*16, [0]*16, 0, 0)
558 def OnEraseBackground(self, e):
562 if self._backBuffer is None or self.GetSize() != self._backBuffer.GetSize():
563 self._backBuffer = wx.EmptyBitmap(*self.GetSizeTuple())
564 self.UpdateDrawing(True)
567 dc = wx.BufferedPaintDC(self, self._backBuffer)
569 def UpdateDrawing(self, force=False):
571 if (not force and now - self._lastDraw < 1.0) or self._backBuffer is None:
575 dc.SelectObject(self._backBuffer)
577 dc.SetFont(wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT))
578 w, h = self.GetSizeTuple()
579 bgLinePen = wx.Pen('#A0A0A0')
580 tempPen = wx.Pen('#FF4040')
581 tempSPPen = wx.Pen('#FFA0A0')
582 tempPenBG = wx.Pen('#FFD0D0')
583 bedTempPen = wx.Pen('#4040FF')
584 bedTempSPPen = wx.Pen('#A0A0FF')
585 bedTempPenBG = wx.Pen('#D0D0FF')
587 #Draw the background up to the current temperatures.
593 for temp, tempSP, bedTemp, bedTempSP, t in self._points:
594 x1 = int(w - (now - t))
595 for x in xrange(x0, x1 + 1):
596 for n in xrange(0, min(len(t0), len(temp))):
597 t = float(x - x0) / float(x1 - x0 + 1) * (temp[n] - t0[n]) + t0[n]
599 dc.DrawLine(x, h, x, h - (t * h / 350))
600 bt = float(x - x0) / float(x1 - x0 + 1) * (bedTemp - bt0) + bt0
601 dc.SetPen(bedTempPenBG)
602 dc.DrawLine(x, h, x, h - (bt * h / 350))
610 for x in xrange(w, 0, -30):
612 dc.DrawLine(x, 0, x, h)
614 for y in xrange(h - 1, 0, -h * 50 / 350):
616 dc.DrawLine(0, y, w, y)
617 dc.DrawText(str(tmpNr), 0, y - dc.GetFont().GetPixelSize().GetHeight())
619 dc.DrawLine(0, 0, w, 0)
620 dc.DrawLine(0, 0, 0, h)
628 for temp, tempSP, bedTemp, bedTempSP, t in self._points:
629 x1 = int(w - (now - t))
630 for x in xrange(x0, x1 + 1):
631 for n in xrange(0, min(len(t0), len(temp))):
632 t = float(x - x0) / float(x1 - x0 + 1) * (temp[n] - t0[n]) + t0[n]
633 tSP = float(x - x0) / float(x1 - x0 + 1) * (tempSP[n] - tSP0[n]) + tSP0[n]
635 dc.DrawPoint(x, h - (tSP * h / 350))
637 dc.DrawPoint(x, h - (t * h / 350))
638 bt = float(x - x0) / float(x1 - x0 + 1) * (bedTemp - bt0) + bt0
639 btSP = float(x - x0) / float(x1 - x0 + 1) * (bedTempSP - btSP0) + btSP0
640 dc.SetPen(bedTempSPPen)
641 dc.DrawPoint(x, h - (btSP * h / 350))
642 dc.SetPen(bedTempPen)
643 dc.DrawPoint(x, h - (bt * h / 350))
651 self.Refresh(eraseBackground=False)
654 if len(self._points) > 0 and (time.time() - self._points[0][4]) > w + 20:
657 def addPoint(self, temp, tempSP, bedTemp, bedTempSP):
658 if len(self._points) > 0 and time.time() - self._points[-1][4] < 0.5:
660 for n in xrange(0, len(temp)):
663 for n in xrange(0, len(tempSP)):
664 if tempSP[n] is None:
668 if bedTempSP is None:
670 self._points.append((temp[:], tempSP[:], bedTemp, bedTempSP, time.time()))
671 wx.CallAfter(self.UpdateDrawing)
674 class LogWindow(wx.Frame):
675 def __init__(self, logText):
676 super(LogWindow, self).__init__(None, title=_("Error log"))
677 self.textBox = wx.TextCtrl(self, -1, logText, style=wx.TE_MULTILINE | wx.TE_DONTWRAP | wx.TE_READONLY)
678 self.SetSize((500, 400))