chiark / gitweb /
Only prevent sleep if we are printing
authorYouness Alaoui <kakaroto@kakaroto.homelinux.net>
Wed, 31 Dec 2014 03:40:09 +0000 (22:40 -0500)
committerYouness Alaoui <kakaroto@kakaroto.homelinux.net>
Wed, 31 Dec 2014 03:40:12 +0000 (22:40 -0500)
Preventing sleep was happening whenever the print window was open
but it should prevent sleep only if we are printing.
If we close the print window though, it will re-enable sleep capabilities
because we wouldn't be able to know when the print has finished anymore

Cura/gui/printWindow.py

index 26ec7aa3ba017120eda32d8c0c985c8a606d8c78..8a831bed9b616bc1f711a5f497b39e2f04e5722e 100644 (file)
@@ -44,6 +44,7 @@ class printWindowPlugin(wx.Frame):
                self._tempGraph = None
                self._infoText = None
                self._lastUpdateTime = time.time()
+               self._isPrinting = False
 
                variables = {
                        'setImage': self.script_setImage,
@@ -75,7 +76,6 @@ class printWindowPlugin(wx.Frame):
 
                if self._printerConnection.hasActiveConnection() and not self._printerConnection.isActiveConnectionOpen():
                        self._printerConnection.openActiveConnection()
-               preventComputerFromSleeping(True)
 
        def script_setImage(self, guiImage, mapImage):
                self._backgroundImage = wx.BitmapFromImage(wx.Image(os.path.join(self._basePath, guiImage)))
@@ -334,6 +334,9 @@ class printWindowPlugin(wx.Frame):
                        self._infoText.SetLabel(info)
                else:
                        self.SetTitle(info.replace('\n', ', '))
+               if connection.isPrinting() != self._isPrinting:
+                       self._isPrinting = connection.isPrinting()
+                       preventComputerFromSleeping(self._isPrinting)
 
 class printWindowBasic(wx.Frame):
        """
@@ -344,6 +347,7 @@ class printWindowBasic(wx.Frame):
                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
+               self._isPrinting = False
 
                self.SetSizer(wx.BoxSizer())
                self.panel = wx.Panel(self)
@@ -403,7 +407,6 @@ class printWindowBasic(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()
@@ -475,6 +478,10 @@ class printWindowBasic(wx.Frame):
                        info += ' Bed: %d' % (self._printerConnection.getBedTemperature())
                info += '\n\n'
                self.statsText.SetLabel(info)
+               if connection.isPrinting() != self._isPrinting:
+                       self._isPrinting = connection.isPrinting()
+                       preventComputerFromSleeping(self._isPrinting)
+
 
        def _updateButtonStates(self):
                self.connectButton.Show(self._printerConnection.hasActiveConnection())