<commit_before># encoding: utf-8

#######################################################################################
#
#	Palette Plugin
#
#	Read the docs:
#	https://github.com/schriftgestalt/GlyphsSDK/tree/master/Python%20Templates/Palette
#
#######################################################################################


from GlyphsApp.plugins import *

class GlyphNote (PalettePlugin):
	
	dialog = objc.IBOutlet()
	glyphNoteTextField = objc.IBOutlet()
	
	def settings(self):
		self.name = Glyphs.localize({'en': u'Glyph Note', 'de': u'Glyphennotiz'})
		self.dialogName = Glyphs.localize({'en': u'Glyph Note', 'de': u'Glyphennotiz'})
		
		# Load .nib dialog (without .extension)
		self.loadNib('IBdialog', __file__)
	
	def start(self):
		# Adding a callback:
		Glyphs.addCallback( self.update, UPDATEINTERFACE )
	
	def __del__(self):
		Glyphs.removeCallback( self.update, UPDATEINTERFACE )
	
	@objc.IBAction
	def setGlyphNote_( self, sender ):
		"""Sets the glyph note to whatever has been entered into the text field in the palette."""
		try:
			theseGlyphs = []
			
			# Extract font from sender
			thisFont = self.windowController().document().font

			# We’re in the Edit View
			if thisFont.currentTab:
				theseGlyphs = [l.parent for l in thisFont.selectedLayers]
			# We’re in the Font view
			else:
				theseGlyphs = [g for g in thisFont.selection]
			
			for thisGlyph in theseGlyphs:
				enteredText = self.glyphNoteTextField.stringValue()
				thisGlyph.note = enteredText
				
		except Exception as e:
			self.logToConsole( "setGlyphNote_: %s" % str(e) )
	

	def update( self, sender ):
		theseGlyphs = []
		thisFont = sender.object()
		
		# We’re in the Edit View
		if thisFont.currentTab:
			theseGlyphs = [l.parent for l in thisFont.selectedLayers]
		# We’re in the Font view
		else:
			theseGlyphs = [g for g in thisFont.selection]

		allNotes = []
		for thisGlyph in theseGlyphs:
			thisNote = thisGlyph.note
			if thisNote == "":
				thisNote = None
			allNotes.append(thisNote)

		numberOfDifferentNotes = len(set(allNotes))

		if numberOfDifferentNotes == 1:
			# update glyph note in palette:
			if len(theseGlyphs) > 1:
				note = "notes"
			else:
				note = "note"
			self.glyphNoteTextField.setPlaceholderString_("Empty glyph %s."%note)
			# assume that glyph has no note set yet, erase display:
			self.glyphNoteTextField.setStringValue_( "" )
			
			thisGlyphNote = theseGlyphs[0].note
			if thisGlyphNote:
				# glyph has a note, and needs to be displayed:
				self.glyphNoteTextField.setStringValue_( thisGlyphNote )
				
		elif numberOfDifferentNotes == 0:
			self.glyphNoteTextField.setPlaceholderString_("No glyph selected.")
			self.glyphNoteTextField.setStringValue_( "" )
			
		else:
			self.glyphNoteTextField.setPlaceholderString_("Multiple values.")
			self.glyphNoteTextField.setStringValue_( "" )
		
	def minHeight( self ):
		"""
		The minimum height of the view in pixels.
		"""
		try:
			return 30
		except Exception as e:
			self.logToConsole( "minHeight: %s" % str(e) )
	
	def maxHeight( self ):
		"""
		The maximum height of the view in pixels.
		Must be equal to or bigger than minHeight.
		"""
		try:
			return 400
		except Exception as e:
			self.logToConsole( "maxHeight: %s" % str(e) )
	
	def __file__(self):
		"""Please leave this method unchanged"""
		return __file__
	
	# Temporary Fix
	# Sort ID for compatibility since v919:
	_sortID = 0
	def setSortID_(self, id):
		try:
			self._sortID = id
		except Exception as e:
			self.logToConsole( "setSortID_: %s" % str(e) )
			
	def sortID(self):
		return self._sortID
	<commit_msg>simplify hack<commit_after># encoding: utf-8

#######################################################################################
#
#	Palette Plugin
#
#	Read the docs:
#	https://github.com/schriftgestalt/GlyphsSDK/tree/master/Python%20Templates/Palette
#
#######################################################################################


from GlyphsApp.plugins import *

class GlyphNote (PalettePlugin):
	
	dialog = objc.IBOutlet()
	glyphNoteTextField = objc.IBOutlet()
	
	def settings(self):
		self.name = Glyphs.localize({'en': u'Glyph Note', 'de': u'Glyphennotiz'})
		self.dialogName = Glyphs.localize({'en': u'Glyph Note', 'de': u'Glyphennotiz'})
		
		# Load .nib dialog (without .extension)
		self.loadNib('IBdialog', __file__)
	
	def start(self):
		# Adding a callback:
		Glyphs.addCallback( self.update, UPDATEINTERFACE )
	
	def __del__(self):
		Glyphs.removeCallback( self.update, UPDATEINTERFACE )
	
	@objc.IBAction
	def setGlyphNote_( self, sender ):
		"""Sets the glyph note to whatever has been entered into the text field in the palette."""
		try:
			theseGlyphs = []
			
			# Extract font from sender
			thisFont = self.windowController().document().font

			# We’re in the Edit View
			if thisFont.currentTab:
				theseGlyphs = [l.parent for l in thisFont.selectedLayers]
			# We’re in the Font view
			else:
				theseGlyphs = [g for g in thisFont.selection]
			
			for thisGlyph in theseGlyphs:
				enteredText = self.glyphNoteTextField.stringValue()
				thisGlyph.note = enteredText
				
		except Exception as e:
			self.logToConsole( "setGlyphNote_: %s" % str(e) )
	

	def update( self, sender ):
		theseGlyphs = []
		thisFont = sender.object()
		
		# We’re in the Edit View
		if thisFont.currentTab:
			theseGlyphs = [l.parent for l in thisFont.selectedLayers]
		# We’re in the Font view
		else:
			theseGlyphs = [g for g in thisFont.selection]

		allNotes = []
		for thisGlyph in theseGlyphs:
			thisNote = thisGlyph.note
			if thisNote == "":
				thisNote = None
			allNotes.append(thisNote)

		numberOfDifferentNotes = len(set(allNotes))

		if numberOfDifferentNotes == 1:
			# update glyph note in palette:
			if len(theseGlyphs) > 1:
				note = "notes"
			else:
				note = "note"
			self.glyphNoteTextField.setPlaceholderString_("Empty glyph %s."%note)
			# assume that glyph has no note set yet, erase display:
			self.glyphNoteTextField.setStringValue_( "" )
			
			thisGlyphNote = theseGlyphs[0].note
			if thisGlyphNote:
				# glyph has a note, and needs to be displayed:
				self.glyphNoteTextField.setStringValue_( thisGlyphNote )
				
		elif numberOfDifferentNotes == 0:
			self.glyphNoteTextField.setPlaceholderString_("No glyph selected.")
			self.glyphNoteTextField.setStringValue_( "" )
			
		else:
			self.glyphNoteTextField.setPlaceholderString_("Multiple values.")
			self.glyphNoteTextField.setStringValue_( "" )
		
	def minHeight( self ):
		"""
		The minimum height of the view in pixels.
		"""
		try:
			return 30
		except Exception as e:
			self.logToConsole( "minHeight: %s" % str(e) )
	
	def maxHeight( self ):
		"""
		The maximum height of the view in pixels.
		Must be equal to or bigger than minHeight.
		"""
		try:
			return 400
		except Exception as e:
			self.logToConsole( "maxHeight: %s" % str(e) )
	
	def __file__(self):
		"""Please leave this method unchanged"""
		return __file__
	
	# Temporary Fix
	# Sort ID for compatibility with v919 to v976
	def setSortID_(self, id):
		pass
	
	def sortID(self):
		return 0
	
{'fraction_non_alphanumeric': 0.1511167656205824, 'fraction_numerical': 0.004947695787390444, 'mean_word_length': 3.786874154262517, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4435853', 'n_tokens_mistral': 2744, 'n_tokens_neox': 2243, 'n_words': 619}