Merge pull request #128 from odysseywestra/popup_menu_fix

Popup Menu Fix
Fixed a few undefined variable errors

Somehow I missed a few in tests/test_memory_leak.py when I was
refactoring out `from numpy import *` for `import numpy`. Whoops.
Fixed an UnboundLocalError in lib/cache.py

Not much to say about this. I guess nobody's tried to index a LRUCache
recently.
Minor refactor in CurveWidget drawing

This was mostly done because flake8 was complaining a lot about how
previously variables were technically used before they existed. In
practice, this wouldn't happen, but I thought the code should have a
minor rework anyway.