Repository: beeware/toga

Issue:
ImageView Example Crashes when Image Not Found
## Expected Behavior
<!--- If you're describing a bug, tell us what you expect to happen. -->
The image view example to render
If the imageview widget does not find an image file, it should print a warning instead of crashing.
Also, test coverage shows 100% for imageview widget `toga/widgets/imageview.py`, consider adding a test case for image not found.

<!--- If you're requesting a new feature, tell us why you'd like this feature. -->

## Current Behavior
<!--- If you're describing a bug, what currently happens? -->
```
(venv) robert@robert-VirtualBox:~/staging/toga/examples/imageview$ python -m imageview
[GTK+] Not implemented: Widget.set_hidden()
resources/brutus.png
[GTK+] Not implemented: Widget.set_hidden()
Traceback (most recent call last):
  File "/home/robert/staging/toga/src/gtk/toga_gtk/app.py", line 67, in startup
    self.interface.startup()
  File "/home/robert/staging/toga/examples/imageview/imageview/app.py", line 19, in startup
    imageview_from_path = toga.ImageView(image_from_path)
  File "/home/robert/staging/toga/src/core/toga/widgets/imageview.py", line 23, in __init__
    self.image = image
  File "/home/robert/staging/toga/src/core/toga/widgets/imageview.py", line 33, in image
    self._impl.set_image(self._image)
  File "/home/robert/staging/toga/src/gtk/toga_gtk/widgets/imageview.py", line 33, in set_image
    self._original_pixbuf = GdkPixbuf.Pixbuf.new_from_file(os.path.join(toga.App.app_dir, self.image.path))
GLib.Error: g-file-error-quark: Failed to open file '/home/robert/staging/toga/examples/imageview/imageview/resources/brutus.png': No such file or directory (4)
^C
```
I have my local checkout of toga installed the following and seems to have the new location of brutus.png from 2d95b16 (#521) 
pip install -e src/core
pip install -e src/dummy
pip install -e src/gtk

```
(venv) robert@robert-VirtualBox:~/staging/toga/examples/imageview$ ls -la /home/robert/staging/toga/examples/imageview/imageview/resources/brutus.png
ls: cannot access '/home/robert/staging/toga/examples/imageview/imageview/resources/brutus.png': No such file or directory
(venv) robert@robert-VirtualBox:~/staging/toga/examples/imageview$ ls -la /home/robert/staging/toga/examples/imageview/resources/brutus.png
-rw-r--r-- 1 robert robert 5469 May 28 07:26 /home/robert/staging/toga/examples/imageview/resources/brutus.png
(venv) robert@robert-VirtualBox:~/staging/toga/examples/imageview$ 
```
## Steps to reproduce
<!--- Provide a set of steps describing how to reproduce this bug. If you have a live example, provide the link below -->
1.Setup Linux environment following instructions here:
https://toga.readthedocs.io/en/latest/how-to/contribute.html

2. cd imageview

3. python -m imageview

## Your Environment
<!--- Provide details on your current environment you found the bug in -->

* Python Version (list the specific version number)
Python 3.6.5

* Operating System and Version (select from the following and list the specific version number; if your OS is not listed, list that as well)

  - [ ] macOS - version: 
  - [ x] Linux - distro:   - version: Ubuntu_18_04
  - [ ] Windows - version:
  - [ ] Other - name:  - version:

* Toga Target (the type of app you are trying to generate)
 
  - [ ] android
  - [ ] cocoa
  - [ ] django 
  - [x ] gtk
  - [ ] iOS
  - [ ] tvOS
  - [ ] watchOS
  - [ ] winforms 
  - [ ] win32
  - [ ] Other (please specify)



Discussion:

Resolving patch:
diff --git a/src/gtk/toga_gtk/widgets/imageview.py b/src/gtk/toga_gtk/widgets/imageview.py
--- a/src/gtk/toga_gtk/widgets/imageview.py
+++ b/src/gtk/toga_gtk/widgets/imageview.py
@@ -27,11 +27,11 @@ def set_image(self, image):
             with urlopen(request) as result:
                 input_stream = Gio.MemoryInputStream.new_from_data(result.read(), None)
                 self._original_pixbuf = GdkPixbuf.Pixbuf.new_from_stream(input_stream, None)
-        elif os.path.isabs(self.image.path):
-            self._original_pixbuf = GdkPixbuf.Pixbuf.new_from_file(self.image.path)
+        full_image_path = self.image.path if os.path.isabs(self.image.path) else os.path.join(toga.App.app_dir, self.image.path)
+        if os.path.isfile(full_image_path):
+            self._original_pixbuf = GdkPixbuf.Pixbuf.new_from_file
         else:
-            self._original_pixbuf = GdkPixbuf.Pixbuf.new_from_file(os.path.join(toga.App.app_dir, self.image.path))
-
+            raise ValueError("No image file available at ", path)
         self.rehint()
 
     def rehint(self):


Test patch: