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
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()
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):
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())
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
self._platformMesh = {}
self._platformTexture = None
self._isSimpleMode = True
- self._usbPrintMonitor = printWindow.printProcessMonitor(lambda : self._queueRefresh())
self._printerConnectionManager = printerConnectionManager.PrinterConnectionManager()
self._viewport = None
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())):
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: