Skip to content

Commit

Permalink
owimageviewer: Open local images directly
Browse files Browse the repository at this point in the history
Using QNetworkAccessManager to 'retrieve' many local files can lead
to temporarily running out of available file descriptors.

Presumably this is because the associated open fd is not closed
until the QNetworkReply is actually deleted (and not just closed).
  • Loading branch information
ales-erjavec committed Sep 9, 2016
1 parent d3c50bd commit 1dd7873
Showing 1 changed file with 29 additions and 5 deletions.
34 changes: 29 additions & 5 deletions Orange/widgets/data/owimageviewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,23 @@ def setupScene(self):
thumbnail.instance = inst
self.thumbnailView.addThumbnail(thumbnail)

if url.isValid():
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
Expand All @@ -1025,13 +1041,17 @@ def set_pixmap(future, thumb=thumbnail):

thumb.setPixmap(pixmap)

self._updateStatus(future)

self._noteCompleted(future)
else:
future = None

self.items.append(_ImageItem(i, thumbnail, url, future))

self.info.setText("Retrieving...\n")
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()

def urlFromValue(self, value):
variable = value.variable
Expand Down Expand Up @@ -1099,7 +1119,8 @@ def commit(self):
else:
self.send("Data", None)

def _updateStatus(self, future):
def _noteCompleted(self, future):
# Note the completed future's state
if future.cancelled():
return

Expand All @@ -1109,6 +1130,9 @@ def _updateStatus(self, future):
else:
self._successcount += 1

self._updateStatus()

def _updateStatus(self):
count = len([item for item in self.items if item.future is not None])
self.info.setText(
"Retrieving:\n" +
Expand Down

0 comments on commit 1dd7873

Please sign in to comment.