def spaceCase(self, sender): sp = CurrentSpaceCenter() sc = sp.getRaw() if sc.isupper(): self.setCase(sp, 'title') elif sc.istitle(): self.setCase(sp, 'lower') elif sc.islower(): self.setCase(sp, 'upper') else: self.setCase(sp, 'upper')
def saverCallback(self, sender): print("saving input text") csc = CurrentSpaceCenter() string = csc.getRaw() print("string is", string) before = getDefault("spaceCenterInputSamples") print("before is ", before) after = list(before) print("after is ", after) if string not in after: after.append(string) print("after2 is ", after) setDefault("spaceCenterInputSamples", after) print("saved input text.") else: print("did nothing.") preferencesChanged()
def __init__(self): self.alphabetSet = alphabetSetLower # set up window self.w = vanilla.Window((420, 150), "Pangrammer Helper") # set up remaining letters display self.w.alphabet = vanilla.TextBox((15, 15, -15, 20), self.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) self.w.counter = vanilla.TextBox((-250, 112, -15, 20), "Pangram length: 0", alignment='right') self.w.checkBox = vanilla.CheckBox((15, 110, -15, 20), "", callback=self.checkBoxCallback, value=False) self.w.checkBoxLabel = vanilla.TextBox( # don’t know how to access the NSText of a Vanilla check box label (32, 112, -15, 20), "Mixed case") # set the editor font to be monospaced, and the rest to be system font monospace_font = NSFont.userFixedPitchFontOfSize_(12) system_font = NSFont.systemFontOfSize_(12) self.w.pangramEditor.getNSTextView().setFont_(monospace_font) self.w.alphabet.getNSTextField().setFont_(system_font) self.w.counter.getNSTextField().setFont_(system_font) self.w.checkBoxLabel.getNSTextField().setFont_(system_font) self.w.open() # set remaining letters and counter to reflect contents of text field self.textEditorCallback(self)
def wordsForMMPair(self, ): self.mixedCase = False ### temp comment out to check speed self.source = self.w.source.get() wordsAll = self.dictWords[self.textfiles[self.source]] #default values are hard coded for now #self.wordCount = self.getIntegerValue(self.w.wordCount) #v = self.getIntegerValue(self.w.wordCount) wordCountValue = int(self.wordCount) #print(v) #print ('self.wordCount', self.wordCount) #currently allows any word lenght, this could be customized later text = '' textList = [] # try getting pairstring once in order to check if encoded pairstring = self.getPairstring(self.pair) #convert MM tuple into search pair to check uc, lc, mixed case. Maybe need a different var name here? pair2char = ''.join(self.pair2char(self.pair)) #check Encoding #print (pairstring) #default value makeUpper = False if pair2char.isupper(): #print (pairstring, 'upper') makeUpper = True #make lower for searching searchString = pair2char.lower() else: #print(pairstring, 'not upper') makeUpper = False searchString = pair2char pass #check for mixed case if self.pair2char(self.pair)[0].isupper(): if self.pair2char(self.pair)[1].islower(): if (self.leftEncoded == True) and (self.rightEncoded == True): self.mixedCase = True try: currentSC = CurrentSpaceCenter() previousText = currentSC.getRaw() except: previousText = '' pass count = 0 #self.usePhrases = False # more results for mixed case if we include lc words and capitalize if self.mixedCase == True: for word in self.randomly(wordsAll): # first look for words that are already mixed case if searchString in word: #avoid duplicates if not word in textList: #print (word) textList.append(word) count += 1 #then try capitalizing lowercase words if (searchString.lower() in word[:2]): word = word.capitalize() #avoid duplicates if not word in textList: #print (word) textList.append(word) count += 1 #stop when you get enough results if count >= wordCountValue: #print (text) break pass else: for word in self.randomly(wordsAll): if searchString in word: #avoid duplicates if not word in textList: #print (word) textList.append(word) count += 1 #stop when you get enough results if count >= wordCountValue: #print (text) break if makeUpper == True: #make text upper again textList = list(text.upper() for text in textList) if not len(textList) == 0: #see if box is checked self.sorted = self.w.listOutput.get() #self.sorted = False if self.sorted == True: sortedText = self.sortWordsByWidth(textList) textList = sortedText joinString = "\\n" text = joinString.join([str(word) for word in textList]) if self.w.mirroredPair.get( ) == True: #if "start with mirrored pair" is checked, add this to text text = self.pairMirrored(self.pair) + joinString + text if self.w.openCloseContext.get( ) == True: # if "show open+close" is checked, add this to text text = self.openCloseContext(self.pair) + text else: text = ' '.join([str(word) for word in textList]) if self.w.mirroredPair.get( ) == True: #if "start with mirrored pair" is checked, add this to text text = self.pairMirrored(self.pair) + text if self.w.openCloseContext.get( ) == True: # if "show open+close" is checked, add this to text text = self.openCloseContext(self.pair) + text # if no words are found, show spacing string and previous text if len(text) == 0: #do i need to get pairstring again or can I used the previous one? #pairstring = self.getPairstring(self.pair) previousText = '\\n no words for pair ' + pairstring self.messageText = '😞 no words found: ' + pairstring self.w.myTextBox.set(self.messageText) if makeUpper == True: text = self.ucString(pairstring) + previousText if self.w.mirroredPair.get( ) == True: #if "start with mirrored pair" is checked, add this to text text = self.pairMirrored(self.pair) + text if self.w.openCloseContext.get( ) == True: # if "show open+close" is checked, add this to text text = self.openCloseContext(self.pair) + text else: text = self.lcString(pairstring) + previousText if self.w.mirroredPair.get( ) == True: #if "start with mirrored pair" is checked, add this to text text = self.pairMirrored(self.pair) + text if self.w.openCloseContext.get( ) == True: # if "show open+close" is checked, add this to text text = self.openCloseContext(self.pair) + text text = text.lstrip() #remove whitespace self.setSpaceCenter(self.font, text) else: #set space center if words are found #not sure why there's always a /slash in from of the first word, added ' '+ to avoid losing the first word text = text.lstrip() #remove whitespace self.setSpaceCenter(self.font, text) self.messageText = '😎 words found: ' + pairstring self.w.myTextBox.set(self.messageText)