UV Islands. how to distinguish them?
Isn't this simply how 'uv select sync' currently displays things rather than being a coding issue?

The only way to do this would be to disable 'uv select sync' and change the 'Sticky select mode' to 'Disabled' in the Image Editor header, as shown below:



The disadvantage is that the whole mesh will have to be selected to appear in the uv image editor. I'm not sure if this helps or not because I don't quite understand what you're looking to do, but thought I would add this information in case it does, seeing as you don't have any other answers.