本文整理汇总了Python中PyQt4.QtGui.QImageReader.errorString方法的典型用法代码示例。如果您正苦于以下问题:Python QImageReader.errorString方法的具体用法?Python QImageReader.errorString怎么用?Python QImageReader.errorString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QImageReader
的用法示例。
在下文中一共展示了QImageReader.errorString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: image_meta_data
# 需要导入模块: from PyQt4.QtGui import QImageReader [as 别名]
# 或者: from PyQt4.QtGui.QImageReader import errorString [as 别名]
def image_meta_data(path):
reader = QImageReader(path)
if not reader.canRead():
return ImgDataError(path, reader.error(), reader.errorString())
img_format = reader.format()
img_format = bytes(img_format).decode("ascii")
size = reader.size()
if not size.isValid():
height = width = float("nan")
else:
height, width = size.height(), size.width()
try:
st_size = os.stat(path).st_size
except OSError:
st_size = -1
return ImgData(path, img_format, height, width, st_size)
示例2: on_reply_ready
# 需要导入模块: from PyQt4.QtGui import QImageReader [as 别名]
# 或者: from PyQt4.QtGui.QImageReader import errorString [as 别名]
def on_reply_ready(reply, future):
nonlocal n_redir
# schedule deferred delete to ensure the reply is closed
# otherwise we will leak file/socket descriptors
reply.deleteLater()
future._reply = None
if reply.error() == QNetworkReply.OperationCanceledError:
# The network request was cancelled
reply.close()
future.cancel()
return
if reply.error() != QNetworkReply.NoError:
# XXX Maybe convert the error into standard
# http and urllib exceptions.
future.set_exception(Exception(reply.errorString()))
reply.close()
return
# Handle a possible redirection
location = reply.attribute(
QNetworkRequest.RedirectionTargetAttribute)
if location is not None and n_redir < 1:
n_redir += 1
location = reply.url().resolved(location)
# Retry the original request with a new url.
request = QNetworkRequest(reply.request())
request.setUrl(location)
newreply = self._netmanager.get(request)
future._reply = newreply
newreply.finished.connect(
partial(on_reply_ready, newreply, future))
reply.close()
return
reader = QImageReader(reply)
image = reader.read()
reply.close()
if image.isNull():
future.set_exception(Exception(reader.errorString()))
else:
future.set_result(image)
示例3: on_reply_ready
# 需要导入模块: from PyQt4.QtGui import QImageReader [as 别名]
# 或者: from PyQt4.QtGui.QImageReader import errorString [as 别名]
def on_reply_ready(reply, future):
nonlocal n_redir
if reply.error() == QNetworkReply.OperationCanceledError:
# The network request itself was canceled
future.cancel()
return
if reply.error() != QNetworkReply.NoError:
# XXX Maybe convert the error into standard
# http and urllib exceptions.
future.set_exception(Exception(reply.errorString()))
return
# Handle a possible redirection
location = reply.attribute(
QNetworkRequest.RedirectionTargetAttribute)
if location is not None and n_redir < 1:
n_redir += 1
print(location)
location = reply.url().resolved(location)
# Retry the original request with a new url.
request = QNetworkRequest(reply.request())
request.setUrl(location)
newreply = self._netmanager.get(request)
future._reply = newreply
newreply.finished.connect(
partial(on_reply_ready, newreply, future))
return
reader = QImageReader(reply)
image = reader.read()
if image.isNull():
future.set_exception(Exception(reader.errorString()))
else:
future.set_result(image)
示例4: setupScene
# 需要导入模块: from PyQt4.QtGui import QImageReader [as 别名]
# 或者: from PyQt4.QtGui.QImageReader import errorString [as 别名]
def setupScene(self):
self.error()
if self.data:
attr = self.stringAttrs[self.imageAttr]
titleAttr = self.allAttrs[self.titleAttr]
instances = [inst for inst in self.data
if numpy.isfinite(inst[attr])]
assert self.thumbnailView.count() == 0
size = QSizeF(self.imageSize, self.imageSize)
for i, inst in enumerate(instances):
url = self.urlFromValue(inst[attr])
title = str(inst[titleAttr])
thumbnail = GraphicsThumbnailWidget(QPixmap(), title=title)
thumbnail.setThumbnailSize(size)
thumbnail.setToolTip(url.toString())
thumbnail.instance = inst
self.thumbnailView.addThumbnail(thumbnail)
if url.isValid() and url.isLocalFile():
reader = QImageReader(url.toLocalFile())
image = reader.read()
if image.isNull():
error = reader.errorString()
thumbnail.setToolTip(
thumbnail.toolTip() + "\n" + error)
self._errcount += 1
else:
pixmap = QPixmap.fromImage(image)
thumbnail.setPixmap(pixmap)
self._successcount += 1
future = Future()
future.set_result(image)
future._reply = None
elif url.isValid():
future = self.loader.get(url)
@future.add_done_callback
def set_pixmap(future, thumb=thumbnail):
if future.cancelled():
return
assert future.done()
if future.exception():
# Should be some generic error image.
pixmap = QPixmap()
thumb.setToolTip(thumb.toolTip() + "\n" +
str(future.exception()))
else:
pixmap = QPixmap.fromImage(future.result())
thumb.setPixmap(pixmap)
self._noteCompleted(future)
else:
future = None
self.items.append(_ImageItem(i, thumbnail, url, future))
if any(it.future is not None and not it.future.done()
for it in self.items):
self.info.setText("Retrieving...\n")
else:
self._updateStatus()