Abstract GUI code from API, mostly complete but still a little more work to do.

This is a pretty big refactor, any external plugins that use the API should check if things still work. Nothing has been removed but there might be different ways of doing the same things e.g. getting the local image on disk is no longer something that is part of the API data structures.

Also did quite a bit of GUI refractoring for re-useability. Again, there is still some more work to do on this as well.