def _stream_for_connection(connection): """ Create a UTF_8 encoded text stream from the given ``connection``. """ stream = QTextStream(connection) stream.setCodec(QTextCodec.codecForName(b'utf-8')) return stream
def _write_doc_to_path(doc, path): # write QDomDocument to path as HROX hrox_file = QFile(path) if not hrox_file.open(QFile.WriteOnly): raise RuntimeError("Failed to open file for writing") stream = QTextStream(hrox_file) doc.save(stream, 1) hrox_file.close()
def _check_data(self, data_set): for data, lines in data_set: stream = QTextStream(data) res = [] while not stream.atEnd(): res.append(stream.readLine()) self.assertEqual(res, lines)
def testConstruction(self): '''QTextStream construction''' obj = QTextStream() self.assertEqual(obj.codec(), QTextCodec.codecForLocale()) self.assertEqual(obj.device(), None) self.assertEqual(obj.string(), None) self.assertTrue(obj.atEnd()) self.assertEqual(obj.readAll(), '')
def readStdout(self): # Ensure only complete lines are passed on text = "" while self.process.canReadLine(): byteArr = self.process.readLine() text += QTextStream(byteArr).readAll() if text: print(text, end='') # Avoid displaying on FreeCAD status bar if self.stdoutHook: self.stdoutHook(text) # Must be at the end as it can cause re-entrance if FreeCAD.GuiUp: FreeCAD.Gui.updateGui()
def readStderr(self): # Ensure only complete lines are passed on # Print any error output to console self.process.setReadChannel(QProcess.StandardError) text = "" while self.process.canReadLine(): byteArr = self.process.readLine() text += QTextStream(byteArr).readAll() if text: if self.stderrHook: self.stderrHook(text) FreeCAD.Console.PrintError(text) # Must be at the end as it can cause re-entrance if FreeCAD.GuiUp: FreeCAD.Gui.updateGui() self.process.setReadChannel(QProcess.StandardOutput)
def saveHistory(self, fileName, html): #TODO """ TOWRITE :param `fileName`: TOWRITE :type `fileName`: QString :param `html`: TOWRITE :type `html`: bool """ qDebug("CmdPrompt saveHistory") file = QFile(fileName) if (not file.open(QIODevice.WriteOnly | QIODevice.Text)): return # TODO: save during input in case of crash output = QTextStream(file) if html: output << promptHistory.toHtml() else: output << promptHistory.toPlainText()
def javaInclude(context, engine): fileName = context.argument(0).toString() scriptFile = QFile("commands/" + fileName) if not scriptFile.open(QIODevice.ReadOnly): return -1 stream = QTextStream(scriptFile) s = stream.readAll() # QString scriptFile.close() parent = context.parentContext() # QScriptContext* if parent != 0: context.setActivationObject(context.parentContext().activationObject()) context.setThisObject(context.parentContext().thisObject()) result = engine.evaluate(s) #TODO/PORT/FIXME# what's this for? return 0
def OnSaveFilePath(self, filePath): """""" file = QFile(filePath) if not file.open(QFile.WriteOnly | QFile.Text): QMessageBox.warning(self, self.tr('Warning'), self.tr('Cannot write file') + ' %s:\n%s.' % (filePath, file.errorString())) return False outf = QTextStream(file) QApplication.setOverrideCursor(Qt.WaitCursor) outf << self.toPlainText() QApplication.restoreOverrideCursor() self.DoSetCurrentFilePath(filePath) # Clear the Modified Flag. self.document().setModified(False) self.setWindowModified(False) self.setWindowTitle('%s[*]' % self.fileName) return True
def load_stylesheet(theme, pyside=True): """ Loads the stylesheet. Takes care of importing the rc module. :param pyside: True to load the pyside rc file, False to load the PyQt rc file :return the stylesheet string """ if theme == 'darkstyle': import themes.darkstyle.pyside_style_rc elif theme == 'robotstyle': import themes.robotstyle.pyside_style_rc from PySide.QtCore import QFile, QTextStream basedir = os.path.abspath(os.path.dirname(__file__)) localPath = "%s/style.qss" % theme f = QFile( os.path.join(basedir, localPath)) if not f.exists(): _logger().error("Unable to load stylesheet, file not found in " "resources") return "" else: f.open(QFile.ReadOnly | QFile.Text) ts = QTextStream(f) stylesheet = ts.readAll() # if platform.system().lower() == 'darwin': # see issue #12 on github # mac_fix = ''' # QDockWidget::title # { # background-color: #353434; # text-align: center; # height: 10px; # } # ''' # stylesheet += mac_fix return stylesheet
def testIt(self): device = MyIODevice() device.open(QIODevice.ReadOnly) s = QTextStream(device) self.assertEqual(s.read(4), "\0a\0a") self.assertEqual(device.readLine(), "\0b\0b\0b\0b")
def setUp(self): self.obj = QTextStream()
def setUp(self): self.ba = QByteArray() self.read = QTextStream(self.ba, QIODevice.ReadOnly) self.write = QTextStream(self.ba, QIODevice.WriteOnly)