Python PyQt5.QtNetwork.QNetworkAccessManager() Examples

The following are 22 code examples of PyQt5.QtNetwork.QNetworkAccessManager(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt5.QtNetwork , or try the search function .
Example #1
Source File: FacePoints.py    From PyQt with GNU General Public License v3.0 7 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(OpencvWidget, self).__init__(*args, **kwargs)
        self.httpRequestAborted = False
        self.fps = 24
        self.resize(800, 600)

        if not os.path.exists("Data/shape_predictor_68_face_landmarks.dat"):
            self.setText("正在下载数据文件。。。")
            self.outFile = QFile(
                "Data/shape_predictor_68_face_landmarks.dat.bz2")
            if not self.outFile.open(QIODevice.WriteOnly):
                QMessageBox.critical(self, '错误', '无法写入文件')
                return
            self.qnam = QNetworkAccessManager(self)
            self._reply = self.qnam.get(QNetworkRequest(QUrl(URL)))
            self._reply.finished.connect(self.httpFinished)
            self._reply.readyRead.connect(self.httpReadyRead)
            self._reply.downloadProgress.connect(self.updateDataReadProgress)
        else:
            self.startCapture() 
Example #2
Source File: HotPlaylist.py    From PyQt with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(Window, self).__init__(*args, **kwargs)
        self.resize(800, 600)
        self.setFrameShape(self.NoFrame)  # 无边框
        self.setFlow(self.LeftToRight)  # 从左到右
        self.setWrapping(True)  # 这三个组合可以达到和FlowLayout一样的效果
        self.setResizeMode(self.Adjust)

        self._loadStart = False
        # 连接竖着的滚动条滚动事件
        self.verticalScrollBar().actionTriggered.connect(self.onActionTriggered)
        # 进度条
        self.loadWidget = QSvgWidget(
            self, minimumHeight=120, minimumWidth=120, visible=False)
        self.loadWidget.load(Svg_icon_loading)

        # 异步网络下载管理器
        self._manager = QNetworkAccessManager(self)
        self._manager.finished.connect(self.onFinished) 
Example #3
Source File: scudcloud.py    From scudcloud with MIT License 6 votes vote down vote up
def webSettings(self):
        self.cookiesjar = PersistentCookieJar(self)
        self.zoom = self.readZoom()
        # We don't want Flash (it causes a lot of trouble in some distros)
        QWebSettings.globalSettings().setAttribute(QWebSettings.PluginsEnabled, False)
        # We don't need Java
        QWebSettings.globalSettings().setAttribute(QWebSettings.JavaEnabled, False)
        # Enabling Local Storage (now required by Slack)
        QWebSettings.globalSettings().setAttribute(QWebSettings.LocalStorageEnabled, True)
        # We need browsing history (required to not limit LocalStorage)
        QWebSettings.globalSettings().setAttribute(QWebSettings.PrivateBrowsingEnabled, False)
        # Enabling Cache
        self.diskCache = QNetworkDiskCache(self)
        self.diskCache.setCacheDirectory(self.cache_path)
        # Required for copy and paste clipboard integration
        QWebSettings.globalSettings().setAttribute(QWebSettings.JavascriptCanAccessClipboard, True)
        # Enabling Inspeclet only when --debug=True (requires more CPU usage)
        QWebSettings.globalSettings().setAttribute(QWebSettings.DeveloperExtrasEnabled, self.debug)
        # Sharing the same networkAccessManager
        self.networkAccessManager = QNetworkAccessManager(self)
        self.networkAccessManager.setCookieJar(self.cookiesjar)
        self.networkAccessManager.setCache(self.diskCache) 
Example #4
Source File: HttpRequestManager.py    From Uranium with GNU Lesser General Public License v3.0 6 votes vote down vote up
def _processNextRequestsInQueue(self) -> None:
        # Process all requests until the max concurrent number is hit or there's no more requests to process.
        while True:
            with self._request_lock:
                # Do nothing if there's no more requests to process
                if not self._request_queue:
                    self._process_requests_scheduled = False
                    return

                # Do not exceed the max request limit
                if len(self._requests_in_progress) >= self._max_concurrent_requests:
                    self._process_requests_scheduled = False
                    return

                # Fetch the next request and process
                next_request_data = self._request_queue.popleft()
            self._processRequest(cast(HttpRequestData, next_request_data))

    # Processes the given HttpRequestData by issuing the request using QNetworkAccessManager and moves the
    # request into the currently in-progress list. 
Example #5
Source File: factory.py    From PhyloSuite with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent=None):
        super(HttpRead, self).__init__(parent)
        # self.doRequest()
        # request = QNetworkRequest()
        # request.setUrl(QUrl(self.url))
        # manager = QNetworkAccessManager()
        # replyObject = manager.get(request)
        # print(replyObject)
        # replyObject.finished.connect(print) 
Example #6
Source File: NetworkMJPGImage.py    From RepetierIntegration with GNU Affero General Public License v3.0 5 votes vote down vote up
def start(self) -> None:
        self.stop()  # Ensure that previous requests (if any) are stopped.

        if not self._source_url:
            Logger.log("w", "Unable to start camera stream without target!")
            return
        self._started = True
        Logger.log("w", "MJPEG starting stream...")
        self._image_request = QNetworkRequest(self._source_url)
        if self._network_manager is None:
            self._network_manager = QNetworkAccessManager()

        self._image_reply = self._network_manager.get(self._image_request)
        self._image_reply.downloadProgress.connect(self._onStreamDownloadProgress) 
Example #7
Source File: NetworkMJPGImage.py    From RepetierIntegration with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)

        self._stream_buffer = QByteArray()
        self._stream_buffer_start_index = -1
        self._network_manager = None  # type: QNetworkAccessManager
        self._image_request = None  # type: QNetworkRequest
        self._image_reply = None  # type: QNetworkReply
        self._image = QImage()
        self._image_rect = QRect()

        self._source_url = QUrl()
        self._started = False

        self._mirror = False

        self.setAntialiasing(True)

    ##  Ensure that close gets called when object is destroyed 
Example #8
Source File: HotPlaylist.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(GridWidget, self).__init__(*args, **kwargs)
        self._layout = QGridLayout(self, spacing=20)
        self._layout.setContentsMargins(20, 20, 20, 20)
        # 异步网络下载管理器
        self._manager = QNetworkAccessManager(self)
        self._manager.finished.connect(self.onFinished) 
Example #9
Source File: HotPlaylist.py    From PyQt with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs):
        super(GridWidget, self).__init__(*args, **kwargs)
        self._layout = FlowLayout(self)  # 使用自定义流式布局
        # 异步网络下载管理器
        self._manager = QNetworkAccessManager(self)
        self._manager.finished.connect(self.onFinished) 
Example #10
Source File: downloader.py    From Mastering-GUI-Programming-with-Python with MIT License 5 votes vote down vote up
def __init__(self, url):
        super().__init__()
        self.manager = qtn.QNetworkAccessManager(
            finished=self.on_finished)
        self.request = qtn.QNetworkRequest(qtc.QUrl(url))
        self.manager.get(self.request) 
Example #11
Source File: question_5_json_poster.py    From Mastering-GUI-Programming-with-Python with MIT License 5 votes vote down vote up
def __init__(self):
        super().__init__()
        self.nam = qtn.QNetworkAccessManager()
        self.nam.finished.connect(self.on_reply) 
Example #12
Source File: poster.py    From Mastering-GUI-Programming-with-Python with MIT License 5 votes vote down vote up
def __init__(self):
        super().__init__()
        self.nam = qtn.QNetworkAccessManager()
        self.nam.finished.connect(self.on_reply) 
Example #13
Source File: factory.py    From PhyloSuite with GNU General Public License v3.0 5 votes vote down vote up
def doRequest(self, url):
        self.url = url
        req = QNetworkRequest(QUrl(self.url))
        self.nam = QNetworkAccessManager()
        self.nam.finished.connect(self.handleResponse)
        self.nam.get(req) 
Example #14
Source File: browsertab.py    From qutebrowser with GNU General Public License v3.0 5 votes vote down vote up
def networkaccessmanager(self) -> typing.Optional[QNetworkAccessManager]:
        """Get the QNetworkAccessManager for this tab.

        This is only implemented for QtWebKit.
        For QtWebEngine, always returns None.
        """
        raise NotImplementedError 
Example #15
Source File: factory.py    From PhyloSuite with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent=None, **dict_args):
        super(HttpWindowDownload, self).__init__(parent)
        self.parent = parent
        self.factory = Factory()
        self.url = QUrl(dict_args["httpURL"])
        self.exportPath = dict_args["exportPath"]
        self.plugin_path = os.path.dirname(self.exportPath)
        self.outFile = QFile(self.exportPath)
        self.httpGetId = 0
        self.httpRequestAborted = False
        self.download_button = dict_args["download_button"]
        self.tableWidget = dict_args["tableWidget"]
        self.row = dict_args["row"]
        self.status = dict_args["status"]
        self.qss_file = dict_args["qss"]
        self.installButtonSig = dict_args["installButtonSig"]
        self.flag = dict_args["flag"]
        self.exe_window = dict_args[
            "exe_path_window"] if "exe_path_window" in dict_args else None
        self.save_pathSig = dict_args["save_pathSig"]
        self.dict_args = dict_args
        self.target_exe = dict_args["target"]
        self.qnam = QNetworkAccessManager()
        self.qnam.authenticationRequired.connect(
            self.slotAuthenticationRequired)
        self.qnam.sslErrors.connect(self.sslErrors)
        self.progressDialog = QProgressDialog(self.parent)
        self.progressDialog.resize(354, 145)
        self.progressDialog.canceled.connect(self.cancelDownload)
        self.progress_text = ""
        self.errorSig.connect(self.popupException)
        self.downloadFile() 
Example #16
Source File: update.py    From PhyloSuite with GNU General Public License v3.0 5 votes vote down vote up
def ini_args(self):
        self.url = QUrl(self.dict_args["url"])
        self.exportPath = self.dict_args["downloadPath"]
        # self.totalSize = self.dict_args["totalSize"]
        self.progressSig = self.dict_args["progressSig"]
        self.outFile = QFile(self.exportPath)
        self.httpGetId = 0
        self.httpRequestAborted = False
        self.qnam = QNetworkAccessManager()
        self.qnam.authenticationRequired.connect(
            self.slotAuthenticationRequired)
        self.qnam.sslErrors.connect(self.sslErrors)
        self.downloadFile() 
Example #17
Source File: updater.py    From vidcutter with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, parent=None, flags=Qt.Dialog | Qt.WindowCloseButtonHint):
        super(Updater, self).__init__(parent, flags)
        self.parent = parent
        self.logger = logging.getLogger(__name__)
        self.api_github_latest = QUrl('https://api.github.com/repos/ozmartian/vidcutter/releases/latest')
        self.manager = QNetworkAccessManager(self)
        self.manager.finished.connect(self.done) 
Example #18
Source File: HttpRequestManager.py    From Uranium with GNU Lesser General Public License v3.0 5 votes vote down vote up
def _onRequestError(self, request_data: "HttpRequestData", error: "QNetworkReply.NetworkError") -> None:
        error_string = None
        if request_data.reply is not None:
            error_string = request_data.reply.errorString()

        if error == QNetworkReply.UnknownNetworkError:
            self._setInternetReachable(False)
            # manager seems not always able to recover from a total loss of network access, so re-create it
            self._network_manager = QNetworkAccessManager(self)

        Logger.log("d", "%s got an error %s, %s", request_data, error, error_string)

        with self._request_lock:
            # Safeguard: make sure that we have the reply in the currently in-progress requests set
            if request_data not in self._requests_in_progress:
                # TODO: ERROR, should not happen
                Logger.log("e", "%s not found in the in-progress set", request_data)
                pass
            else:
                # Disconnect callback signals
                if request_data.reply is not None:
                    if request_data.download_progress_callback is not None:
                        request_data.reply.downloadProgress.disconnect(request_data.onDownloadProgressCallback)
                    if request_data.upload_progress_callback is not None:
                        request_data.reply.uploadProgress.disconnect(request_data.onUploadProgressCallback)

                    request_data.setDone()
                    self._requests_in_progress.remove(request_data)

        # Schedule the error callback if there is one
        if request_data.error_callback is not None:
            self.callLater(0, request_data.error_callback, request_data.reply, error)

        # Continue to process the next request
        self._processNextRequestsInQueue() 
Example #19
Source File: HttpRequestManager.py    From Uranium with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, max_concurrent_requests: int = 4, parent: Optional["QObject"] = None,
                 enable_request_benchmarking: bool = False) -> None:
        if HttpRequestManager.__instance is not None:
            raise RuntimeError("Try to create singleton '%s' more than once" % self.__class__.__name__)
        HttpRequestManager.__instance = self

        super().__init__(parent)

        self._network_manager = QNetworkAccessManager(self)
        self._account_manager = None
        self._is_internet_reachable = True

        # All the requests that have been issued to the QNetworkManager are considered as running concurrently. This
        # number defines the max number of requests that will be issued to the QNetworkManager.
        self._max_concurrent_requests = max_concurrent_requests

        # A FIFO queue for the pending requests.
        self._request_queue = deque()  # type: deque

        # A set of all currently in progress requests
        self._requests_in_progress = set()  # type: Set[HttpRequestData]
        self._request_lock = RLock()
        self._process_requests_scheduled = False

        # Debug options
        #
        # Enabling benchmarking will make the manager to time how much time it takes for a request from start to finish
        # and log them.
        self._enable_request_benchmarking = enable_request_benchmarking 
Example #20
Source File: ClusterApiClient.py    From Cura with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, address: str, on_error: Callable) -> None:
        """Initializes a new cluster API client.

        :param address: The network address of the cluster to call.
        :param on_error: The callback to be called whenever we receive errors from the server.
        """
        super().__init__()
        self._manager = QNetworkAccessManager()
        self._address = address
        self._on_error = on_error 
Example #21
Source File: NetworkMJPGImage.py    From Cura with GNU Lesser General Public License v3.0 5 votes vote down vote up
def start(self) -> None:
        self.stop()  # Ensure that previous requests (if any) are stopped.

        if not self._source_url:
            Logger.log("w", "Unable to start camera stream without target!")
            return
        self._started = True

        self._image_request = QNetworkRequest(self._source_url)
        if self._network_manager is None:
            self._network_manager = QNetworkAccessManager()

        self._image_reply = self._network_manager.get(self._image_request)
        self._image_reply.downloadProgress.connect(self._onStreamDownloadProgress) 
Example #22
Source File: NetworkMJPGImage.py    From Cura with GNU Lesser General Public License v3.0 5 votes vote down vote up
def __init__(self, *args, **kwargs) -> None:
        super().__init__(*args, **kwargs)

        self._stream_buffer = QByteArray()
        self._stream_buffer_start_index = -1
        self._network_manager = None  # type: QNetworkAccessManager
        self._image_request = None  # type: QNetworkRequest
        self._image_reply = None  # type: QNetworkReply
        self._image = QImage()
        self._image_rect = QRect()

        self._source_url = QUrl()
        self._started = False

        self._mirror = False

        self.setAntialiasing(True)