Added a base widget class

In an effort to reduce the amount of duplicate code in the plugin, I’ve
added a base widget class which is designed to be extended. This can
probably still be improved, but it’s a good start.