當前位置: 首頁>>代碼示例>>Python>>正文


Python QIODevice.ReadWrite方法代碼示例

本文整理匯總了Python中PyQt5.QtCore.QIODevice.ReadWrite方法的典型用法代碼示例。如果您正苦於以下問題:Python QIODevice.ReadWrite方法的具體用法?Python QIODevice.ReadWrite怎麽用?Python QIODevice.ReadWrite使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyQt5.QtCore.QIODevice的用法示例。


在下文中一共展示了QIODevice.ReadWrite方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: fromqimage

# 需要導入模塊: from PyQt5.QtCore import QIODevice [as 別名]
# 或者: from PyQt5.QtCore.QIODevice import ReadWrite [as 別名]
def fromqimage(im):
    """
    :param im: A PIL Image object, or a file name
    (given either as Python string or a PyQt string object)
    """
    buffer = QBuffer()
    buffer.open(QIODevice.ReadWrite)
    # preserve alha channel with png
    # otherwise ppm is more friendly with Image.open
    if im.hasAlphaChannel():
        im.save(buffer, 'png')
    else:
        im.save(buffer, 'ppm')

    b = BytesIO()
    try:
        b.write(buffer.data())
    except TypeError:
        # workaround for Python 2
        b.write(str(buffer.data()))
    buffer.close()
    b.seek(0)

    return Image.open(b) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:26,代碼來源:ImageQt.py

示例2: fromqimage

# 需要導入模塊: from PyQt5.QtCore import QIODevice [as 別名]
# 或者: from PyQt5.QtCore.QIODevice import ReadWrite [as 別名]
def fromqimage(im):
    """
    :param im: A PIL Image object, or a file name
    (given either as Python string or a PyQt string object)
    """
    buffer = QBuffer()
    buffer.open(QIODevice.ReadWrite)
    # preserve alpha channel with png
    # otherwise ppm is more friendly with Image.open
    if im.hasAlphaChannel():
        im.save(buffer, "png")
    else:
        im.save(buffer, "ppm")

    b = BytesIO()
    b.write(buffer.data())
    buffer.close()
    b.seek(0)

    return Image.open(b) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:22,代碼來源:ImageQt.py

示例3: fromqimage

# 需要導入模塊: from PyQt5.QtCore import QIODevice [as 別名]
# 或者: from PyQt5.QtCore.QIODevice import ReadWrite [as 別名]
def fromqimage(im):
    """
    :param im: A PIL Image object, or a file name
    (given either as Python string or a PyQt string object)
    """
    buffer = QBuffer()
    buffer.open(QIODevice.ReadWrite)
    # preserve alpha channel with png
    # otherwise ppm is more friendly with Image.open
    if im.hasAlphaChannel():
        im.save(buffer, 'png')
    else:
        im.save(buffer, 'ppm')

    b = BytesIO()
    try:
        b.write(buffer.data())
    except TypeError:
        # workaround for Python 2
        b.write(str(buffer.data()))
    buffer.close()
    b.seek(0)

    return Image.open(b) 
開發者ID:holzschu,項目名稱:python3_ios,代碼行數:26,代碼來源:ImageQt.py

示例4: open_serial_link

# 需要導入模塊: from PyQt5.QtCore import QIODevice [as 別名]
# 或者: from PyQt5.QtCore.QIODevice import ReadWrite [as 別名]
def open_serial_link(self, port):
        """
        Creates a new serial link instance.
        """
        self.input_buffer = []
        self.serial = QSerialPort()
        self.serial.setPortName(port)
        if self.serial.open(QIODevice.ReadWrite):
            self.serial.setDataTerminalReady(True)
            if not self.serial.isDataTerminalReady():
                # Using pyserial as a 'hack' to open the port and set DTR
                # as QtSerial does not seem to work on some Windows :(
                # See issues #281 and #302 for details.
                self.serial.close()
                pyser = serial.Serial(port)  # open serial port w/pyserial
                pyser.dtr = True
                pyser.close()
                self.serial.open(QIODevice.ReadWrite)
            self.serial.setBaudRate(115200)
            self.serial.readyRead.connect(self.on_serial_read)
        else:
            msg = _("Cannot connect to device on port {}").format(port)
            raise IOError(msg) 
開發者ID:mu-editor,項目名稱:mu,代碼行數:25,代碼來源:main.py

示例5: test_Window_open_serial_link

# 需要導入模塊: from PyQt5.QtCore import QIODevice [as 別名]
# 或者: from PyQt5.QtCore.QIODevice import ReadWrite [as 別名]
def test_Window_open_serial_link(qtapp):
    """
    Ensure the serial port is opened in the expected manner.
    """
    mock_serial = mock.MagicMock()
    mock_serial.setPortName = mock.MagicMock(return_value=None)
    mock_serial.setBaudRate = mock.MagicMock(return_value=None)
    mock_serial.open = mock.MagicMock(return_value=True)
    mock_serial.readyRead = mock.MagicMock()
    mock_serial.readyRead.connect = mock.MagicMock(return_value=None)
    mock_serial_class = mock.MagicMock(return_value=mock_serial)
    with mock.patch("mu.interface.main.QSerialPort", mock_serial_class):
        w = mu.interface.main.Window()
        w.open_serial_link("COM0")
        assert w.input_buffer == []
    mock_serial.setPortName.assert_called_once_with("COM0")
    mock_serial.setBaudRate.assert_called_once_with(115200)
    mock_serial.open.assert_called_once_with(QIODevice.ReadWrite)
    mock_serial.readyRead.connect.assert_called_once_with(w.on_serial_read) 
開發者ID:mu-editor,項目名稱:mu,代碼行數:21,代碼來源:test_main.py

示例6: fromqpixmap

# 需要導入模塊: from PyQt5.QtCore import QIODevice [as 別名]
# 或者: from PyQt5.QtCore.QIODevice import ReadWrite [as 別名]
def fromqpixmap(im):
    return fromqimage(im)
    # buffer = QBuffer()
    # buffer.open(QIODevice.ReadWrite)
    # # im.save(buffer)
    # # What if png doesn't support some image features like animation?
    # im.save(buffer, 'ppm')
    # bytes_io = BytesIO()
    # bytes_io.write(buffer.data())
    # buffer.close()
    # bytes_io.seek(0)
    # return Image.open(bytes_io) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:14,代碼來源:ImageQt.py

示例7: serialize

# 需要導入模塊: from PyQt5.QtCore import QIODevice [as 別名]
# 或者: from PyQt5.QtCore.QIODevice import ReadWrite [as 別名]
def serialize(items):
    """Serialize a list of WebHistoryItems to a data stream.

    Args:
        items: An iterable of WebHistoryItems.

    Return:
        A (stream, data, user_data) tuple.
            stream: The reset QDataStream.
            data: The QByteArray with the raw data.
            user_data: A list with each item's user data.

    Warning:
        If 'data' goes out of scope, reading from 'stream' will result in a
        segfault!
    """
    data = QByteArray()
    stream = QDataStream(data, QIODevice.ReadWrite)
    user_data = []  # type: typing.List[typing.Mapping[str, typing.Any]]

    current_idx = None

    for i, item in enumerate(items):
        if item.active:
            if current_idx is not None:
                raise ValueError("Multiple active items ({} and {}) "
                                 "found!".format(current_idx, i))
            current_idx = i

    if items:
        if current_idx is None:
            raise ValueError("No active item found!")
    else:
        current_idx = 0

    _serialize_items(items, current_idx, stream)

    user_data += [item.user_data for item in items]

    stream.device().reset()
    qtutils.check_qdatastream(stream)
    return stream, data, user_data 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:44,代碼來源:tabhistory.py

示例8: serialize

# 需要導入模塊: from PyQt5.QtCore import QIODevice [as 別名]
# 或者: from PyQt5.QtCore.QIODevice import ReadWrite [as 別名]
def serialize(items):
    """Serialize a list of WebHistoryItems to a data stream.

    Args:
        items: An iterable of WebHistoryItems.

    Return:
        A (stream, data, user_data) tuple.
            stream: The reset QDataStream.
            data: The QByteArray with the raw data.
            cur_user_data: The user data for the current item or None.

    Warning:
        If 'data' goes out of scope, reading from 'stream' will result in a
        segfault!
    """
    data = QByteArray()
    stream = QDataStream(data, QIODevice.ReadWrite)
    cur_user_data = None

    current_idx = None

    for i, item in enumerate(items):
        if item.active:
            if current_idx is not None:
                raise ValueError("Multiple active items ({} and {}) "
                                 "found!".format(current_idx, i))
            current_idx = i
            cur_user_data = item.user_data

    if items:
        if current_idx is None:
            raise ValueError("No active item found!")
    else:
        current_idx = -1

    ### src/core/web_contents_adapter.cpp serializeNavigationHistory
    #                                          sample data:
    # kHistoryStreamVersion
    stream.writeInt(HISTORY_STREAM_VERSION)  # \x00\x00\x00\x03
    # count
    stream.writeInt(len(items))              # \x00\x00\x00\x01
    # currentIndex
    stream.writeInt(current_idx)             # \x00\x00\x00\x00

    for item in items:
        _serialize_item(item, stream)

    stream.device().reset()
    qtutils.check_qdatastream(stream)
    return stream, data, cur_user_data 
開發者ID:qutebrowser,項目名稱:qutebrowser,代碼行數:53,代碼來源:tabhistory.py

示例9: on_buttonConnect_clicked

# 需要導入模塊: from PyQt5.QtCore import QIODevice [as 別名]
# 或者: from PyQt5.QtCore.QIODevice import ReadWrite [as 別名]
def on_buttonConnect_clicked(self):
        # 打開或關閉串口按鈕
        if self._serial.isOpen():
            # 如果串口是打開狀態則關閉
            self._serial.close()
            self.textBrowser.append('串口已關閉')
            self.buttonConnect.setText('打開串口')
            self.labelStatus.setProperty('isOn', False)
            self.labelStatus.style().polish(self.labelStatus)  # 刷新樣式
            return

        # 根據配置連接串口
        name = self.comboBoxPort.currentText()
        if not name:
            QMessageBox.critical(self, '錯誤', '沒有選擇串口')
            return
        port = self._ports[name]
#         self._serial.setPort(port)
        # 根據名字設置串口(也可以用上麵的函數)
        self._serial.setPortName(port.systemLocation())
        # 設置波特率
        self._serial.setBaudRate(  # 動態獲取,類似QSerialPort::Baud9600這樣的吧
            getattr(QSerialPort, 'Baud' + self.comboBoxBaud.currentText()))
        # 設置校驗位
        self._serial.setParity(  # QSerialPort::NoParity
            getattr(QSerialPort, self.comboBoxParity.currentText() + 'Parity'))
        # 設置數據位
        self._serial.setDataBits(  # QSerialPort::Data8
            getattr(QSerialPort, 'Data' + self.comboBoxData.currentText()))
        # 設置停止位
        self._serial.setStopBits(  # QSerialPort::Data8
            getattr(QSerialPort, self.comboBoxStop.currentText()))

        # NoFlowControl          沒有流程控製
        # HardwareControl        硬件流程控製(RTS/CTS)
        # SoftwareControl        軟件流程控製(XON/XOFF)
        # UnknownFlowControl     未知控製
        self._serial.setFlowControl(QSerialPort.NoFlowControl)
        # 讀寫方式打開串口
        ok = self._serial.open(QIODevice.ReadWrite)
        if ok:
            self.textBrowser.append('打開串口成功')
            self.buttonConnect.setText('關閉串口')
            self.labelStatus.setProperty('isOn', True)
            self.labelStatus.style().polish(self.labelStatus)  # 刷新樣式
        else:
            self.textBrowser.append('打開串口失敗')
            self.buttonConnect.setText('打開串口')
            self.labelStatus.setProperty('isOn', False)
            self.labelStatus.style().polish(self.labelStatus)  # 刷新樣式 
開發者ID:PyQt5,項目名稱:PyQt,代碼行數:52,代碼來源:SerialDebugAssistant.py


注:本文中的PyQt5.QtCore.QIODevice.ReadWrite方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。