Repository: vispy/vispy

Issue:
Vispy Linux Error ( division by zero)
When I try to tun the vispy on linux I get the following error:

```
from vispy.plot import Fig
f = Fig()

/lib/python2.7/site-packages/vispy/util/dpi/_linux.pyc in <lambda>(x_px, y_px, x_mm, y_mm)
     49     from_xrandr = _get_dpi_from(
     50         'xrandr', r'(\d+)x(\d+).*?(\d+)mm x (\d+)mm',
---> 51         lambda x_px, y_px, x_mm, y_mm: 25.4 * (x_px / x_mm + y_px / y_mm) / 2)
     52     if from_xrandr is not None:
     53         return from_xrandr
```

ZeroDivisionError: float division by zero



Discussion:
I can't reproduce this on Ubuntu 14.04 and the mainline code as of Jun 15.  

Are you running against the mainline code?

I'm still getting this on 0.4.0 and Git :/ Arch Linux
EDIT: And sadly Python 2 and 3.
@Lartza @motamedi79 If you are still available for testing could you try running the `xrandr` command on your machine and letting me know the input. This function is fairly simple in that it runs `xdpyinfo` and if the command fails or is not what vispy expects it tries running `xrandr` and does the same checks. It is apparently getting output from `xrandr` that it understands but one of the `mm` in the output must be 0 based on the error message. I will try reproducing this if you are not available.
Can't even remember what I was trying to do with vispy back then but luckily the issue is reproducible easily. Installing xorg-xdpyinfo seems to fix it yet xdpyinfo is not indicated as a dependency of vispy anywhere at all :/

```
[lartza@archvm ~]$ xrandr
Screen 0: minimum 320 x 200, current 1360 x 768, maximum 16384 x 16384
VGA-1 connected primary 1360x768+0+0 (normal left inverted right x axis y axis) 0mm x 0mm
   1360x768      59.95*+  60.02  
   2560x1600     59.99    59.97  
   1920x1440     60.00  
   1856x1392     60.00  
   1792x1344     60.00  
   2048x1152     60.00  
   1920x1200     59.88    59.95  
   1920x1080     60.00  
   1600x1200     60.00  
   1680x1050     59.95    59.88  
   1400x1050     59.98    59.95  
   1600x900      60.00  
   1280x1024     60.02  
   1440x900      59.89    59.90  
   1280x960      60.00  
   1366x768      59.79    60.00  
   1280x800      59.81    59.91  
   1280x768      59.87    59.99  
   1280x720      60.00  
   1024x768      60.00  
   800x600       60.32    56.25  
   848x480       60.00  
   640x480       59.94  
```
@Lartza awesome. Thank you. Any idea why the `VGA-1` line ends with `0mm x 0mm` (I'm not sure what that is trying to list).

Edit: Ah it's screen dimensions.
I'm guessing (and googled a bit), if that should report the size of the physical screen for DPI calculations it's because it's not a physical screen but VirtualBox. But honestly don't know :P
@larsoner Any objections to having this logic default to a DPI of `96.` with a warning if screen dimensions have a `0` in them? 96 is the default if `DISPLAY` isn't set or if xrandr has no recognizable output.
We already default to 96 here:

https://github.com/vispy/vispy/blob/acc4c4b24ff4e628253641df887a6e58fbd24a8e/vispy/util/dpi/_linux.py#L29

+1 for fixing 0 DPI -> 96 DPI (maybe with a warning?), assuming that's what you mean @davidh-ssec 

Resolving patch:
diff --git a/vispy/util/dpi/_linux.py b/vispy/util/dpi/_linux.py
--- a/vispy/util/dpi/_linux.py
+++ b/vispy/util/dpi/_linux.py
@@ -26,6 +26,14 @@ def _get_dpi_from(cmd, pattern, func):
             return func(*map(float, match.groups()))
 
 
+def _xrandr_calc(x_px, y_px, x_mm, y_mm):
+    if x_mm == 0 or y_mm == 0:
+        logger.warning("'xrandr' output has screen dimension of 0mm, " +
+                       "can't compute proper DPI")
+        return 96.
+    return 25.4 * (x_px / x_mm + y_px / y_mm) / 2
+
+
 def get_dpi(raise_error=True):
     """Get screen DPI from the OS
 
@@ -51,7 +59,7 @@ def get_dpi(raise_error=True):
 
     from_xrandr = _get_dpi_from(
         'xrandr', r'(\d+)x(\d+).*?(\d+)mm x (\d+)mm',
-        lambda x_px, y_px, x_mm, y_mm: 25.4 * (x_px / x_mm + y_px / y_mm) / 2)
+        _xrandr_calc)
     if from_xrandr is not None:
         return from_xrandr
     if raise_error:


Test patch: