Beispiel #1
0
    def __init__(self, port, parent=None):
        super().__init__(parent)

        sslConfiguration = QSslConfiguration()
        certFile = QFile(":/localhost.cert")
        keyFile = QFile(":/localhost.key")
        certFile.open(QIODevice.ReadOnly)
        keyFile.open(QIODevice.ReadOnly)
        certificate = QSslCertificate(certFile, QSsl.Pem)
        if __binding__ == "PyQt5":
            sslKey = QSslKey(keyFile, QSsl.Rsa, QSsl.Pem)
        else:
            sslKey = QSslKey(keyFile.readAll(), QSsl.Rsa, QSsl.Pem)
        certFile.close()
        keyFile.close()
        sslConfiguration.setPeerVerifyMode(QSslSocket.VerifyNone)
        sslConfiguration.setLocalCertificate(certificate)
        sslConfiguration.setPrivateKey(sslKey)

        if __binding__ == "PySide2":
            QSslConfiguration.setDefaultConfiguration(sslConfiguration)

        self.m_pWebSocketServer = QWebSocketServer("SSL Echo Server",
                                                   QWebSocketServer.SecureMode,
                                                   self)

        self.m_clients = []

        if __binding__ == "PyQt5":
            self.m_pWebSocketServer.setSslConfiguration(sslConfiguration)

        if self.m_pWebSocketServer.listen(QHostAddress.Any, port):
            print("SSL Echo Server listening on port", port)
            self.m_pWebSocketServer.newConnection.connect(self.onNewConnection)
            self.m_pWebSocketServer.sslErrors.connect(self.onSslErrors)
Beispiel #2
0
def main():
    import sys

    app = QCoreApplication(sys.argv)  # noqa: F841
    f = QFile()
    f.open(sys.stdout.fileno(), QIODevice.WriteOnly)
    out = QTextStream(f)
    serialPortInfos = QSerialPortInfo.availablePorts()

    out << "Total number of ports available: " << len(serialPortInfos) << "\n"

    blankString = "N/A"
    description = ""
    manufacturer = ""
    serialNumber = ""

    for serialPortInfo in serialPortInfos:
        description = serialPortInfo.description()
        manufacturer = serialPortInfo.manufacturer()
        serialNumber = serialPortInfo.serialNumber()
        out << "\nPort: " << serialPortInfo.portName(
        ) << "\nLocation: " << serialPortInfo.systemLocation(
        ) << "\nDescription: " << (  # noqa: E501
            description if description else blankString
        ) << "\nManufacturer: " << (
            manufacturer
            if manufacturer else blankString) << "\nSerial number: " << (
                serialNumber if serialNumber else blankString
            ) << "\nVendor Identifier: " << (
                QByteArray.number(serialPortInfo.vendorIdentifier(), 16)
                if serialPortInfo.hasVendorIdentifier() else blankString
            ) << "\nProduct Identifier: " << (
                QByteArray.number(serialPortInfo.productIdentifier(), 16) if
                serialPortInfo.hasProductIdentifier() else blankString) << "\n"
Beispiel #3
0
    def __init__(self, url):
        super().__init__()
        self.setAttribute(Qt.WA_DeleteOnClose, True)
        self.progress = 0

        f = QFile()
        f.setFileName(":/jquery.min.js")
        f.open(QIODevice.ReadOnly)
        self.jQuery = f.readAll().data().decode()
        self.jQuery += "\nvar qt = { 'jQuery': jQuery.noConflict(true) };"
        f.close()

        self.view = QWebEngineView(self)
        self.view.load(url)

        self.view.loadFinished.connect(self.adjustLocation)
        self.view.titleChanged.connect(self.adjustTitle)
        self.view.loadProgress.connect(self.setProgress)
        self.view.loadFinished.connect(self.finishLoading)

        self.locationEdit = QLineEdit(self)
        self.locationEdit.setSizePolicy(
            QSizePolicy.Expanding,
            self.locationEdit.sizePolicy().verticalPolicy())
        self.locationEdit.returnPressed.connect(self.changeLocation)

        toolBar = self.addToolBar(self.tr("Navigation"))
        toolBar.addAction(self.view.pageAction(QWebEnginePage.Back))
        toolBar.addAction(self.view.pageAction(QWebEnginePage.Forward))
        toolBar.addAction(self.view.pageAction(QWebEnginePage.Reload))
        toolBar.addAction(self.view.pageAction(QWebEnginePage.Stop))
        toolBar.addWidget(self.locationEdit)

        viewMenu = self.menuBar().addMenu(self.tr("&View"))
        viewSourceAction = QAction(self.tr("Page Source"), self)
        viewSourceAction.triggered.connect(self.viewSource)
        viewMenu.addAction(viewSourceAction)

        effectMenu = self.menuBar().addMenu(self.tr("&Effect"))
        effectMenu.addAction(self.tr("Highlight all links"),
                             self.highlightAllLinks)

        self.rotateAction = QAction(self)
        self.rotateAction.setIcon(self.style().standardIcon(
            QStyle.SP_FileDialogDetailedView))
        self.rotateAction.setCheckable(True)
        self.rotateAction.setText(self.tr("Turn images upside down"))
        self.rotateAction.toggled.connect(self.rotateImages)
        effectMenu.addAction(self.rotateAction)

        toolsMenu = self.menuBar().addMenu(self.tr("&Tools"))
        toolsMenu.addAction(self.tr("Remove GIF images"), self.removeGifImages)
        toolsMenu.addAction(self.tr("Remove all inline frames"),
                            self.removeInlineFrames)
        toolsMenu.addAction(self.tr("Remove all object elements"),
                            self.removeObjectElements)
        toolsMenu.addAction(self.tr("Remove all embedded elements"),
                            self.removeEmbeddedElements)

        self.setCentralWidget(self.view)
Beispiel #4
0
    def __init__(self, parent: QWidget = None):
        super().__init__(parent)
        self.setupUi(self)

        self.m_content = Document()
        self.m_filePath = ""

        self.editor.setFont(QFontDatabase.systemFont(QFontDatabase.FixedFont))
        self.preview.setContextMenuPolicy(Qt.NoContextMenu)

        page = PreviewPage(self)
        self.preview.setPage(page)

        self.editor.textChanged.connect(
            lambda: self.m_content.setText(self.editor.toPlainText()))

        channel = QWebChannel(self)
        channel.registerObject("content", self.m_content)
        page.setWebChannel(channel)

        self.preview.setUrl(QUrl("qrc:/index.html"))

        self.actionNew.triggered.connect(self.onFileNew)
        self.actionOpen.triggered.connect(self.onFileOpen)
        self.actionSave.triggered.connect(self.onFileSave)
        self.actionSaveAs.triggered.connect(self.onFileSaveAs)
        self.actionExit.triggered.connect(self.onExit)

        self.editor.document().modificationChanged.connect(
            self.actionSave.setEnabled)

        defaultTextFile = QFile(":/default.md")
        defaultTextFile.open(QIODevice.ReadOnly)
        self.editor.setPlainText(defaultTextFile.readAll().data().decode())
Beispiel #5
0
def main():
    import sys

    app = QApplication(sys.argv)

    acmeSeries = QBoxPlotSeries()
    acmeSeries.setName("Acme Ltd")

    boxWhiskSeries = QBoxPlotSeries()
    boxWhiskSeries.setName("BoxWhisk Inc")

    acmeData = QFile(":acme")
    if not acmeData.open(QIODevice.ReadOnly | QIODevice.Text):
        sys.exit(1)

    dataReader = BoxDataReader(acmeData)
    while not dataReader.atEnd():
        _set = dataReader.readBox()
        if _set is not None:
            acmeSeries.append(_set)

    boxwhiskData = QFile(":boxwhisk")
    if not boxwhiskData.open(QIODevice.ReadOnly | QIODevice.Text):
        sys.exit(1)

    dataReader.readFile(boxwhiskData)
    while not dataReader.atEnd():
        _set = dataReader.readBox()
        if _set is not None:
            boxWhiskSeries.append(_set)

    chart = QChart()
    chart.addSeries(acmeSeries)
    chart.addSeries(boxWhiskSeries)
    chart.setTitle("Acme Ltd and BoxWhisk Inc share deviation in 2012")
    chart.setAnimationOptions(QChart.SeriesAnimations)

    chart.createDefaultAxes()
    chart.axes(Qt.Vertical)[0].setMin(15.0)
    chart.axes(Qt.Vertical)[0].setMax(34.0)

    chart.legend().setVisible(True)
    chart.legend().setAlignment(Qt.AlignBottom)

    chartView = QChartView(chart)
    chartView.setRenderHint(QPainter.Antialiasing)

    window = QMainWindow()
    window.setCentralWidget(chartView)
    window.resize(800, 600)
    window.show()

    sys.exit(app.exec_())
Beispiel #6
0
    def on_transparentStyle_clicked(self):
        styleSheet = QFile(":/files/transparent.qss")

        if not styleSheet.open(QIODevice.ReadOnly):
            print("Unable to open :/files/transparent.qss")
            return

        QApplication.instance().setStyleSheet(styleSheet.readAll().data().decode())
Beispiel #7
0
    def requestStarted(self, job: QWebEngineUrlRequestJob) -> None:
        webUiOrigin = QUrl(SCHEMENAME + ":")
        GET: QByteArray = QByteArray(b"GET")
        POST: QByteArray = QByteArray(b"POST")

        method = job.requestMethod()
        url = job.requestUrl()
        initiator = job.initiator()
        if method == GET and url == WebUiHandler.aboutUrl:
            f = QFile(":/about.html", job)
            f.open(QIODevice.ReadOnly)
            job.reply(b"text/html", f)
        elif (method == POST and url == WebUiHandler.aboutUrl
              and initiator == webUiOrigin):
            job.fail(QWebEngineUrlRequestJob.RequestAborted)
            QApplication.exit()
        else:
            job.fail(QWebEngineUrlRequestJob.UrlNotFound)
Beispiel #8
0
 def set_file(self, file_path):
     in_file = QFile(file_path)
     if in_file.open(QFile.ReadOnly | QFile.Text):
         text = in_file.readAll()
         self.setPlainText(text)
     self._file_path = file_path
     self._last_modified = fileio.get_last_modified_date(self._file_path)
     if self._completer:
         self._completer.set_filepath(file_path)
     self.fileSet.emit()
Beispiel #9
0
def main():
    import sys

    a = QApplication(sys.argv)

    acmeSeries = QCandlestickSeries()
    acmeSeries.setName("Acme Ltd")
    acmeSeries.setIncreasingColor(QColor(Qt.green))
    acmeSeries.setDecreasingColor(QColor(Qt.red))

    acmeData = QFile(":acme")
    if not acmeData.open(QIODevice.ReadOnly | QIODevice.Text):
        sys.exit(1)

    categories = []

    dataReader = CandlestickDataReader(acmeData)
    while not dataReader.atEnd():
        _set = dataReader.readCandlestickSet()
        if _set is not None:
            acmeSeries.append(_set)
            categories.append(
                QDateTime.fromMSecsSinceEpoch(int(
                    _set.timestamp())).toString("dd"))

    chart = QChart()
    chart.addSeries(acmeSeries)
    chart.setTitle("Acme Ltd Historical Data (July 2015)")
    chart.setAnimationOptions(QChart.SeriesAnimations)

    chart.createDefaultAxes()

    axisX = chart.axes(Qt.Horizontal)[0]
    axisX.setCategories(categories)

    axisY = chart.axes(Qt.Vertical)[0]
    axisY.setMax(axisY.max() * 1.01)
    axisY.setMin(axisY.min() * 0.99)

    chart.legend().setVisible(True)
    chart.legend().setAlignment(Qt.AlignBottom)

    chartView = QChartView(chart)
    chartView.setRenderHint(QPainter.Antialiasing)

    window = QMainWindow()
    window.setCentralWidget(chartView)
    window.resize(800, 600)
    window.show()

    sys.exit(a.exec_())
Beispiel #10
0
    def openFile(self, path: str) -> None:
        f = QFile(path)

        if not f.open(QIODevice.ReadOnly):

            QMessageBox.warning(
                self,
                self.windowTitle(),
                self.tr("Could not open file %s: %s" %
                        (QDir.toNativeSeparators(path), f.errorString())),
            )
            return

        self.m_filePath = path
        self.editor.setPlainText(f.readAll().data().decode())
Beispiel #11
0
    def onFileSave(self):
        if not self.m_filePath:
            self.onFileSaveAs()
            return

        f = QFile(self.m_filePath)
        if not f.open(QIODevice.WriteOnly | QIODevice.Text):
            QMessageBox.warning(
                self,
                self.windowTitle(),
                self.tr("Could not write to file %s: %s" %
                        (QDir.toNativeSeparators(
                            self.m_filePath), f.errorString())),
            )
            return

        text = QTextStream(f)
        text << self.editor.toPlainText()

        self.editor.document().setModified(False)