def takeSnapshot(self, path): ''' screen capture in png format :param path: saved file path :return: None ''' p1 = self.cmd.popen(['screencap', '-p'], stdout=PIPE) p = Popen(['perl', '-pe', 's/\x0D\x0D\x0A/\x0A/g'], stdin=p1.stdout, stdout=PIPE) out, error = p.communicate() ba = QByteArray.fromRawData(out) img = QImage.fromData(ba, 'PNG') orient = self.getCurrDisplay()['orientation'] if orient == 1: img = img.transformed(QMatrix().rotate(-90)) elif orient == 2: img = img.transformed(QMatrix().rotate(-180)) elif orient == 3: img = img.transformed(QMatrix().rotate(-270)) img.save(path, 'PNG')
def testIt(self): data = py3k.b("foobar") a = QByteArray.fromRawData(data) self.assertEqual(type(a), QByteArray) self.assertEqual(a.data(), data)