Пример #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)
Пример #2
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)
Пример #3
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())
Пример #4
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())
Пример #5
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()
Пример #6
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())