chiark / gitweb /
Update for USB printing dialog
authordaid <daid303@gmail.com>
Tue, 11 Feb 2014 20:02:44 +0000 (21:02 +0100)
committerdaid <daid303@gmail.com>
Tue, 11 Feb 2014 20:02:44 +0000 (21:02 +0100)
Cura/gui/printWindow2.py
Cura/gui/sceneView.py
Cura/gui/util/engineResultView.py
Cura/gui/util/openglGui.py
Cura/gui/util/openglHelpers.py
Cura/gui/util/previewTools.py
Cura/util/machineCom.py
Cura/util/printerConnection/printerConnectionBase.py
Cura/util/printerConnection/serialConnection.py

index d6ab29554a913c72c179e165f8b611b927498411..18a3efe3219ee042e11ee598452b043a5522eb26 100644 (file)
@@ -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())
index 6d263bdd1fe1fdf569154d51235844b4159dbcc0..ec88e4c30ce28deac890677d777619de91f346e5 100644 (file)
@@ -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:
index 06908620193f8e57297e8ebded51d8b1ca0f1d9a..f354088eb5a3259c4c256e44d95ef403e694389b 100644 (file)
@@ -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 *
 
index dbba4a8aaabbd0f95296cf1d92211e9fc1d2a856..37a27ead31796bb3ecd73e7e97a90e1c172a8691 100644 (file)
@@ -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
index c525282671e6fe815e7a42a92bb82df02b5c6f94..ebf4c241ae2cd650ac3f7a253c7543a073c7b462 100644 (file)
@@ -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 *
index db4b7e214bac7b100d828263eb6be498f03b8d49..a64833b7493dd91d27e07e9ce36cf6923109eb9a 100644 (file)
@@ -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 *
 
index ec372df7e440bcebe905a2b08b99c496ff23fa03..dc3430b4c849abffd8c3048c6f3e64d2fd09e678 100644 (file)
@@ -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:
index e0870669377a58a7e7918d962b7adb13b38b49f6..60fe501cf0887de12472e188ace70d9e1c2e6b37 100644 (file)
@@ -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
index 1e8e5b77166db114a45c339bfd907025c116a5b5..0777a570fee776e03671e7e8928de215cee3a01e 100644 (file)
@@ -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