Made gp_widget_* functions more memory safe.

Many of them return pointers to nodes in a widget tree. These are unsafe
as they become invalid if the tree is deleted. Now the Python binding
increments the ref count of the tree root when a pointer is returned,
and decrements the root ref count when the returned object is deleted.