Skip to content

Commit

Permalink
Merge pull request #1550 from ales-erjavec/image-viewer-local-files
Browse files Browse the repository at this point in the history
[FIX] owimageviewer: Open local images directly
  • Loading branch information
astaric authored Sep 12, 2016
2 parents 2e7b23d + 1dd7873 commit 8ae84ef
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 8ae84ef

Please sign in to comment.