Beispiel #1
0
 def importDips(self, fileURLsStr):
     self.dipModel.reset()
     for filePath in fileURLsStr:
         file = QFile(QUrl(filePath).toLocalFile())
         if (not file.open(QIODevice.ReadOnly)):
             print("impossible to open file \" " + filePath +
                   " \", error is:" + file.errorString())
             continue
         while not file.atEnd():
             line = str(file.readLine(), encoding='utf-8')
             lineCells = line.split(',')
             try:
                 float(lineCells[0])
             except ValueError:
                 continue
             dip = Dipole.initByComposent(xPos=float(lineCells[0]),
                                          yPos=float(lineCells[1]),
                                          zPos=float(lineCells[2]),
                                          quaternion=anglesSphToQuaternion(
                                              float(lineCells[3]),
                                              float(lineCells[4])),
                                          parent=self.dipModel)
             self.dipModel.append(dip)
Beispiel #2
0
 def testHuge(self):
     handle = QFile(":manychars.txt")
     handle.open(QFile.ReadOnly)
     original = open(os.path.join(self.testdir, "manychars.txt"), "r")
     self.assertEqual(handle.readLine(), original.readline())
Beispiel #3
0
 def testSimple(self):
     handle = QFile(":words.txt")
     handle.open(QFile.ReadOnly)
     original = open(os.path.join(self.testdir, "words.txt"), "r")
     self.assertEqual(handle.readLine(), original.readline())
Beispiel #4
0
 def testAlias(self):
     handle = QFile(":jack")
     handle.open(QFile.ReadOnly)
     original = open(os.path.join(self.testdir, "shining.txt"), "r")
     self.assertEqual(handle.readLine(), original.readline())
class Sender(QRunnable):
    class Signals(QObject):
        update_status = Signal(int)

    def __init__(self,
                 portname: str,
                 filepath: str,
                 baudrate: int,
                 databits: str,
                 parity: str,
                 stopbits_: str,
                 flowcontrol_: str,
                 parent: QObject = None):
        super(Sender, self).__init__(parent)
        self.file = QFile(filepath)
        self.errorString = 'Unknown error'
        self.signals = self.Signals()
        self.portname = portname
        self.baudrate = baudrate
        self.bytesize = bytesize.get(databits)
        self.parity = parities.get(parity)
        self.stopbits = stopbits.get(stopbits_)
        self.flowcontrol = flowcontrol_
        self.xonoff = (self.flowcontrol == 'SoftwareControl')
        self.rtscts = (self.flowcontrol == 'HardwareControl')
        self.port = Serial(
            port=self.portname,
            baudrate=self.baudrate,
            parity=self.parity,
            stopbits=self.stopbits,
            bytesize=self.bytesize,
            xonxoff=self.xonoff,
            rtscts=self.rtscts,
            dsrdtr=False,
            timeout=None,
            write_timeout=10.0  # 10s
        )
        self.cancelled = False

    def run(self):
        if not self.port.isOpen():
            self.errorString = ("Could not open port %s" % self.portname)
            return
        self.file.open(QFile.ReadOnly)
        line = self.file.readLine()
        while not self.cancelled:
            if self.port.write(bytes(line.data())) > 0:
                print(str(line))
                self.signals.update_status.emit(self.file.pos())
                if not self.file.atEnd():
                    line = self.file.readLine()
                else:
                    break
        if self.cancelled:
            self.port.reset_output_buffer()
            self.port.flushOutput()
            self.port.flush()
        else:
            self.port.flush()
        self.file.close()
        self.port.close()

    @Slot()
    def cancel(self):
        self.cancelled = True