示例#1
0
 def _createSnapshot(self, *args):
     Logger.log("i", "Creating chitu thumbnail image ...")
     try:
         self._snapshot = Snapshot.snapshot(width=300, height=300)
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")
         self._snapshot = None
 def do_snap(self,gfile):
     img = Snapshot.snapshot(width = 200, height = 200).scaled(200,200,Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
     outdata = ""
     outdata = outdata + self.overseek()
     outdata = outdata + "; bigtree thumbnail end\r\n\r\n"
     outdata = outdata + self.material_usage()
     
     fh = QFile(gfile)
     fh.open(QIODevice.ReadOnly)
     stream = QTextStream(fh)
     stream.setCodec(CODEC)
     fg = stream.readAll() + "\r\n"
     if self.extruder_M2O() == True:
         fg = fg.replace("M104 T0",";M104 T0")
         fg = fg.replace("M104 T1",";M104 T1")
         fg = fg.replace("M109 T0",";M109 T0")
         fg = fg.replace("M109 T1",";M109 T1")
     fh.close()
     bigtree3dfile = os.path.splitext(gfile)[0]+"[Bigtree].gcode"
     fh = QFile(bigtree3dfile)
     fh.open(QIODevice.WriteOnly)
     stream = QTextStream(fh)
     stream.setCodec(CODEC)
     stream << outdata
     stream << fg
     fh.close()
     os.remove(gfile)
示例#3
0
 def _create_thumbnail(self, *args):
     Logger.log("d", "Creating Prusa thumbnail ...")
     try:
         self._thumbnail = Snapshot.snapshot(width=300, height=300)
     except Exception:
         Logger.logException("w", "Failed to create thumbnail")
         self._thumbnail = None
示例#4
0
 def _createSnapshot(self, *args):
     # must be called from the main thread because of OpenGL
     Logger.log("d", "Creating thumbnail image...")
     try:
         self._snapshot = Snapshot.snapshot(width=300, height=300)
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")
         self._snapshot = None  # Failing to create thumbnail should not fail creation of UFP
示例#5
0
 def _createSnapshot(self, *args):
     Logger.log("i", "Creating thumbnail image ...")
     try:
         self._snapshot = Snapshot.snapshot(width=60, height=60)
         Logger.log("i", "self._snapshot => ", dir(self._snapshot))
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")
         self._snapshot = None
示例#6
0
 def _create_snapshot(self, width, height):
     # must be called from the main thread because of OpenGL
     Logger.log("d", "Creating thumbnail image...")
     try:
         snapshot = Snapshot.snapshot(width = width, height = height)
         return snapshot
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")
         return None
示例#7
0
 def _createSnapshot(self, *args):
     # must be called from the main thread because of OpenGL
     Logger.log("d", "Creating thumbnail image...")
     try:
         # Screen seems to be 720px wide, but not fully used to show preview so snapshot at +/- 600px
         self._snapshot = Snapshot.snapshot(width=600, height=600)
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")
         self._snapshot = None  # Failing to create thumbnail should not fail creation of UFP
示例#8
0
 def _createSnapshot(self) -> None:
     self._snapshot = None
     if not CuraApplication.getInstance().isVisible:
         Logger.log("w", "Can't create snapshot when renderer not initialized.")
         return
     Logger.log("i", "Creating thumbnail image (just before slice)...")
     try:
         self._snapshot = Snapshot.snapshot(width = 300, height = 300)
     except:
         Logger.logException("w", "Failed to create snapshot image")
         self._snapshot = None  # Failing to create thumbnail should not fail creation of UFP
示例#9
0
    def _createSnapshot(self):
        Logger.log("d", "Creating thumbnail image...")
        if not CuraApplication.getInstance().isVisible:
            Logger.log("w", "Can't create snapshot when renderer not initialized.")
            return None
        try:
            snapshot = Snapshot.snapshot(width = 300, height = 300)
        except:
            Logger.logException("w", "Failed to create snapshot image")
            return None

        return snapshot
 def overread(self,msize):
     moutdata = ""
     img = Snapshot.snapshot(width = msize.width(), height = msize.height()).scaled(msize.width(),msize.height(),Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
     moutdata = moutdata + ";"+(hex(msize.width())[2:]).rjust(4,'0')+(hex(msize.height())[2:]).rjust(4,'0')+"\r\n"
     pos = QSize(0,0)
     for ypos in range(0,img.height()):
         qrgb = ";"
         for xpos in range(0,img.width()):
             data = img.pixel(xpos,ypos)
             pos.setWidth(pos.width()+1)
             qrgb = qrgb + (hex(((data & 0x00F80000) >> 8 ) | ((data & 0x0000FC00) >> 5 ) | ((data & 0x000000F8) >> 3 ))[2:]).rjust(4,'0')
         pos.setWidth(0)
         pos.setHeight(pos.height()+1)
         moutdata = moutdata + qrgb + "\r\n"
     return moutdata
 def do_snap(self,gfile):
     m0 = Snapshot.snapshot(width = 900, height = 900)
     if m0 is not None:  #if not isinstance(m0,NoneType): #NoneType
         m1 = m0.scaled(150,150,Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
         m2 = m0.scaled(42,42,Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
         if m1:
             hd = []
             ds = self.trans(m2,42,42)
             db = self.trans(m1,150,150)
 
             size0 = len(ds)
             size1 = len(db)
             size2 = os.path.getsize(gfile)
 
             offset = 0
             hd.append(1)
             offset = 25
             hd.extend(i4b(offset))
             hd.extend(i4b(size0))
             offset += size0
             hd.extend(i4b(offset))
             hd.extend(i4b(size1))
             offset += size1
             hd.extend(i4b(offset))
             hd.extend(i4b(size2))
 
             fg = []
             f = open(gfile, 'rb+')
             fg = f.read()
             f.close()
 
             gjz = os.path.splitext(gfile)[0]+".gjz"
             f = open(gjz, 'wb+')
             f.write(bytes(hd))
             f.write(bytes(ds))
             f.write(bytes(db))
             f.write(fg)
             f.close()
             #os.remove(gfile)
         FlyingBearStage.FlyingBearStageIns.setUploadFileNameUSB(gjz)
     else:
         FlyingBearStage.FlyingBearStageIns.setUploadFileNameUSB(gfile)            
     #FlyingBearStage.FlyingBearStageIns.setUploadFileName(gjz)
     CuraApplication.getInstance().getController().setActiveStage("PrepareStage") #setActiveStage("PrepareStage")
     #sleep(1)
     Logger.log("d", "NAME %s",FlyingBearStage.FlyingBearStageIns.getPluginId())
     CuraApplication.getInstance().getController().setActiveStage(FlyingBearStage.FlyingBearStageIns.getPluginId())
 def _createSnapshot(self, g, *args):
     Logger.log("i", "Creating thumbnail image ...")
     try:
         # Convert the image to grayscale, and back to 24bits so it renders properly
         # in printer.
         img = Snapshot.snapshot(width=80, height=60)
         img = img.convertToFormat(QtGui.QImage.Format_Grayscale8)
         img = img.convertToFormat(QtGui.QImage.Format_RGB666)
         # Converts the image into BMP byte array.
         arr = QtCore.QByteArray()
         buff = QtCore.QBuffer(arr)
         buff.open(QtCore.QIODevice.WriteOnly)
         img.save(buff, format="BMP")
         g.bmp = arr.data()
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")
         g.bmp = gx._SAMPLE_BMP
    def _generateSnapshot(self) -> Optional[str]:
        '''Grabs the snapshot from the Cura Backend if one exists and returns it as a buffer.'''
        try:
            Logger.log("i", "Generating Snapshot")
            # Attempt to get the existing snapshot, if it exists (Cura 4.9 and above):
            backend = CuraApplication.getInstance().getBackend()
            snapshot = None if getattr(
                backend, "getLatestSnapshot", None) is None else backend.getLatestSnapshot()

            if snapshot is None:
                Logger.log(
                    "i", "No snapshot from backend, generate snapshot ourselves.")
                # Try to generate a snapshot ourselves (for Cura 4.8 and before, but is not reliable (I think due to threading))
                try:
                    from cura.Snapshot import Snapshot

                    snapshot = Snapshot.snapshot(width=300, height=300)
                except:
                    Logger.log("e", "Failed to create snapshot image")
                    return None

            if snapshot:
                Logger.log("i", "Snapshot Found")

                thumbnail_buffer = QBuffer()
                thumbnail_buffer.open(QBuffer.ReadWrite)
                snapshot.save(thumbnail_buffer, "PNG")

                encodedSnapshot = thumbnail_buffer.data(
                ).toBase64().data().decode("utf-8")

                thumbnail_buffer.close()

                return encodedSnapshot
            else:
                Logger.log("i", "No Snapshot Found")
                return None

        except Exception:
            Logger.logException(
                "e", "Exception raised while saving snapshot")
            return None
 def do_snap(self,gfile):
     img = Snapshot.snapshot(width = 200, height = 200).scaled(200,200,Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
     outdata = ""
     outdata = outdata + self.overseek()
     outdata = outdata + "; bigtree thumbnail end\r\n\r\n"
     fh = QFile(gfile)
     fh.open(QIODevice.ReadOnly)
     stream = QTextStream(fh)
     stream.setCodec(CODEC)
     # lino = 0
     fg = stream.readAll() + "\r\n"
     fh.close()
     bigtree3dfile = os.path.splitext(gfile)[0]+"[Bigtree].gcode"
     fh = QFile(bigtree3dfile)
     fh.open(QIODevice.WriteOnly)
     stream = QTextStream(fh)
     stream.setCodec(CODEC)
     stream << outdata
     stream << fg
     fh.close()
     os.remove(gfile)
    def do_snap(self, gfile):
        m0 = Snapshot.snapshot(width=900, height=900)
        m1 = m0.scaled(150, 150, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
        m2 = m0.scaled(42, 42, Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
        if m1:
            hd = []
            ds = self.trans(m2, 42, 42)
            db = self.trans(m1, 150, 150)

            size0 = len(ds)
            size1 = len(db)
            size2 = os.path.getsize(gfile)

            offset = 0
            hd.append(1)
            offset = 25
            hd.extend(i4b(offset))
            hd.extend(i4b(size0))
            offset += size0
            hd.extend(i4b(offset))
            hd.extend(i4b(size1))
            offset += size1
            hd.extend(i4b(offset))
            hd.extend(i4b(size2))

            fg = []
            f = open(gfile, 'rb+')
            fg = f.read()
            f.close()

            gjz = os.path.splitext(gfile)[0] + ".gjz"
            f = open(gjz, 'wb+')
            f.write(bytes(hd))
            f.write(bytes(ds))
            f.write(bytes(db))
            f.write(fg)
            f.close()
            #os.remove(gfile)

        FlyingBearExtension.FlyingBearExtensionIns.showPluginMainWindow(gjz)
示例#16
0
    def create_snapshot(self, size):

        # Take a snapshot of given size
        snapshot = Snapshot.snapshot(width=size[0], height=size[1])

        # Used for debugging
        #snapshot.save(os.path.dirname(__file__) + "/test.png")

        # Smapshot gcode
        gcode = ''

        # Iterate all of the image  pixels
        for y in range(snapshot.height()):
            for x in range(snapshot.width()):

                # Take pixel data
                pixel = snapshot.pixelColor(x, y)

                # Convert to 16-bit (2-byte) -encoded image
                rgb16 = (pixel.red() >> 3 << 11) | (
                    pixel.green() >> 2 << 5) | (pixel.blue() >> 3)

                # Convert pixel data into hex values
                rgb16_hex = "{:04x}".format(rgb16)

                # Change rndianess to little-endian
                rgb16_hex_le = rgb16_hex[2:4] + rgb16_hex[0:2]

                # Add resulting values to a gcode
                gcode += rgb16_hex_le

            # Add a G-code code
            gcode += '\rM10086 ;'

        # Add new line break
        gcode += '\r'

        # Return resulting G-code
        return gcode
示例#17
0
 def _createSnapshot(self, *args):
     # must be called from the main thread because of OpenGL
     Logger.log("d", "Creating thumbnail image...")
     self._snapshot = Snapshot.snapshot(width = 300, height = 300)
示例#18
0
def take_screenshot():
    cut_image = Snapshot.snapshot(width = 900, height = 900)
    return cut_image
示例#19
0
 def _createSnapshot(self, *args):
     # must be called from the main thread because of OpenGL
     Logger.log("d", "Creating thumbnail image...")
     self._snapshot = Snapshot.snapshot(width=300, height=300)
 def do_snap(self,gfile):
     img = Snapshot.snapshot(width = 200, height = 200).scaled(200,200,Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
 def _createSnapshot(self, width, height):
     Logger.log("d", "Creating thumbnail image...")
     try:
         return Snapshot.snapshot(width, height)
     except Exception:
         Logger.logException("w", "Failed to create snapshot image")