Delete a widget if not in use

I have a widget show in the view port if I right click but I would like it to be removed from the view port if something other than is is selected. Here is what I have so far.