本文整理匯總了Python中PyQt5.QtNetwork.QNetworkAccessManager方法的典型用法代碼示例。如果您正苦於以下問題:Python QtNetwork.QNetworkAccessManager方法的具體用法?Python QtNetwork.QNetworkAccessManager怎麽用?Python QtNetwork.QNetworkAccessManager使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtNetwork
的用法示例。
在下文中一共展示了QtNetwork.QNetworkAccessManager方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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)
示例2: webSettings
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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)
示例3: _processNextRequestsInQueue
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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.
示例4: __init__
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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()
示例5: __init__
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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)
示例6: networkaccessmanager
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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
示例7: start
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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)
示例8: __init__
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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
示例9: __init__
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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
示例10: _onRequestError
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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()
示例11: __init__
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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)
示例12: ini_args
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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()
示例13: __init__
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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()
示例14: doRequest
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
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)
示例15: __init__
# 需要導入模塊: from PyQt5 import QtNetwork [as 別名]
# 或者: from PyQt5.QtNetwork import QNetworkAccessManager [as 別名]
def __init__(self):
super().__init__()
self.nam = qtn.QNetworkAccessManager()
self.nam.finished.connect(self.on_reply)