From: daid Date: Tue, 11 Feb 2014 20:02:44 +0000 (+0100) Subject: Update for USB printing dialog X-Git-Tag: 14.02-RC1~19 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=045b99d0bc4730b9e6eccf9eaf5f16cfdeebdf3f;p=cura.git Update for USB printing dialog --- diff --git a/Cura/gui/printWindow2.py b/Cura/gui/printWindow2.py index d6ab2955..18a3efe3 100644 --- a/Cura/gui/printWindow2.py +++ b/Cura/gui/printWindow2.py @@ -3,17 +3,78 @@ __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AG import wx import power import time +import sys +import os +import ctypes + +#TODO: This does not belong here! +if sys.platform.startswith('win'): + def preventComputerFromSleeping(prevent): + """ + Function used to prevent the computer from going into sleep mode. + :param prevent: True = Prevent the system from going to sleep from this point on. + :param prevent: False = No longer prevent the system from going to sleep. + """ + ES_CONTINUOUS = 0x80000000 + ES_SYSTEM_REQUIRED = 0x00000001 + #SetThreadExecutionState returns 0 when failed, which is ignored. The function should be supported from windows XP and up. + if prevent: + ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_SYSTEM_REQUIRED) + else: + ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS) + +else: + def preventComputerFromSleeping(prevent): + #No preventComputerFromSleeping for MacOS and Linux yet. + pass + +class printWindowPlugin(wx.Frame): + def __init__(self, parent, printerConnection, filename): + super(printWindowPlugin, 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())) + self._printerConnection = printerConnection + self._basePath = os.path.dirname(filename) + self._backgroundImage = None + self._colorCommandMap = {} + + variables = { + 'setImage': self.setImage, + 'addColorCommand': self.addColorCommand, + } + execfile(filename, variables, variables) -from wx.lib import buttons + self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) + self.Bind(wx.EVT_PAINT, self.OnDraw) + self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick) + + def setImage(self, guiImage, mapImage): + self._backgroundImage = wx.BitmapFromImage(wx.Image(os.path.join(self._basePath, guiImage))) + self._mapImage = wx.Image(os.path.join(self._basePath, mapImage)) + self.SetSize(self._backgroundImage.GetSize()) + + def addColorCommand(self, r, g, b, command): + self._colorCommandMap[(r, g, b)] = command + + def OnEraseBackground(self, e): + pass + + def OnDraw(self, e): + dc = wx.BufferedPaintDC(self, self._backgroundImage) -from Cura.util import profile -from Cura.util import resources + def OnLeftClick(self, e): + r = self._mapImage.GetRed(e.GetX(), e.GetY()) + g = self._mapImage.GetGreen(e.GetX(), e.GetY()) + b = self._mapImage.GetBlue(e.GetX(), e.GetY()) + if (r, g, b) in self._colorCommandMap: + print self._colorCommandMap[(r, g, b)] -class printWindow(wx.Frame): - "Main user interface window" +class printWindowBasic(wx.Frame): + """ + Printing window for USB printing, network printing, and any other type of printer connection we can think off. + This is only a basic window with minimal information. + """ def __init__(self, parent, printerConnection): - super(printWindow, 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())) + 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())) self._printerConnection = printerConnection self._lastUpdateTime = 0 @@ -75,6 +136,7 @@ class printWindow(wx.Frame): if self._printerConnection.hasActiveConnection() and not self._printerConnection.isActiveConnectionOpen(): self._printerConnection.openActiveConnection() + preventComputerFromSleeping(True) def OnPowerWarningChange(self, e): type = self.powerManagement.get_providing_power_source_type() @@ -97,6 +159,8 @@ class printWindow(wx.Frame): pass #TODO: Give warning that the close will kill the print. self._printerConnection.closeActiveConnection() self._printerConnection.removeCallback(self._doPrinterConnectionUpdate) + #TODO: When multiple printer windows are open, closing one will enable sleeping again. + preventComputerFromSleeping(False) self.Destroy() def OnConnect(self, e): @@ -191,7 +255,7 @@ class printWindow(wx.Frame): def _updateButtonStates(self): self.connectButton.Show(self._printerConnection.hasActiveConnection()) - self.connectButton.Enable(not self._printerConnection.isActiveConnectionOpen()) + self.connectButton.Enable(not self._printerConnection.isActiveConnectionOpen() and not self._printerConnection.isActiveConnectionOpening()) self.pauseButton.Show(self._printerConnection.hasPause()) if not self._printerConnection.hasActiveConnection() or self._printerConnection.isActiveConnectionOpen(): self.printButton.Enable(not self._printerConnection.isPrinting()) diff --git a/Cura/gui/sceneView.py b/Cura/gui/sceneView.py index 6d263bdd..ec88e4c3 100644 --- a/Cura/gui/sceneView.py +++ b/Cura/gui/sceneView.py @@ -11,18 +11,16 @@ import platform import cStringIO as StringIO import OpenGL -#OpenGL.ERROR_CHECKING = False +OpenGL.ERROR_CHECKING = False from OpenGL.GLU import * from OpenGL.GL import * -from Cura.gui import printWindow from Cura.gui import printWindow2 from Cura.util import profile from Cura.util import meshLoader from Cura.util import objectScene from Cura.util import resources from Cura.util import sliceEngine -from Cura.util import machineCom from Cura.util import removableStorage from Cura.util import explorer from Cura.util.printerConnection import printerConnectionManager @@ -55,7 +53,6 @@ class SceneView(openglGui.glGuiPanel): self._platformMesh = {} self._platformTexture = None self._isSimpleMode = True - self._usbPrintMonitor = printWindow.printProcessMonitor(lambda : self._queueRefresh()) self._printerConnectionManager = printerConnectionManager.PrinterConnectionManager() self._viewport = None @@ -273,7 +270,8 @@ class SceneView(openglGui.glGuiPanel): def _openPrintWindowForConnection(self, connection): print '_openPrintWindowForConnection', connection.getName() if connection.window is None or not connection.window: - connection.window = printWindow2.printWindow(self, connection) + #connection.window = printWindow2.printWindowPlugin(self, connection, "C:/Software/Cura/Cura/plugins/PronterfaceUI/script.py") + connection.window = printWindow2.printWindowBasic(self, connection) connection.window.Show() connection.window.Raise() if not connection.loadGCodeData(StringIO.StringIO(self._engine.getResult().getGCode())): @@ -1118,30 +1116,6 @@ class SceneView(openglGui.glGuiPanel): self._drawMachine() - if self._usbPrintMonitor.getState() == 'PRINTING' and self._usbPrintMonitor.getID() == self._engine.getID(): - z = self._usbPrintMonitor.getZ() - if self.viewMode == 'gcode': - layer_height = profile.getProfileSettingFloat('layer_height') - layer1_height = profile.getProfileSettingFloat('bottom_thickness') - if layer_height > 0: - if layer1_height > 0: - layer = int((z - layer1_height) / layer_height) + 1 - else: - layer = int(z / layer_height) - else: - layer = 1 - self.layerSelect.setValue(layer) - else: - size = self._machineSize #Typing is hard. - glEnable(GL_BLEND) - glColor4ub(255,255,0,128) - glBegin(GL_QUADS) - glVertex3f(-size[0]/2,-size[1]/2, z) - glVertex3f( size[0]/2,-size[1]/2, z) - glVertex3f( size[0]/2, size[1]/2, z) - glVertex3f(-size[0]/2, size[1]/2, z) - glEnd() - if self.viewMode != 'gcode': #Draw the object box-shadow, so you can see where it will collide with other objects. if self._selectedObj is not None: diff --git a/Cura/gui/util/engineResultView.py b/Cura/gui/util/engineResultView.py index 06908620..f354088e 100644 --- a/Cura/gui/util/engineResultView.py +++ b/Cura/gui/util/engineResultView.py @@ -5,7 +5,7 @@ import numpy import math import OpenGL -#OpenGL.ERROR_CHECKING = False +OpenGL.ERROR_CHECKING = False from OpenGL.GLU import * from OpenGL.GL import * diff --git a/Cura/gui/util/openglGui.py b/Cura/gui/util/openglGui.py index dbba4a8a..37a27ead 100644 --- a/Cura/gui/util/openglGui.py +++ b/Cura/gui/util/openglGui.py @@ -9,7 +9,7 @@ import time from wx import glcanvas import OpenGL -#OpenGL.ERROR_CHECKING = False +OpenGL.ERROR_CHECKING = False from OpenGL.GL import * from Cura.util import version diff --git a/Cura/gui/util/openglHelpers.py b/Cura/gui/util/openglHelpers.py index c5252826..ebf4c241 100644 --- a/Cura/gui/util/openglHelpers.py +++ b/Cura/gui/util/openglHelpers.py @@ -9,7 +9,7 @@ from Cura.util.resources import getPathForImage import OpenGL -#OpenGL.ERROR_CHECKING = False +OpenGL.ERROR_CHECKING = False from OpenGL.GLUT import * from OpenGL.GLU import * from OpenGL.GL import * diff --git a/Cura/gui/util/previewTools.py b/Cura/gui/util/previewTools.py index db4b7e21..a64833b7 100644 --- a/Cura/gui/util/previewTools.py +++ b/Cura/gui/util/previewTools.py @@ -5,7 +5,7 @@ import wx import numpy import OpenGL -#OpenGL.ERROR_CHECKING = False +OpenGL.ERROR_CHECKING = False from OpenGL.GLU import * from OpenGL.GL import * diff --git a/Cura/util/machineCom.py b/Cura/util/machineCom.py index ec372df7..dc3430b4 100644 --- a/Cura/util/machineCom.py +++ b/Cura/util/machineCom.py @@ -326,6 +326,11 @@ class MachineCom(object): baudrate = self._baudrate if baudrate == 0: baudrate = self._baudrateDetectList.pop(0) + if len(self._serialDetectList) < 1: + self._log("Found no ports to try for auto detection") + self._errorValue = 'Failed to autodetect serial port.' + self._changeState(self.STATE_ERROR) + return port = self._serialDetectList.pop(0) self._log("Connecting to: %s with baudrate: %s (auto)" % (port, baudrate)) try: diff --git a/Cura/util/printerConnection/printerConnectionBase.py b/Cura/util/printerConnection/printerConnectionBase.py index e0870669..60fe501c 100644 --- a/Cura/util/printerConnection/printerConnectionBase.py +++ b/Cura/util/printerConnection/printerConnectionBase.py @@ -75,6 +75,10 @@ class printerConnectionBase(object): def isActiveConnectionOpen(self): return False + #Are we trying to open an active connection right now. + def isActiveConnectionOpening(self): + return False + #Returns true if we have the ability to pause the file printing. def hasPause(self): return False diff --git a/Cura/util/printerConnection/serialConnection.py b/Cura/util/printerConnection/serialConnection.py index 1e8e5b77..0777a570 100644 --- a/Cura/util/printerConnection/serialConnection.py +++ b/Cura/util/printerConnection/serialConnection.py @@ -125,6 +125,12 @@ class serialConnection(printerConnectionBase.printerConnectionBase): return False return self._commState == machineCom.MachineCom.STATE_OPERATIONAL or self._commState == machineCom.MachineCom.STATE_PRINTING or self._commState == machineCom.MachineCom.STATE_PAUSED + #Are we trying to open an active connection right now. + def isActiveConnectionOpening(self): + if self._process is None: + return False + return self._commState == machineCom.MachineCom.STATE_OPEN_SERIAL or self._commState == machineCom.MachineCom.STATE_CONNECTING or self._commState == machineCom.MachineCom.STATE_DETECT_SERIAL or self._commState == machineCom.MachineCom.STATE_DETECT_BAUDRATE + def getTemperature(self, extruder): if extruder >= len(self._temperature): return None