def MakeBubbleLayersMain( self, sender ):
		try:
			font = Glyphs.font # frontmost font
			fontMaster = font.selectedFontMaster # active master
			selectedLayers = font.selectedLayers # active layers of selected glyphs
			GLYPHSAPPVERSION = NSBundle.bundleForClass_(GSMenu).infoDictionary().objectForKey_("CFBundleShortVersionString")

			font.disableUpdateInterface() # suppresses UI updates in Font View

			try:
				offsetH = int(self.w.editH.get())
				offsetV = int(self.w.editV.get())
			except:
				Glyphs.displayDialog_withTitle_("You typed something other than numbers in the text field.", "Invalid Input")

			if self.w.masterRadio.get() == 0:
				masters = [font.selectedFontMaster]
			else:
				masters = font.masters

			for gLayer in selectedLayers:
				glyph = gLayer.parent
				glyph.beginUndo() # begin undo grouping			

				if self.w.overwriteRadio.get() == 0: # never overwrite
					# bubbleList is a list of masters that have bubble layer
					bubbleList = [ layer.associatedFontMaster() for layer in glyph.layers if layer.name=='bubble' ]
				elif self.w.overwriteRadio.get() == 1: # make new only if empty
					bubbleList = [ layer.associatedFontMaster() for layer in glyph.layers if layer.name=='bubble' and len(layer.paths) > 0 ]
					bubblesToBeDeleted = [ layer for layer in glyph.layers if layer.name=='bubble' and len(layer.paths)==0 ]
				else: #Always delete and make new
					bubbleList = []
					bubblesToBeDeleted = [ layer for layer in glyph.layers if layer.name=='bubble' ]
				if 'bubblesToBeDeleted' in locals():
					for emptyBubble in bubblesToBeDeleted:
						glyph.removeLayerForKey_(emptyBubble.layerId)

				for master in masters:
					if not master in bubbleList: # if master is not mentioned in bubbleList = doesn't have bubble
						newBubbleLayer = GSLayer()
						newBubbleLayer.name = "bubble"
						newBubbleLayer.width = glyph.layers[master.id].width
						newBubbleLayer.associatedMasterId = master.id
						for pathToCopy in glyph.layers[master.id].paths:
							newBubbleLayer.addPath_( pathToCopy.copy() )
						self.offsetPath(newBubbleLayer, offsetH, offsetV) # SHOULD NOT BE EXECUTED IF SIDEBEARING OPTION IS OFF
						newBubbleLayer.removeOverlap()
						for path in newBubbleLayer.paths: # remove negative path because you don't need it
							if path.direction == 1:
								path.reverse()
						newBubbleLayer.removeOverlap() # remove overlap again to eliminate all negative path
						if self.w.adhereToSB.get():
							self.fitToSidebearing(newBubbleLayer, master)
						glyph.layers.append(newBubbleLayer)
				glyph.endUndo()   # end undo grouping		
			font.enableUpdateInterface() # re-enables UI updates in Font View
	
			if not self.SavePreferences( self ):
				print "Note: 'Make Bubble Layers' could not write preferences."
		except Exception, e:
			# brings macro window to front and reports error:
			Glyphs.showMacroWindow()
			print "Make Bubble Layers Error (MakeBubbleLayersMain): %s" % e
dataset/ETHPy150Open Tosche/BubbleKern/Make Bubble Layers.py/MakeBubbleLayers.MakeBubbleLayersMain/original