Exemplo n.º 1
0
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
Exemplo n.º 2
0
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
Exemplo n.º 3
0
def getContent(path):
    file = QFile(path)
    if not file.open(QIODevice.ReadOnly | QIODevice.Text):
        return
    ts = QTextStream(file)
    ts.setCodec("UTF-8")
    res = ts.readAll()
    return res
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
class QTextStreamShiftTest(unittest.TestCase):
    def setUp(self):
        self.ba = QByteArray()
        self.read = QTextStream(self.ba, QIODevice.ReadOnly)
        self.write = QTextStream(self.ba, QIODevice.WriteOnly)

    def testNumber(self):
        """QTextStream << number"""

        self.write << "4"
        self.write.flush()
        res = self.read.readLine()
        self.assertTrue(isinstance(res, py3k.unicode))
        self.assertEqual(res, "4")
Exemplo n.º 7
0
class QTextStreamShiftTest(unittest.TestCase):
    def setUp(self):
        self.ba = QByteArray()
        self.read = QTextStream(self.ba, QIODevice.ReadOnly)
        self.write = QTextStream(self.ba, QIODevice.WriteOnly)

    def testNumber(self):
        '''QTextStream << number'''

        self.write << '4'
        self.write.flush()
        res = self.read.readLine()
        self.assertTrue(isinstance(res, py3k.unicode))
        self.assertEqual(res, '4')
Exemplo n.º 8
0
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 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 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
Exemplo n.º 11
0
    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(), '')
Exemplo n.º 12
0
class QTextStreamGetSet(unittest.TestCase):
    def setUp(self):
        self.obj = QTextStream()

    def testCodec(self):
        """QTextStream set/get Codec"""

        codec = QTextCodec.codecForName("ISO8859-1")
        self.obj.setCodec(codec)
        self.assertEqual(codec, self.obj.codec())

    def testDevice(self):
        """QTextStream get/set Device"""
        device = QFile()
        self.obj.setDevice(device)
        self.assertEqual(device, self.obj.device())
        self.obj.setDevice(None)
        self.assertEqual(None, self.obj.device())
Exemplo n.º 13
0
class QTextStreamGetSet(unittest.TestCase):
    def setUp(self):
        self.obj = QTextStream()

    def testCodec(self):
        '''QTextStream set/get Codec'''

        codec = QTextCodec.codecForName('ISO8859-1')
        self.obj.setCodec(codec)
        self.assertEqual(codec, self.obj.codec())

    def testDevice(self):
        '''QTextStream get/set Device'''
        device = QFile()
        self.obj.setDevice(device)
        self.assertEqual(device, self.obj.device())
        self.obj.setDevice(None)
        self.assertEqual(None, self.obj.device())
Exemplo n.º 14
0
 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()
Exemplo n.º 15
0
def load_stylesheet(pyside=True):


    f = QFile(":petfactoryStyle/style.qss")
    if not f.exists():
        pass

    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: 12px;
            }
            '''
            stylesheet += mac_fix
        return stylesheet
Exemplo n.º 16
0
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
Exemplo n.º 17
0
    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(), "")
Exemplo n.º 18
0
 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)
Exemplo n.º 19
0
    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()
Exemplo n.º 20
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
Exemplo n.º 21
0
 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")
Exemplo n.º 22
0
 def setUp(self):
     self.obj = QTextStream()
Exemplo n.º 23
0
 def setUp(self):
     self.ba = QByteArray()
     self.read = QTextStream(self.ba, QIODevice.ReadOnly)
     self.write = QTextStream(self.ba, QIODevice.WriteOnly)
Exemplo n.º 24
0
 def setUp(self):
     self.ba = QByteArray()
     self.read = QTextStream(self.ba, QIODevice.ReadOnly)
     self.write = QTextStream(self.ba, QIODevice.WriteOnly)
Exemplo n.º 25
0
 def setUp(self):
     self.obj = QTextStream()
Exemplo n.º 26
0
 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")