import vanilla import string from mojo.UI import * # Pangrammer Helper # By Mark Simonson, v. 1.1, March 13, 2012 # Thanks to Frederik Berlaen for help with hooking up to Space Center # Simple Python version of a Flash/ActionScript "app" I first did in 2003: http://www.ms-studio.com/Animation/pangrammerhelper.html # Purpose is to help you write pangrams--sentences that contain all the letters of the alphabet. # Type in the window. The alphabet will shrink as you use up the letters. Current pangram length displayed at bottom. # If you have a Space Center window open, its current text will be used and updated as you compose your pangram. # Note: It doesn't do anything with spelled out glyph names (e.g., "/space" or "/exclam"). # It's only designed to work with literal text you can type directly. # Non-alphabetic characters are not included in the count for pangram length. alphabetSet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" class PangrammerHelper(object): def __init__(self): # set up window self.w = vanilla.Window((300, 150), "Pangrammer Helper") # set up remaining letters display self.w.alphabet = vanilla.TextBox((15, 15, -15, 20), alphabetSet) # set up text field, inserting Space Center text if available if CurrentSpaceCenter() is None: pangram = "Type your pangram here" else: sp = CurrentSpaceCenter() pangram = sp.getRaw() self.w.pangramEditor = vanilla.TextEditor((15, 40, -15, 70), pangram, callback=self.textEditorCallback) # set up text counter display self.w.counter = vanilla.TextBox((15, 110, -15, 20), "Pangram length: 0") # open window self.w.open() # set remaining letters and counter to reflect contents of text field self.textEditorCallback(self) def textEditorCallback(self, sender): # get pangram text from edit field and convert to uppercase for testing pangram = self.w.pangramEditor.get() tempPangram = string.upper(pangram) # determine and update list of unused letters remainingLetters = "" for c in alphabetSet: i = string.find(tempPangram, c) if i < 0: remainingLetters = remainingLetters+c self.w.alphabet.set(remainingLetters) # determine and display pangram length count = 0 for c in tempPangram: i = string.find(alphabetSet, c) if i >= 0: count += 1 self.w.counter.set("Pangram length: %d" % count) # update Space Center text if CurrentSpaceCenter() is not None: sp = CurrentSpaceCenter() sp.setRaw(pangram) PangrammerHelper()